Skip to content

A simple webhook for tracking to Toggl the time spent watching stuff on Plex

License

Notifications You must be signed in to change notification settings

twissell-/PlexTogglTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlexTogglTracker

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.

How does it work?

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).

Basic Usage

Installation

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)

Configuration

endpoint

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

toggl_api_token

You can find it under "My Profile" in your Toggl account.

plex_username

As it appears on you Plex profile. This is used to filter out events not generated by you.

mapping

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.

Limitations

  • Only working for movies and episode Plex types.

About

A simple webhook for tracking to Toggl the time spent watching stuff on Plex

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages