l3uddz / plex_autoscan

Script to assist sonarr/radarr with plex imports. Will only scan the folder that has been imported, instead of the whole library section.
GNU General Public License v3.0
397 stars 70 forks source link

Incompatibility with the new Plex Movie agent #159

Open agneevX opened 3 years ago

agneevX commented 3 years ago

EDIT 2: With Plex Media Server v1.21.1.3759, the metadata issue for movies with the new agent have been fixed, and I've disabled Fix Mismatched.


EDIT: If Fix Mismatched is enabled, plex_autoscan will attempt to match the movie with the legacy agent, but the new agent (Plex Movie) will ignore it, so this is the best option as of now.

Fixing match of 'Baby Driver' (plex://movie/5d776ba0ad5437001f7a5376) to 'Baby Driver' (com.plexapp.agents.imdb://tt3890160?lang=en).
Successfully matched 'metadata_item_id' '22669' to 'Baby Driver' (com.plexapp.agents.imdb://tt3890160?lang=en).

When adding movies to a library with the new Plex Movie agent, the movie isn't added properly, with Fix Mismatched disabled.

Part of config.json:

"PLEX_FIX_MISMATCHED": false,
"PLEX_ANALYZE_TYPE": "basic",
"PLEX_CHECK_BEFORE_SCAN": false

As you can see, there's missing info and no cast info is downloaded.

Screen Shot 2020-10-31 at 8 19 40 PM

(The metadata-fetching visible is because I hit Refresh Metadata)

bad1dea commented 3 years ago

Can you post your log from plex_autoscan?

I have fix mismatched options enabled, and have no issues with the scanner. Only thing is, it changes the poster data, but everything else will populate.

If Plex is set up properly with the new movie agent, Plex Autoscan will tell Plex to scan using it, and once it's completed, it will change the guid to one of the legacy ones.. doesn't effect what you are describing.

I had a similar issue to what you did, and it ended up being a permission issue. Can you validate your PLEX User (either for docker or sudo).. that fixed issue for me after months of wondering what was going on.

I ended up scripting something to fix 16000 entries in movies the past 2 weeks.

 2020-11-07 02:28:25,354 -     INFO -      PLEX [139713792956160]: Finished basic analysis of 'metadata_item': 207294

 2020-11-07 02:28:35,375 -     INFO -      PLEX [139713792956160]: No duplicate 'media_items' found with 'metadata_item_id': '207294'

 2020-11-07 02:28:35,375 -     INFO -      PLEX [139713792956160]: Fixing match of 'Better Luck Tomorrow' (plex://movie/5d9f351268e4c8001fb5e46b) to 'Better Luck Tomorrow' (com.plexapp.agents.imdb://tt0280477?lang=en).

 2020-11-07 02:28:35,989 -     INFO -      PLEX [139713792956160]: Successfully matched 'metadata_item_id' '207294' to 'Better Luck Tomorrow' (com.plexapp.agents.imdb://tt0280477?lang=en).

 2020-11-07 02:28:35,995 -     INFO -      PLEX [139713792956160]: Successfully refreshed 'metadata_item_id' '207294' of 'Better Luck Tomorrow'.

001

agneevX commented 3 years ago

@bad1dea

My logs are very similar to yours.

If Plex is set up properly with the new movie agent, Plex Autoscan will tell Plex to scan using it, and once it's completed, it will change the guid to one of the legacy ones

I've re-enabled Fix Matched and checked two files. One was added by plex_autoscan, the other was added manually. Both have plex:// in their GUID.

So, despite this line, it is not being matched to the legacy agent.

2020-11-07 02:28:35,375 - INFO - PLEX [139713792956160]: Fixing match of 'Better Luck Tomorrow' (plex://movie/5d9f351268e4c8001fb5e46b) to 'Better Luck Tomorrow' (com.plexapp.agents.imdb://tt0280477?lang=en).

Can you validate your PLEX User (either for docker or sudo).. that fixed issue for me after months of wondering what was going on.

Plex runs under its own user, so I have sudo enabled in the config file.

Technically speaking, turning off Fix Mismatched should let Plex automatically scan with the new agent, but I suspect that the scanning or the scan command is not the same as the legacy agent.

bad1dea commented 3 years ago

Hard to go further without seeing your Plex Log with Debug enabled (not verbose) while scanning an item.

If you can run the following and fill in xyz

curl -s -X PUT -i 'http://XXXXXXXXXX:32400/library/metadata/YYYYYYYYYYY/refresh?X-Plex-Token=ZZZZZZZZZZZ'

X = hostname/fqdn to plex server
Y = metadata id (example 207294 for my log from previous post)
Z = Plex Token (can use the same on Plex Autoscan) is using.

^ if the above command works and fixes the metadata, then there is something rogue going on with Plex_Autoscan, most likely permission issue.

I agree the movie agent should be added, I even took a look at adding it myself, unfortunately unless Plex gives us some rhyme or reason to the plex://movie/HASH it's hard to validate it from Plex Autoscan.

They did add XML tags/db entries with the TMDB_ID and IMDB_ID for other 3rd party tools (which Iuse to correct legitimate errors with metadata)

<Guid id="imdb://tt5981656"/>
<Guid id="tmdb://494750"/>

Which I guess, we could generate/validate against instead of forcing a com.plexapp.agents.XXXX://ID

bad1dea commented 3 years ago

If you want to keep fix mismatch on for TV show for now.. you can edit

Line 333 of plex.py to the following

from
    if parent_guid and (parent_guid.lower() != new_guid):
to
    if parent_guid and (parent_guid.lower() != new_guid) and ("plex://movie/" not in parent_guid.lower()):

It'll just skip it for the movies (anything with plex://movie/)

I'm working on adding another function to grab the id's from the tags, and validate it that way, since we don't know how the new plex movie agent generates it's guid hash.

Considering there is a new TV Plex Agent coming out, we'll run into this issue for TV Series soon too.

If you want to help test, let me know.

agneevX commented 3 years ago

I don't understand why Fix Mismatched has to be enabled in the first place.

If a scan request is sent to Plex for the particular file (which has a proper name structure), it should add the file to the library without any issue.

That scan request is not updated for the new agent.

bad1dea commented 3 years ago

The reason for the option is for a few reasons.

1) Plex movie scanning is based off of TITLE, YEAR 2) Plex tv scanning is based off of the general notations, SXXEXX, 2020-XX-XX, or whatever.

Sometimes, the scanner mostly movies, ends up finding dupes, or sometimes the database has wrong years for movies (production, vs released, etc etc)

When Sonarr/Radarr are set up to connect to Plex Autoscan, it tells PLEX to scan, but also provides Plex_autoscan with additional information.

Mainly the IMDB/TMDB ID's for the Episode/Show/Movie, and all it tries to do is make sure the ID is found for that Item once it's been added, it's just to make sure Plex finds what Sonarr/Radarr found. If it doesn't match, it forces Plex to use the ID's supplied by Radarr/Sonarr.

Plex scanner is a hit or miss, it'll work 99% of the time, and then stop for some odd qwirk, its really messed up.

 2020-11-09 08:37:40,411 -    DEBUG -  AUTOSCAN [140078605133568]: Client '10.10.10.9' request dump:
{
    "downloadId": "d7140a5ad334476b802e3b7ba144d753",
    "eventType": "Download",
    "isUpgrade": false,
    "movie": {
        "folderPath": "/movies/For Better or For Worse (2014)",
        "id": 15728,
        "imdbId": "tt3579488",
        "releaseDate": "9999-12-31",
        "title": "For Better or For Worse",
        "tmdbId": 284166
    },
    "movieFile": {
        "id": 88922,
        "path": "/downloads/completed/movies/For.Better.or.For.Worse.2014.1080p.AMZN.WEB-DL.DDP5.1.H.264-DONNA/e457cdb6841d3bbe76bb750fd565bd05.mkv",
        "quality": "WEBDL-1080p",
        "qualityVersion": 1,
        "relativePath": "For Better or For Worse (2014) WEBDL-1080p.mkv",
        "releaseGroup": "DONNA",
        "sceneName": "For.Better.or.For.Worse.2014.1080p.AMZN.WEB-DL.DDP5.1.H.264-DONNA",
        "size": 6366636601
    },
    "remoteMovie": {
        "imdbId": "tt3579488",
        "title": "For Better or For Worse",
        "tmdbId": 284166,
        "year": 2014
    }
}
asw13537 commented 3 years ago

I have the same issue where metadata is not pulling down until i manually refresh. I have the mismatch disabled however my movies are formatted into movie (year) {imdb-tt123456}.mkv format. Plex should pick up on the imdb reference. Running plex in docker, I don't see any permission issues. Data can be manually refreshed fine.

agneevX commented 3 years ago

That's because the scan request for the new agent isn't the same as for the old agent.

I made a rough script for Radarr auto scanning here: https://gist.github.com/agneevX/a865bc1821a1c6e5ca4a80fab5d2316a

asw13537 commented 3 years ago

i tried the script, it just does a scan, doesn't pull the metadata.

Running this refreshed the item and pulled the missing data down. Have tried redeploying plexautoscan but still same issue.

curl -s -X PUT -i 'http://XXXXXXXXXX:32400/library/metadata/YYYYYYYYYYY/refresh?X-Plex-Token=ZZZZZZZZZZZ'

X = hostname/fqdn to plex server Y = metadata id (example 207294 for my log from previous post) Z = Plex Token (can use the same on Plex Autoscan) is using.

bad1dea commented 3 years ago

I’ll post my script once I get home

Get Outlook for iOShttps://aka.ms/o0ukef


From: asw13537 notifications@github.com Sent: Thursday, November 12, 2020 1:51:55 PM To: l3uddz/plex_autoscan plex_autoscan@noreply.github.com Cc: bad1dea khuong@live.ca; Mention mention@noreply.github.com Subject: Re: [l3uddz/plex_autoscan] Add support for new Plex Movie agent (#159)

i tried the script, it just does a scan, doesn't pull the metadata.

Running this refreshed the item and pulled the missing data down. Have tried redeploying plexautoscan but still same issue.

curl -s -X PUT -i 'http://XXXXXXXXXX:32400/library/metadata/YYYYYYYYYYY/refresh?X-Plex-Token=ZZZZZZZZZZZ'

X = hostname/fqdn to plex server Y = metadata id (example 207294 for my log from previous post) Z = Plex Token (can use the same on Plex Autoscan) is using.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fl3uddz%2Fplex_autoscan%2Fissues%2F159%23issuecomment-726270321&data=04%7C01%7C%7Ceefa0a37f8394233978008d8873c06bd%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408039160647620%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BafZ03Qg%2FqTEtXGNoy%2B8IlUWcMaqIaimgZac%2Fh0k1Co%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACPAA7RV4W2GU7PJQY63CEDSPQVEXANCNFSM4TF5Y4ZA&data=04%7C01%7C%7Ceefa0a37f8394233978008d8873c06bd%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408039160657612%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9aBSFrwg%2FR1m4Gp39t%2FG7OAIi4vXK3OQ5xssfqoI%2BN0%3D&reserved=0.

asw13537 commented 3 years ago

cheers buddy.

bad1dea commented 3 years ago

Here you go..

https://gist.github.com/bad1dea/406076a2c6708930bc18371f059f5845

bad1dea commented 3 years ago

What the script does is,

Looks through your database for any Movies (by section id) that do not have proper tagging, and forces plex to do a scan on JUST that item.

You need sqlite3, and curl installed.

agneevX commented 3 years ago

i tried the script, it just does a scan, doesn't pull the metadata.

Are you sure? I just tried it right now and it pulled all the info for the item.

bad1dea commented 3 years ago

It will only pull meta data if your Plex is set up properly. Same as Plex Autoscan.

If you can go to Plex, select the movie, and do refresh auto scan and it downloads it. It’ll just make that process easier in the long run.

If there is a mismatch, or you need to do a “match” or “fix match” in Plex, that’s separate.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Agneev Mukherjee notifications@github.com Sent: Friday, November 13, 2020 4:25:49 AM To: l3uddz/plex_autoscan plex_autoscan@noreply.github.com Cc: bad1dea khuong@live.ca; Mention mention@noreply.github.com Subject: Re: [l3uddz/plex_autoscan] Add support for new Plex Movie agent (#159)

i tried the script, it just does a scan, doesn't pull the metadata.

Are you sure? I just tried it right now and it pulled all the info for the item.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fl3uddz%2Fplex_autoscan%2Fissues%2F159%23issuecomment-726652846&data=04%7C01%7C%7C976910de0af84d211faa08d887b61cb0%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408563514655948%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BUPGDflPNcb6916%2FEzUgnpks9advM1sJuf8Sy0jv1L4%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACPAA7RLSV6JZKBZ54SJGYTSPT3R3ANCNFSM4TF5Y4ZA&data=04%7C01%7C%7C976910de0af84d211faa08d887b61cb0%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408563514665940%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=6hRgPT46Hl2eY8cD3aB4N7gd6eg8lftcSqe1FZoqTbE%3D&reserved=0.

agneevX commented 3 years ago

How often do you get mismatches? Personally, I've never encountered mismatches.

bad1dea commented 3 years ago

0 Mismatches.

What happens is, everything will work fine, then suddenly movies will do what OP describes, where it doesn’t grab Metadata without manual refresh. Then I run script to fix the 5-20 items.

Then it all works perfectly for a while, and repeat. Unfortunately Plex is a bit finicky. I’ve learned to live with its quirks.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Agneev Mukherjee notifications@github.com Sent: Friday, November 13, 2020 12:05:56 PM To: l3uddz/plex_autoscan plex_autoscan@noreply.github.com Cc: bad1dea khuong@live.ca; Mention mention@noreply.github.com Subject: Re: [l3uddz/plex_autoscan] Add support for new Plex Movie agent (#159)

How often do you get mismatches? Personally, I've never encountered mismatches.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fl3uddz%2Fplex_autoscan%2Fissues%2F159%23issuecomment-726880261&data=04%7C01%7C%7C32604e97cfcc4adb239e08d887f6635e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408839606279582%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=k0eDDZyzDdk3U2sRQSKAzu0uRWkL9cUAROO%2FxIGki3o%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACPAA7RGDSSNSLRSHC5FA4DSPVRPJANCNFSM4TF5Y4ZA&data=04%7C01%7C%7C32604e97cfcc4adb239e08d887f6635e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637408839606289581%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=deKHp%2F1na7rPmdxklzZ4o%2FctGSYMIhp01s1S4gQBz3c%3D&reserved=0.

dennisoderwald commented 3 years ago

Here you go..

https://gist.github.com/bad1dea/406076a2c6708930bc18371f059f5845

Thank you. I took the liberty of optimizing the query, as it would have skipped some titles that did not meet the criteria. So I make sure that every file is updated.

SELECT id FROM metadata_items WHERE refreshed_at IS NULL AND media_item_count > 0 AND library_section_id IS $PLEX_MOVIE_SECTION_ID ORDER BY added_at ASC

asw13537 commented 3 years ago

my section Id for movies is 11 , check the image, movies metadata_type in my movies is 12 or 1, so i need to amend your script I think and change the 18 to either 12 or 1..Im not sure can you advise SELECT metadata_item_id FROM taggings) AND metadata_type IS NOT 18 AND library_section_id IS $PLEX_MOVIE_SECTION_ID ORDER BY title ASC;"

https://ibb.co/rF8SNtL

bad1dea commented 3 years ago

Leave 18 alone -that is Metadata TYPE.. not section id.. change the variable.. not any of the numbers..

18 = Collections, not Movies.

PLEX_MOVIE_SECTION_ID=11

bad1dea commented 3 years ago

Only edit the below, you can replace the QUERY with the one supplied by dennis if that suites you better.

PLEX_DATABASE_PATH="Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" # Full path to PLEX DB
PLEX_TOKEN="xxx" # Plex Token -- Can use PLEX_AUTOSCAN Token
PLEX_URL="http://127.0.0.1:32400" # URL to PLEX Server (must be reachable)
PLEX_MOVIE_SECTION_ID="1" # Set this to SECTION ID of Movies
asw13537 commented 3 years ago

thanks for your help but when i run it with your config. Nothing actually scans or refreshes. I don't see anything happening with it. SQL connects, runs and finishes but i see nothing happening in plex. Checking alerts and console.

I am running the script on the same host. Reverse proxy. The web url is reacable plex.domain.com:443 My section id is right 11.

I know when i run the curl on its own, works when i fill in details manually. Any thoughts?

Not sure if this holds any relevance, but the metadata that is missing rating, cast ect, it does pull down some like synopsis. Would this have an impact on the script filtering for missing data?

asw13537 commented 3 years ago

I have your script now working, however it will only refresh the metadata for one movie, normally the last movie that has has been added. It's not picking up on the other movies that require metadata.

Ameded the script to also look for audience_rating is NULL this picks up on the movies that it is not refreshing the metadata for. Granted not ideal as a couple of movies that i have which dont have a rating but works fine.

Horribleness commented 3 years ago

Plex_Autoscan is working well with the latest changes to PMS 1.21.1.3759 (changelog):

agneevX commented 3 years ago

This would explain the behavior when Fix Mismatched is disabled.