z411 / trackma

Open multi-site list manager for Unix-like systems. (ex-wMAL)
https://z411.github.io/trackma
GNU General Public License v3.0
779 stars 81 forks source link

Jellyfin tracker only picks episode name #552

Open MyFilippo94 opened 3 years ago

MyFilippo94 commented 3 years ago

I've succeffully set up integration with Jellyfin, but when the player completes the episode, Trackma asks me to add a new serie with the episode's name. In other words, Trackma receives from Jellyfin only the episode name, and isn't able to recognize the serie's name, season and episode number.

Jellyfin's folder structure is organized according to The TVDB standard, as an example:

As a result, it is of course unable to automatically update the list's progress, as it can't find a "Karen Bee - Part 1" serie.

I did look around in the settings, but nothing suggests I might've missed a configuration. Can I solve it by myself, or is it a software limitation?

FichteFoll commented 3 years ago

Should be addressed by #547. Can you test that locally?

FichteFoll commented 3 years ago

Note that you'll have to add an altname for "Monogatari 2" since there's no way trackma could deduce the correct anime title from that naming, unless it was configured as an alternative title by the API you use already (which is unlikely).

MyFilippo94 commented 3 years ago

I am afraid it didn't work. I admit I am not used to installing pr from github, so what I did was download the main branch, and then the three modified files from #547, merge them on the folder (respecting the paths of course), and then proceed with installation instructions (removing the previous installation first).

Launching it from the terminal still shows that it didn't manage to fetch the serie's name. I moved it to my current anilist progress to test if it'd increase by 1, so the test file was "Monogatari/Season 3/Monogatari - S03E13 - Nadeko Medusa - Part 1 Bluray-1080p.mkv". I did add "Monogatari 3" as alternate name to "Monogatari Series: Second Season" in Trackma, although it wasn't useful, as there's no trace of the season's name in the readout. The end result was the same, as by settings the program opened a dialog asking me if I wanted to add "Nadeko Medusa - Part" serie to my list.

This is the output:

Engine: Trackma v0.8.4 - using account <username>(anilist).
Engine: Reading config files...
Data: Initializing...
libanilist: Initializing...
Data: Using libanilist (anime)
libanilist: Downloading list...
Engine: Parsing redirection file...
Engine: Scanning local library...
Tracker (Jellyfin): Initializing...
Tracker (Jellyfin): Using Jellyfin.
Ready.
Tracker (Jellyfin): Will add Nadeko Medusa - Part 1
Tracker (Jellyfin): Waiting for the player to close.

I'm using Monogatari as an example, but I think none of other shows updated succeffully. Notable mention is "Beastars/Season 2/Beastars - S02E10 - Episode 10 HDTV-1080p.mkv", returning a Tracker (Jellyfin): Found video but the file name format couldn't be recognized. message

FichteFoll commented 3 years ago

That definitely doesn't look correct. Can you test with the -d debug flag and paste the output here? That should reveal whether you are indeed running the changes.

Other than that, you can clone arbitrary branches (from pull requets) by checking which branch the PR was created from and then usign git clone https://github.com/FichteForks/trackma.git --branch pr/tweak-show-recognition, or by using the Github CLI client on the main clone and doing gh pr checkout 547 or by adding the fork as an additional remote and then checking that out directly.

Also, what OS are you on?

MyFilippo94 commented 3 years ago

I was running the changes, I did put a customized print("some random string "+self.name) function on that name to see what the var contained, and it did print the output I did put. I removed it in the report as it was not relevant. Thanks for the instructions with git, I downloaded and installed it again, and run with trackma-qt -d

This is the output:

Trackma-qt v0.8.4
Showing debug information.
Icon theme "adwaita" not found.
Icon theme "ubuntu-mono" not found.
Icon theme "yaru" not found.
Icon theme "Mint-X" not found.
Icon theme "elementary" not found.
Engine: Trackma v0.8.4 - using account <username>(anilist).
Engine: Reading config files...
Data: Initializing...
[D] Data: Reading userconfig...
libanilist: Initializing...
Data: Using libanilist (anime)
[D] Data: Locking database...
[D] Data: Reading metadata...
[D] Data: Reading queue...
[D] Data: Reading info DB...
[D] Data: No items in queue.
[D] Data: No items in queue.
libanilist: Downloading list...
[D] Data: Saving userconfig...
[D] Data: Saving cache...
[D] Data: Saving metadata...
Engine: Parsing redirection file...
Engine: Can't auto-scan library: Media directories not set.
[D] Engine: Initializing tracker...
Tracker (Jellyfin): Initializing...
[D] Tracker (Jellyfin): Enabling tracker...
Tracker (Jellyfin): Using Jellyfin.
Ready.
[D] Tracker (Jellyfin): Guessing filename: Nadeko Medusa - Part 1
[D] Tracker (Jellyfin): Show guess: Nadeko Medusa - Part: None
Tracker (Jellyfin): Will add Nadeko Medusa - Part 1
[D] Tracker (Jellyfin): Guessing filename: Nadeko Medusa - Part 1
[D] Tracker (Jellyfin): Same filename as before. Skipping.
Tracker (Jellyfin): Waiting for the player to close.

Then it did, again, proceed prompting me for a "Nadeko Medusa - Part" serie to be added.

