Repository navigation
Syncing Jellyfin watch history to Tunarr tags (for Smart Collections) #1894
joopdo
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hey all,
I wanted to share something I've been working on that others might find useful.
The use case: I want to create Smart Collections based on watch history. For example, a "Simpsons - Watched" collection that only contains episodes I've already seen, so I can build a channel from those.
My setup: I use local media files as my Tunarr source (not Jellyfin/Plex as a media source) to avoid unnecessary transcoding. But I do use Jellyfin as my primary player, so that's where my watch history lives. The two systems don't talk to each other natively.
The problem: Tunarr's Smart Collections use the Meilisearch index for filtering, but the
tagsfield in the index only gets populated during media ingestion. If you add tags directly to the SQLite database (viatag_relations), they show up in the API (/api/programs/{id}returns"tags": ["watched"]) but the search index doesn't know about them. Sotags in ["watched"]returns 0 results in a Smart Collection.The solution: After writing tags to the database, you can also update the Meilisearch index directly using a PUT request to the embedded Meilisearch instance. The key insight is that PUT to
/indexes/programs/documentsdoes a partial update (only changes the fields you send, keeps everything else intact), while POST does a full replace (which will destroy your documents if you only send{id, tags}). Learned that one the hard way.I wrote a script that does the full sync. It also handles the reverse: when you mark something as unwatched in Jellyfin, the tag gets removed from both the DB and the search index on the next run. I run it on a cron every hour or so.
Some things I learned along the way that might save others some pain:
tag_relationstable needs explicit columns:(tag_id, program_id, grouping_id, source)withgrouping_id = NULLandsource = 'media'. If you skipgrouping_id, the columns shift and things break silently./indexes/programs/documents?primaryKey=idfor partial updates/proc/*/cmdlineinside the container (it's random on each start)Here's the script for anyone interested:
sync-watched.sh (click to expand)
Works on Tunarr 1.2.20 with the embedded Meilisearch 1.30. Requires
jq,sqlite3, andcurlon the host.All reactions