Project status: Working fine; I have been using it for more than a year. If you have ideas for new features, suggestions are welcome.
An ActivityWatch watcher to report on when there's a video playing in mpv, and what it is.
Currently, only provides heartbeat events with the video's title and filename. This is enough to see what you watched and for how long.
The bucket used is aw-watcher-mpv-curplaying_CLIENTHOSTNAME
.
Notably, it works by scanning logs provided by another utility. This repo is for the -sender
part that scans the logs. The other part is aw-watcher-mpv-logger - an mpv
plugin that records the events as text files that the sender then scans.
- Install aw-watcher-mpv-logger by following the installation instructions there.
- Get the latest release from Releases, or see Build from source.
- Create folder
aw-watcher-mpv
in the same place were other watchers live. Examples:- Windows: If the path to aw-qt is
C:\Program Files\ActivityWatch\aw-qt.exe
, the path to the watcher's folder should beC:\Program Files\ActivityWatch\aw-watcher-mpv\
- Arch:
/opt/activitywatch/aw-watcher-afk
- Windows: If the path to aw-qt is
- Unpack contents of downloaded ZIP to newly created folder
aw-watcher-mpv
. (On Linux and maybe MacOS, you may need to give theaw-watcher-mpv
executable inside the execute permission -chmod +x aw-watcher-mpv
). - Restart ActivityWatch
- Right-click the tray icon and you should see
aw-watcher-mpv
appear in modules. Start it. On the first launch, it should fail immediately due to a lack of config (which will look to you like its entry in Modules not staying checkmarked). - In the AW Config directory (which is different than installation directory) find the automatically created file
aw-watcher-mpv\aw-watcher-mpv.toml
. Inside provide path to output of aw-watcher-mpv-logger (default<mpv root>/mpv_history
). For example:
Win:
log_folder = "C:/Program Files/mpv/mpv-history"
Linux:
log_folder = "/home/user/.config/mpv/mpv-history"
After this change, aw-watcher-mpv
should launch and run correctly.
- If you want
aw-watcher-mpv
to launch automatically, add it toautostart_modules
list ofaw-qt.toml
in the AW Config directory. Example config:
[aw-qt]
autostart_modules = ["aw-server", "aw-watcher-afk", "aw-watcher-window", "aw-watcher-mpv"]
Alternatively to letting AW launch the watcher, you may install aw-watcher-mpv-sender
as a python module and launch it via the command line (see python -m aw_watcher_mpv_sender --help
).
If you need to build from source:
- Clone the repository
- (Optional) Create a venv with e.g.
python -m virtualenv venv
and activate it (with e.g../venv/Scripts/activate
). poetry install
to get all the dependencies. You may need to dopip install poetry
first.pyinstaller --clean pyinstaller.spec
to build the module. After this, the folderdist/aw-watcher-mpv
will be the built module.
-
Currently, the log file for today is fully scanned every five seconds. This isn't too bad as the log file can't be more than a few megabytes for a full day, but a better way should be implemented later.- fixed, now the sender seeks to the last file end position. - Because the sender only checks the current day's logs, the last event or two from the last day (so, ~10 seconds of viewing time) may be lost. More generally, it doesn't scan old logs to discover events there.
- Visualizations? Would be nice to have something like "video titles by playing time".
- Counting video playing time as non-afk. That actually seems easy-ish to implement dashboard-side; it'd require adding another union here. Doing this in a generic fashion would of course need a PR.
- Automatically delete old
-logger
logfiles?
Initial draft of the logger code was based on mpv-history.lua - SqrtMinusOne graciously posted it when I asked on the AW discord if anyone knew of an existing AW watcher for mpv.