Looks like it is unable to retrieve the filename, which indeed is pretty important. I'm running my main OS in a VM with GPU-Passthrough, It's an arch based linux distro, Garuda KDE Dr460nized, link here: https://garudalinux.org/downloads.html. It is running without an issue, as far as I can tell.

Jellyfin is in a docker container in a different VM, routed through a reverse proxy (Nginx proxy manager). It's reachable (only in local network) through http://url/ (routing to port 8096), and these further custom nginx configurations are added (I added them for Jellyfin MPV Shim to work):

location = /web {
    # Proxy main Jellyfin traffic
    proxy_pass http://$server:$port/web/index.html;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Protocol $scheme;
    proxy_set_header X-Forwarded-Host $http_host;
}

location /socket {
    # Proxy Jellyfin Websockets traffic
    proxy_pass http://$server:$port;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Protocol $scheme;
    proxy_set_header X-Forwarded-Host $http_host;
}

Am I perhaps meant to route another port for trackma to be able to reach the file name from the server?

Edit: I just now noticed there's a docker version of Trackma in the main page. I'll eventually take a look at that once I am sure it can reliably monitor Jellyfin, sounds like a very convenient solution for my needs. Althought I'll still have to add alternate names manually.

FichteFoll commented 3 years ago

Thanks for the logs. It appears that the Jellyfin tracker only receives the episode name "Nadeko Medusa - Part 1" for show guessing, which it obviously cannot match to "Monogatari". I don't know how Jellyfin works, e.g. whether it extracts the media title set in the file's metadata, but from trackma's PoV this is the problem.

I have verified that "Monogatari - S02E01 - Karen Bee - Part 1.mkv" is recognized correctly in my PR and added a test case for it.

MyFilippo94 commented 3 years ago

I looked into the code, and found a possible solution to this problem. I apologize for my "non github" way of presenting it.

File trackma/tracker/jellyfin.py, row 114. "file_name": current_session['Name'], Here you fetch from a json object the name, or the title of the episode. I banally loaded the url you look up for in the browser, and saw that you have actually access to a lot of very useful stuff in this NowPlayingItem object. Here are some lines that are interesting:

"NowPlayingItem": {
    "Name": "Nadeko Medusa - Part 1",
    "Path": "/anime/Monogatari/Season 3/Monogatari - S03E10 - Nadeko Medusa - Part 1 Bluray-1080p.mkv",
    "ProviderIds": {
        "Tvdb": "4590177"
    },
    "SeriesName": "Monogatari",
    "SeasonName": "Stagione 3",
    "MediaStreams": [
        {
            "Title": "Otorimonogatari 01",
            "DisplayTitle": "Otorimonogatari 01 - 1080p - H264 - SDR",
        },
},

Jellyfin seems to offer plenty of information actually for Trackma to be able to identify the serie. You could make some big effort and reach for "Providers" and fetch some metadata to then, hopefully, match a corresponding Anilist object, but even without that, you can easely reconstruct that this is episode 10 of serie Monogatari season 3.

In other words, rather than fetching current_session['Name'], you could definitely extract and parse S03E10 from current_session['Path'].split('//')[-1], or perhaps have a deeper look into searching some more relevant objects in the NowPlayingItem object. Then it's on the user to specify that "Monogatari Series: Second Season" has an alternate "Monogatari 3" title.

FichteFoll commented 3 years ago

The same also happens for the mpris tracker, where sometimes very misleading media titles can shadow the much more descriptive filename. That's a more fundamental decision that we should discuss with @z411. Maybe there needs to be a new option that prefers the filename over the media title if both are accessible?

MyFilippo94 commented 3 years ago

That's true, a correct naming is required for this to work. I am following the official directions for how to organize a TVDB valid library for Jellyfin, here: https://jellyfin.org/docs/general/server/media/shows.html. I assume therefore that this should be a very common system for Jellyfin users, that if supported should cover a large amount of cases. Note that Jellyfin also shares "SeriesName" and "SeasonName", along with stuff like "IndexNumber": 10 "ParentIndexNumber": 3, that undocumented me would guess it being the index respectively of episode and serie, so there should be metadata indipendent from the filename, that Jellyfin either automatically guessed, or the user manually inputed, that should be reliable enough for at least a correct "Jellyfin compliant" recognization of the serie, a starting point to reach for an "Anilist compliant" one.

ahmubashshir commented 3 years ago

The same also happens for the mpris tracker, where sometimes very misleading media titles can shadow the much more descriptive filename. That's a more fundamental decition that we should discuss with @z411. Maybe there needs to be a new option that prefers the filename over the media title if both are accessible?

I actually patched mpris tracker to ignore media title in my local branch :3

slapelachie commented 3 years ago

Yes I did use the TVDB standard when implementing this tracker. I implemented it to take the name of the folder and try to match it with an existing anime through the tracker website you are using. For example, I have my own library as name-of-series/name-of-series_ep#.ext

In regards to the media title issue, I noticed this issue with Monogatari as well and did my own fix but didn't push it as I forgot. I however have now made a merge request under #571 to fix this issue and use the name of the folder instead.

If there are any further questions or problems please let me know.

FichteFoll commented 3 years ago

Just FYI, I'm still very much interested in adding an option for ignoring the media title if the tracker type supports it, since it breaks a lot for some files when using the MPRIS tracker, but haven't found the time to work on it yet.