PlexTogglTracker
is my automated solution for tracking to Toggl the time spent watching stuff on Plex. Time-tracking is very personal, everyone has its own way of doing it, so feel free to adapt this code to fit your needs.
PlexTogglTracker
is a Flask blueprint. It serves an endpoint that must be added to your Plex account webhooks.
When a media.play
or media.resume
event is received from Plex, PlexTogglTracker
creates a Toggl time entry and stops it when receives a media.pause
or media.stop
event.
The description of the time entry is always the title of what is being played. The project depends on the configuration. PlexTogglTracker
maps Plex libraries to Toggl projects. (See mapping).
Install it using pip or adding it to your requirements.txt
:
pip install git+https://github.com/twissell-/PlexTogglTracker@master
Import the module, configure it and register it into your flask app:
import plextoggltracker
from flask import Flask
app = Flask("app")
plextoggltracker.configure(
toggl_api_token="your_token"),
plex_username="your_plex_username",
mapping=["your mapping configuration"],
)
app.register_blueprint(
plextoggltracker.webhook, url_prefix="your_prefix")
)
app.run(host="0.0.0.0", port=86000)
The endpoint for the webhook is fixed: /webhook
. I recommend to generate a random hash and use it as url_prefix
when you register the blueprint, so the final endpoint ends up as something like 184bd97bddca7afd201cc2d0d77109f3/webhook
On linux you can generate the hash with:
echo $RANDOM | md5sum | head -c32
You can find it under "My Profile" in your Toggl account.
As it appears on you Plex profile. This is used to filter out events not generated by you.
A list of dictionaries telling PlexTogglTracker
what project assign to the created time entry based on in which library the file you are playing is. The default configuration is:
[
{
"libraries": ["TV Shows", "Movies"],
"project": "Watching TV"
}
]
This config will track videos on the "TV Shows" and "Movies" Plex libraries to entries on the "Watching TV" Toggl project.
Note: Media on libraries not defined here or assigned to a nonexistent project will be ignored.
- Only working for
movies
andepisode
Plex types.