p-hueber / prefetcharr

Let Sonarr fetch the next season of a show you are watching on Jellyfin/Emby/Plex.
Other
41 stars 1 forks source link

plex/tautulli support? #18

Closed kysersoze81 closed 7 months ago

kysersoze81 commented 7 months ago

What's the chances of adding in plex support or tautulli for tracking watched episodes?

p-hueber commented 7 months ago

@kysersoze81 I just pushed #19, it would be great to get some feedback on it before I merge this. I don't use plex myself, so it didn't get much testing.

kysersoze81 commented 7 months ago

Just grabbed this now. (docker for testing)

Edit, set a log location. will it work if its set to jellyfin? because it doesn't like being set to plex Edit, Sorry I still have the main repo how do i swap to the plex version?

p-hueber commented 7 months ago

@kysersoze81 if you use the docker-compose example from the readme, just replace #latest with #plex and build the image again. use the server token as api key and make sure you got the url right - error reporting isn't ideal yet and an incorrect url goes unnoticed.

if everything is set up correctly, you should be able to see something like this in the logs if there's an active playback session

 INFO prefetcharr::process: title="The Bear" now_playing=NowPlaying { series: Tvdb(403294), episode: 1, season: 1 } 
kysersoze81 commented 7 months ago

For some reason i can't seem to pull the #plex build Docker version 26.0.0, build 2ae903e Docker Compose version v2.26.0 I've had to modify the compose.yml to get it to work at all

name: prefetcharr
services:
    prefetcharr:
        build: https://github.com/p-hueber/prefetcharr.git#plex
        environment:
            - MEDIA_SERVER_TYPE=plex
            - MEDIA_SERVER_URL=http://local.ip.address.home
            - MEDIA_SERVER_API_KEY=redacted
            - SONARR_URL=http://lan.ip.address.home/sonarr
            - SONARR_API_KEY=redacted
            - LOG_DIR=/log
            - RUST_LOG=prefetcharr
            - INTERVAL=900
            - REMAINING_EPISODES=2
        volumes:
            - /home/prefetcharr:/log
        image: prefetcharr
p-hueber commented 7 months ago

Did you mean to write "pull"? Because there is no image to pull, you have to build it. I can only guess what issues you are running into, but the error message might already suggest you to run something likedocker compose build prefetcharr. If that's not the problem, please post the error message you are facing and I can try to help

kysersoze81 commented 7 months ago

Sorry you were right. I needed to run docker-compose build in the docker-compose.yml folder to get it running Now i have this:

