Code Monkey home page Code Monkey logo

jellyfin-session-kicker's Introduction

Session kicker for Jellyfin

This docker image allows you to kick users out of a session after X amount of time. Built with a simple HTTP server so integration into different services & scripts should be simple.

By default Session kicker will attempt to stop media with commands & stopping encoding. If stop command not support it will delete the device, you can disable this functionality with DELETE_DEVICE_IF_NO_MEDIA_CONTROLS.

or as u/llllllllillllllillll puts it

This is useful if you share your server with a bunch of knob heads who use up your monthly internet bandwidth by leaving The Simpsons playing for 12 hours straight

Documentation

Environment variables

  • JELLYFIN_API_KEY - Required
    • API key for Jellyfin
  • JELLYFIN_API_URL - Required
    • API URL for Jellyfin
  • DONT_KICK_ITEM_TYPE - Optional
    • Default "movie"
    • Comma separated list of Item types what shouldn't be tracked, should be lowercase.
  • MESSAGE_TIME_IN_MILLI - Optional
    • Default 60000
    • Meant to be how long the message displays for, but Jellyfin doesn't respect it.
  • MAX_WATCH_TIME_IN_SECONDS - Optional
    • Default 50.0
    • Max watch time a user can have in seconds.
  • ITEM_ID_ON_SESSION_KICKED - Optional
    • Default ""
    • Item ID to play instead of stopping playback, leave blank to disable.
  • WATCH_TIME_OVER_MSG - Optional
    • Default "You aren't whitelisted for unlimited watch time."
  • NOT_WHITELISTED_MSG - Optional
    • Default "You have used up your watch time."
  • RESET_AFTER_IN_HOURS - Optional
    • Default 24
    • How many hours should the session cache be reset, set as 0 to disable.
  • HTTP_HOST - Optional
  • HTTP_PORT - Optional
  • MONGO_DB - Optional
    • By default "session_timer"
  • MONGO_HOST - Optional
    • By default "localhost"
  • MONGO_PORT - Optional
    • By default 27017
  • DELETE_DEVICE_IF_NO_MEDIA_CONTROLS - Optional
    • If device doesn't support media controls, nuke the device.
    • by default True
  • ACCRUE_BY_DEVICE_INSTEAD_OF_USER - Optional
    • Accrue time per device rather than per user
    • by default False

Deployment

  • Download & configure docker-compose.yml
  • sudo docker-compose build; sudo docker-compose up -d
  • Proxy exposed port.

HTTP Server

Authorization

  • Session kicker uses Basic Auth.
  • Basic Auth credentials are display on initial run.
    • e.g. Your basic auth: xxxx

Add user to whitelist for Media type.

  • Method - POST
  • Authorization - Basic Auth
  • Body - Json
Payload
{
	"UserId": "f521b643f9914b749b9e30bbd06b1792",
	"MediaTypes": ["episode"]
}

Remove user from whitelist for Media type.

  • Method - DELETE
  • Authorization - Basic Auth
  • Body - Json
Payload
{
	"UserId": "f521b643f9914b749b9e30bbd06b1792",
	"MediaTypes": ["episode"]
}

Get all whitelisted Users.

  • Method - GET
  • Authorization - Basic Auth
Response
[
	{
		"UserId": "f521b643f9914b749b9e30bbd06b1792",
		"MediaTypes": [
			"episode"
		]
	}
]

Reset HTTP Key

  • Method - PATCH
  • Authorization - Basic Auth
Response
{
	"key": "d8C9ORsEzjSlUFJx8GMl8VClDmzcRLE_5B5B79Jz0QTtycw0EypqSw"
}

jellyfin-session-kicker's People

Contributors

shanarys avatar wardpearce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jellyfin-session-kicker's Issues

Auth issue.

I've tried several different ways to perform a GET request, making sure to include the Authorization header with the given basic token supplied at runtime, and I always received invalid auth. Here's an example of request and response:

root@63fa9d5d9c8b:/# curl jellyfin-session-kicker --header "Authorization: basic TJziSL1bx4X8fYLJZnlZHxyXOjvUgLdXXPGtbn7NyAgOsj4leJohXQ"
{"error": "Invalid basic auth credentials"}

I would greatly appreciate any help figuring this out! Or providing another means to whitelist would also work.

Thank you.

Env varible default bool bug and feature to accrue time by device rather than user

os.getenv(A, B) looks for env variable A and returns B as a default if it doesn't exist. However variable B is always returned as a string, regardless of what the function was called with.

For DELETE_DEVICE_IF_NO_MEDIA_CONTROLS, B is set to the bool False, which gets converted to the string "False". This will always True for bool("False") since the string is not empty. This is a very annoying oversight from the python developers. A better check is:

DELETE_DEVICE_IF_NO_MEDIA_CONTROLS = os.getenv("DELETE_DEVICE_IF_NO_MEDIA_CONTROLS", "True").lower() == "true"

I've created a PR that includes this change. This PR also includes a new env variable that allows time to be accrued by DeviceId rather than UserId. So the same user with multiple devices is treated differently.

PR: #27

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.