2024-04-01T08:20:02.577142Z  INFO prefetcharr: Start watching Plex sessions
2024-04-01T08:20:02.592275Z ERROR prefetcharr::media_server::plex: cannot fetch sessions from plex: error sending request for url (https://192.168.1.X:32400/status/sessions): error trying to connect: error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:../ssl/statem/statem_clnt.c:1889: (IP address mismatch)
2024-04-01T08:22:38.194173Z  INFO prefetcharr: Start watching Plex sessions
2024-04-01T08:22:39.971797Z ERROR prefetcharr::media_server::plex: cannot fetch sessions from plex: HTTP status client error (401 Unauthorized) for url (http://192.168.1.X:32400/status/sessions)

It doesn't seem to want to connect to plex as http or https I have network connectivity and everything else is communicating fine. what i have read online is about certificate issues with letsencrypt. which i think plex uses

Should i be using a client api key like the arr's?

p-hueber commented 7 months ago

First attempt is a certificate problem because your server cert cannot be used for an IP address. You'd have to use the domain your certificate was signed for. But it should work with http, as your second attempt shows. Double check you use the right token as suggested in a previous comment https://github.com/p-hueber/prefetcharr/issues/18#issuecomment-2025674877

kysersoze81 commented 7 months ago

Sorry to open this up again. The issue that i was having before was that you can't use "" for field in the docker-compose.yaml also the url's need to be "http://i.p.add.ress:port/baseurl" just wanted to confirm if this was an issue that needs solving before moving forward

2024-04-03T08:47:17.961702Z ERROR prefetcharr::process: Failed to process err=error decoding response body: missing field `statistics` at line 50759 column 7

Caused by:
    missing field `statistics` at line 50759 column 7

Thanks in advance

p-hueber commented 7 months ago

no problem at all, please keep commenting! I just closed this issue because plex support landed in the current 0.5.0 release. the error you are facing is not related to plex but to sonarr giving a response I did not anticipate. I'll make a quick fix to make this more resilient. could you tell me which version of sonarr you are using?

p-hueber commented 7 months ago

@kysersoze81 could you please build your container from main branch? just change #plex to #main in the yaml, stop the container, re-build and start it again. the error message should be gone, ignoring the offending series entry during lookup.

kysersoze81 commented 7 months ago

Sonar version 4.0.3.1413 Plex version 1.40.1.8227-c0dd5a73e

kysersoze81 commented 7 months ago

it built

[+] Building 57.5s (6/6) FINISHED                                                                                                                   docker:default
 => [prefetcharr internal] load git source https://github.com/p-hueber/prefetcharr.git#main                                                                 1.6s
 => [prefetcharr internal] load metadata for docker.io/library/rust:1.75.0                                                                                    1.8s
 => CACHED [prefetcharr 1/3] FROM docker.io/library/rust:1.75.0@sha256:87f3b2f93b82995443a1a558c234212dafe79cfdc3af956539610560369ddcd0                       0.0s 
 => [prefetcharr 2/3] COPY ./ ./                                                                                                                              0.1s 
 => [prefetcharr 3/3] RUN cargo build --release                                                                                                              50.9s 
 => [prefetcharr] exporting to image                                                                                                                          2.8s 
 => => exporting layers                                                                                                                                       2.8s 
 => => writing image sha256:f154b7cb1700e5d6e7a668e0ebd0c995b722e68a1dfe2fcc9e994ed0aaf92b55                                                                  0.0s 
 => => naming to docker.io/library/prefetcharr 

but this is the log output


Caused by:
    missing field `statistics` at line 50759 column 7
2024-04-03T11:06:31.596906Z  INFO prefetcharr: prefetcharr 0.5.0
2024-04-03T11:06:31.597061Z  INFO prefetcharr: Start watching Plex sessions

docker-compose.yml

name: prefetcharr
services:
    prefetcharr:
        build: https://github.com/p-hueber/prefetcharr.git#main
        environment:
            - MEDIA_SERVER_TYPE=plex
            - MEDIA_SERVER_URL=http://1.2.3.4:32400
            - MEDIA_SERVER_API_KEY=key
            - SONARR_URL=http://w.x.y.z:8989/sonarr
            - SONARR_API_KEY=other key
            - LOG_DIR=/log
            - RUST_LOG=prefetcharr
            - INTERVAL=900
            - REMAINING_EPISODES=2
        volumes:
            - /home/prefetcharr:/log
        image: prefetcharr
p-hueber commented 7 months ago

seems good so far! you don't see much in the log because the log level defaults to ERROR and the corresponding entry is not quite right in the yaml file. change it to RUST_LOG=prefetcharr=debug to see more than just errors.

kysersoze81 commented 7 months ago

Yeah ok. I changed it just to have a look. I'm getting some results like this on the ERROR level log

2024-04-03T12:06:31.851725Z DEBUG prefetcharr::sonarr: ignoring malformed series entry: missing field `statistics` series=Object {"added": String("2024-03-29T09:33:03Z"), "airTime": String("03:00"), "alternateTitles": Array [], "certification": String("12"), "cleanTitle": String("murdaughmurderssouthernscandal"), "ended": Bool(true), "firstAired": String("2023-02-22T00:00:00Z"), "genres": Array [String("Crime"), String("Documentary"), String("Mini-Series")], "id": Number(469), "images": Array [Object {"coverType": String("banner"), "remoteUrl": String("https://artworks.thetvdb.com/banners/v4/series/429854/banners/63d54e2f22912.jpg"), "url": String("/sonarr/MediaCover/469/banner.jpg?lastWrite=638473015835835484")}, Object {"coverType": String("poster"), "remoteUrl": String("https://artworks.thetvdb.com/banners/v4/series/429854/posters/63f109a4eb4b5.jpg"), "url": String("/sonarr/MediaCover/469/poster.jpg?lastWrite=638473015835915483")}, Object {"coverType": String("fanart"), "remoteUrl": String("https://artworks.thetvdb.com/banners/v4/series/429854/backgrounds/63fcc15fdda0d.jpg"), "url": String("/sonarr/MediaCover/469/fanart.jpg?lastWrite=638473015835995482")}], "imdbId": String("tt26340238"), "languageProfileId": Number(1), "lastAired": String("2023-09-20T00:00:00Z"), "monitorNewItems": String("all"), "monitored": Bool(true), "network": String("Netflix"), "originalLanguage": Object {"id": Number(1), "name": String("English")}, "overview": String("Shocking tragedies shatter a tight-knit South Carolina community and expose the horrifying secrets of its most powerful family."), "path": String("/mnt/share/TV Shows/Murdaugh Murders - A Southern Scandal (2023) - 429854"), "previousAiring": String("2023-09-20T08:22:00Z"), "qualityProfileId": Number(6), "ratings": Object {"value": Number(0), "votes": Number(0)}, "rootFolderPath": String("/mnt/share/TV Shows/"), "runtime": Number(41), "seasonFolder": Bool(true), "seasons": Array [Object {"monitored": Bool(false), "seasonNumber": Number(0)}, Object {"monitored": Bool(true), "seasonNumber": Number(1), "statistics": Object {"episodeCount": Number(3), "episodeFileCount": Number(3), "percentOfEpisodes": Number(100), "previousAiring": String("2023-02-22T09:22:00Z"), "releaseGroups": Array [String("NTb")], "sizeOnDisk": Number(7503346713), "totalEpisodeCount": Number(3)}}, Object {"monitored": Bool(true), "seasonNumber": Number(2), "statistics": Object {"episodeCount": Number(3), "episodeFileCount": Number(3), "percentOfEpisodes": Number(100), "previousAiring": String("2023-09-20T08:22:00Z"), "releaseGroups": Array [String("EDITH")], "sizeOnDisk": Number(4757850712), "totalEpisodeCount": Number(3)}}], "seriesType": String("standard"), "sortTitle": String("murdaugh murders a southern scandal"), "statistics": Object {"episodeCount": Number(6), "episodeFileCount": Number(6), "percentOfEpisodes": Number(100), "releaseGroups": Array [String("NTb"), String("EDITH")], "seasonCount": Number(2), "sizeOnDisk": Number(12261197425), "totalEpisodeCount": Number(6)}, "status": String("ended"), "tags": Array [Number(15)], "title": String("Murdaugh Murders: A Southern Scandal"), "titleSlug": String("murdaugh-murders-a-southern-scandal"), "tvMazeId": Number(66494), "tvRageId": Number(0), "tvdbId": Number(429854), "useSceneNumbering": Bool(false), "year": Number(2023)}
2024-04-03T12:06:31.854359Z  INFO prefetcharr::process: title="The Rookie" now_playing=NowPlaying { series: Tvdb(350665), episode: 4, season: 6 }
2024-04-03T12:06:31.854368Z DEBUG prefetcharr::process: ignoring early episode now_playing=NowPlaying { series: Tvdb(350665), episode: 4, season: 6 } season=SeasonResource { season_number: 6, monitored: true, statistics: SeasonStatisticsResource { size_on_disk: 15779141696, episode_count: 5, total_episode_count: 6, other: Object {"episodeFileCount": Number(5), "nextAiring": String("2024-04-10T01:00:00Z"), "percentOfEpisodes": Number(100), "previousAiring": String("2024-04-03T01:00:00Z"), "releaseGroups": Array [String("FLUX")]} }, other: Object {} }
p-hueber commented 7 months ago

great, works as expected. thank you!

with REMAINING_EPISODES=2, prefetcharr would attempt to search for the next season while you watch "The Rookie" S06E05. but as there's no S07 yet, it will only make sure that "The Rookie" is monitored in sonarr.

the first message complains about "Murdaugh Murders" having a season 0 without any episode counts. I assume it's some sort of special, so instead of filtering the whole series, I should rather ignore such seasons.