ZeroQI / YouTube-Agent.bundle

Plex Metadata Agent for Movies and TV Series libraries
452 stars 43 forks source link

Downloaded Episode is not updating metadata in Plex #67

Closed harroguk closed 3 years ago

harroguk commented 3 years ago

Clicking refresh metadata on the episode in plex produces the following in com.plexapp.agents.youtube.log

2021-02-05 19:32:10,950 (4b0) :  DEBUG (runtime:717) - Handling request GET /:/plugins/com.plexapp.agents.youtube/messaging/function/X0FnZW50S2l0OlVwZGF0ZU1ldGFkYXRh/Y2VyZWFsMQoxCmxpc3QKMApyMAo_/Y2VyZWFsMQoxCmRpY3QKMTAKczIKeG5zNApsYW5nYjFzNQpmb3JjZWIwczgKcGVyaW9kaWNzNQo5MjQyMnM0CmRiaWRpMApzNwp2ZXJzaW9uczEyMApjb20ucGxleGFwcC5hZ2VudHMueW91dHViZTovL3lvdXR1YmV8VUM2eXpWX3hnS244cjc3RmtjbVp5TVNnfFBsYXlTdGF0aW9uIEFjY2VzcyBbVUM2eXpWX3hnS244cjc3RmtjbVp5TVNnXS8yMDIxP2xhbmc9eG5zMTAKcGFyZW50R1VJRHM1Cjg4NzQxczgKcGFyZW50SURzNwpUVl9TaG93czEwCm1lZGlhX3R5cGVzMTMwCmNvbS5wbGV4YXBwLmFnZW50cy55b3V0dWJlOi8veW91dHViZXxVQzZ5elZfeGdLbjhyNzdGa2NtWnlNU2d8UGxheVN0YXRpb24gQWNjZXNzIFtVQzZ5elZfeGdLbjhyNzdGa2NtWnlNU2ddLzIwMjEvMTAyMDUxNzAxP2xhbmc9eG5zNApndWlkczc4CnlvdXR1YmV8VUM2eXpWX3hnS244cjc3RmtjbVp5TVNnfFBsYXlTdGF0aW9uIEFjY2VzcyBbVUM2eXpWX3hnS244cjc3RmtjbVp5TVNnXXMyCmlkcjAK
2021-02-05 19:32:10,950 (4b0) :  DEBUG (runtime:49) - Received packed state data (80 bytes)
2021-02-05 19:32:10,951 (4b0) :  DEBUG (runtime:814) - Found route matching /:/plugins/com.plexapp.agents.youtube/messaging/function/X0FnZW50S2l0OlVwZGF0ZU1ldGFkYXRh/Y2VyZWFsMQoxCmxpc3QKMApyMAo_/Y2VyZWFsMQoxCmRpY3QKMTAKczIKeG5zNApsYW5nYjFzNQpmb3JjZWIwczgKcGVyaW9kaWNzNQo5MjQyMnM0CmRiaWRpMApzNwp2ZXJzaW9uczEyMApjb20ucGxleGFwcC5hZ2VudHMueW91dHViZTovL3lvdXR1YmV8VUM2eXpWX3hnS244cjc3RmtjbVp5TVNnfFBsYXlTdGF0aW9uIEFjY2VzcyBbVUM2eXpWX3hnS244cjc3RmtjbVp5TVNnXS8yMDIxP2xhbmc9eG5zMTAKcGFyZW50R1VJRHM1Cjg4NzQxczgKcGFyZW50SURzNwpUVl9TaG93czEwCm1lZGlhX3R5cGVzMTMwCmNvbS5wbGV4YXBwLmFnZW50cy55b3V0dWJlOi8veW91dHViZXxVQzZ5elZfeGdLbjhyNzdGa2NtWnlNU2d8UGxheVN0YXRpb24gQWNjZXNzIFtVQzZ5elZfeGdLbjhyNzdGa2NtWnlNU2ddLzIwMjEvMTAyMDUxNzAxP2xhbmc9eG5zNApndWlkczc4CnlvdXR1YmV8VUM2eXpWX3hnS244cjc3RmtjbVp5TVNnfFBsYXlTdGF0aW9uIEFjY2VzcyBbVUM2eXpWX3hnS244cjc3RmtjbVp5TVNnXXMyCmlkcjAK
2021-02-05 19:32:10,953 (4b0) :  DEBUG (model:32) - Loading model with GUID com.plexapp.agents.youtube://youtube|UC6yzV_xgKn8r77FkcmZyMSg|PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]/2021/102051701?lang=xn
2021-02-05 19:32:10,953 (4b0) :  DEBUG (model:234) - Deserializing from C:\Users\Administrator\AppData\Local\Plex Media Server\Metadata\TV Shows\f\3f527ab031001fbf0fddbc0c7cee2fcc3174ba2.bundle\Contents\com.plexapp.agents.youtube\Info.xml
2021-02-05 19:32:10,957 (4b0) :  DEBUG (networking:143) - Requesting 'http://127.0.0.1:32400/library/metadata/92422/tree'
2021-02-05 19:32:10,963 (4b0) :  INFO (logkit:16) - update()
2021-02-05 19:32:10,964 (4b0) :  INFO (logkit:16) - D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]\PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].mp4
2021-02-05 19:32:10,966 (4b0) :  INFO (logkit:16) - D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]\PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].mp4
2021-02-05 19:32:10,966 (4b0) :  INFO (logkit:16) - =============================================================================================================================================================
2021-02-05 19:32:10,966 (4b0) :  INFO (logkit:16) - Attempting to load details from json file - json_filename: D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]\PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].info.json
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - =============================================================================================================================================================
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - update() using json file with api as backup - guid: UC6yzV_xgKn8r77FkcmZyMSg, dir: D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg], metadata.id: youtube|UC6yzV_xgKn8r77FkcmZyMSg|PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - [ ] dir:        "D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]"
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - [ ] library:    "YouTube"
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - [ ] root:       "D:\TV\YouTube"
2021-02-05 19:32:10,967 (4b0) :  INFO (logkit:16) - [ ] path:       "PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]"
2021-02-05 19:32:11,155 (4b0) :  INFO (logkit:16) - [ ] series_root_folder: "D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]"
2021-02-05 19:32:11,155 (4b0) :  INFO (logkit:16) - [ ] subfolder_count:    "0"
2021-02-05 19:32:11,157 (4b0) :  INFO (logkit:16) - Grouping folder not found or single folder, root: D:\TV\YouTube, path: PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg], Grouping folder: PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg], subdirs: 0, reverse_path: [u'PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]']
2021-02-05 19:32:11,157 (4b0) :  INFO (logkit:16) - No GUID so random folder
2021-02-05 19:32:11,196 (4b0) :  DEBUG (networking:138) - Fetching 'https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics%2CbrandingSettings&id=UC6yzV_xgKn8r77FkcmZyMSg&key=[snipped]' from the HTTP cache
2021-02-05 19:32:11,236 (4b0) :  INFO (logkit:16) - [?] json_channel_details: [u'kind', u'statistics', u'contentDetails', u'brandingSettings', u'snippet', u'etag', u'id']
2021-02-05 19:32:11,236 (4b0) :  INFO (logkit:16) - [ ] title:       "PlayStation Access"
2021-02-05 19:32:11,237 (4b0) :  INFO (logkit:16) - [ ] role:        PlayStation Access
2021-02-05 19:32:11,237 (4b0) :  INFO (logkit:16) - [ ] art:       
2021-02-05 19:32:11,237 (4b0) :  INFO (logkit:16) - [ ] banners:   
2021-02-05 19:32:11,239 (4b0) :  INFO (logkit:16) - [ ] posters:   https://yt3.ggpht.com/ytc/AAUvwnjItXDY0YgBYg75RPGxkGarww_7aq0sLoq2ezguvw=s240-c-k-c0x00ffffff-no-rj
2021-02-05 19:32:11,239 (4b0) :  INFO (logkit:16) - =============================================================================================================================================================
2021-02-05 19:32:11,239 (4b0) :  INFO (logkit:16) - Season: 2021
2021-02-05 19:32:11,240 (4b0) :  INFO (logkit:16) - metadata.seasons[2021].episodes[102051701] "PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].mp4"
2021-02-05 19:32:11,240 (4b0) :  INFO (logkit:16) - populate_episode_metadata_from_info_json() - series_root_folder: D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg], filename: PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].mp4
2021-02-05 19:32:11,240 (4b0) :  INFO (logkit:16) - Searching for "PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].info.json". Searching in "D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]".
2021-02-05 19:32:11,436 (4b0) :  INFO (logkit:16) - Directory \\?\D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg] contains 1247 files
2021-02-05 19:32:11,437 (4b0) :  INFO (logkit:16) - Found 0 matches.
2021-02-05 19:32:11,437 (4b0) :  INFO (logkit:16) - populate_episode_metadata_from_api() - filename: PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console  [2jOX4IUYqTU].mp4
2021-02-05 19:32:11,437 (4b0) :  INFO (logkit:16) - # videoId [2jOX4IUYqTU] not in Playlist/channel item list so loading video_details
2021-02-05 19:32:11,477 (4b0) :  DEBUG (networking:138) - Fetching 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=2jOX4IUYqTU&key=[snipped]' from the HTTP cache
2021-02-05 19:32:11,536 (4b0) :  DEBUG (networking:143) - Requesting 'https://i.ytimg.com/vi/2jOX4IUYqTU/sddefault.jpg'
2021-02-05 19:32:11,641 (4b0) :  DEBUG (networking:175) - Not caching 'https://i.ytimg.com/vi/2jOX4IUYqTU/sddefault.jpg' (content type 'image/jpeg' not cacheable in Agent plug-ins)
2021-02-05 19:32:11,642 (4b0) :  INFO (logkit:16) - [ ] title:    "7 Things Gamers Only Do When They Have A New Console"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] summary:  "Rob has been the proud owner of a PS5 since November and has noticed some weird gaming habits that only happen during that magical, new console honeymoon period. Are you guilty of any of these? Let us know in the comments!. . PlayStation Access brings you the latest PlayStation news, features and gameplay every week, giving you unprecedented access to the biggest titles on PlayStation. Subscribe now to ensure you never miss out: http://bit.ly/AccessSub. . All music featured courtesy of epidemicsound.com (http://www.epidemicsound.com). . We use AverMedia's live Gamer Pro for PS4 capture and streaming. . . Want more?. Ash's Twitter: http://twitter.com/ashmillman. Rosie's Twitter: https://twitter.com/RosieCaddick88. Rob's Twitter:    http://bit.ly/RobPearson. Dave's Twitter:  http://bit.ly/DavidJackson. Nath's Twitter:  http://bit.ly/NathanDitum. . Join us on Facebook: http://bit.ly/AccessFB. Follow us on Twitter: http://bit.ly/TweetAccess. . #Robservations #7Things #PS5"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] date:     "2021-02-05T17:00:04Z"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] rating:   "9.87065481002"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] thumbs:   "https://i.ytimg.com/vi/2jOX4IUYqTU/sddefault.jpg"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] duration: "PT10M59S"->"659000"
2021-02-05 19:32:11,644 (4b0) :  INFO (logkit:16) - [ ] director: "PlayStation Access"
2021-02-05 19:32:11,645 (4b0) :  INFO (logkit:16) - [ ] posters: https://i.ytimg.com/vi/2jOX4IUYqTU/sddefault.jpg
2021-02-05 19:32:11,645 (4b0) :  INFO (logkit:16) - [ ] genres:   "[u'Gaming', u'PlayStation 5', u'Console', u'Friday Feature', u'PSA', u'List', u'Habits', u'PlayStation Access', u'New', u'PS5']"
2021-02-05 19:32:11,645 (4b0) :  INFO (logkit:16) - =============================================================================================================================================================
2021-02-05 19:32:11,657 (4b0) :  DEBUG (model:229) - Serializing to C:\Users\Administrator\AppData\Local\Plex Media Server\Metadata\TV Shows\f\3f527ab031001fbf0fddbc0c7cee2fcc3174ba2.bundle\Contents\com.plexapp.agents.youtube\Info.xml
2021-02-05 19:32:11,660 (4b0) :  DEBUG (runtime:88) - Sending packed state data (107 bytes)
2021-02-05 19:32:11,660 (4b0) :  DEBUG (runtime:924) - Response: [200] str, 16 bytes

If I reresh metadata at the show level then I get...

2021-02-05 19:35:51,707 (1b30) :  CRITICAL (core:574) - Exception in the update function of agent named 'YouTubeSeries', called with guid 'com.plexapp.agents.youtube://youtube|UC6yzV_xgKn8r77FkcmZyMSg|PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]?lang=xn' (most recent call last):
  File "C:\InstalledPrograms\PlexMediaServer\Resources\Plug-ins-cb530f3ab\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\agentkit.py", line 1093, in _update
    agent.update(obj, media, lang, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\YouTube-Agent.bundle\Contents\Code\__init__.py", line 678, in update
    def update (self, metadata, media, lang, force ):  Update (metadata, media, lang, force,  False)
  File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\YouTube-Agent.bundle\Contents\Code\__init__.py", line 670, in Update
    populate_episode_metadata_from_api(filename, episode, metadata, first, episodes, genre_array)
  File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\YouTube-Agent.bundle\Contents\Code\__init__.py", line 299, in populate_episode_metadata_from_api
    episode.duration                = ISO8601DurationToSeconds(video_details['contentDetails']['duration'])*1000;               Log.Info('[ ] duration: "{}"->"{}"'.format(video_details['contentDetails']['duration'], episode.duration))
  File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\YouTube-Agent.bundle\Contents\Code\__init__.py", line 52, in ISO8601DurationToSeconds
    match = re.match('PT(\d+H)?(\d+M)?(\d+S)?', duration).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

I first noticed this behavior on 2021-02-02 1700 UTC

ZeroQI commented 3 years ago

It means video_details['contentDetails']['duration'] is equal to None...

Change line 299 to: episode.duration = ISO8601DurationToSeconds(video_details['contentDetails']['duration'] or "PT0M0S")*1000; Log.Info('[ ] duration: "{}"->"{}"'.format(video_details['contentDetails']['duration'], episode.duration))

If works will put in master code

harroguk commented 3 years ago

Line Changed Restarted Plex Server (I dont know any other way to reload a plugin)

Ran "refresh Metadata" on the episode Ran "refresh Metadata" on the show

Metadata is still not updated for the episode. Error still appears in the log. I have attached a full log here

If you want to see if you have problems matching a file locally then a file with the issue is named and in the path below. Or if someone else wants to see if they have a problem too then the link is https://www.youtube.com/watch?v=2jOX4IUYqTU

D:\TV\YouTube\PlayStation Access [UC6yzV_xgKn8r77FkcmZyMSg]\PlayStation Access - s2021e102051701 - 7 Things Gamers Only Do When They Have A New Console [2jOX4IUYqTU].mp4

com.plexapp.agents.youtube.log

ZeroQI commented 3 years ago

iBad code, my bad... Change line 49 the function:

### Convert ISO8601 Duration format into seconds ###
def ISO8601DurationToSeconds(duration):
  def js_int(value):  return int(''.join([x for x in list(value or '0') if x.isdigit()]))  # js-like parseInt - https://gist.github.com/douglasmiranda/2174255
  try:     match = re.match('PT(\d+H)?(\d+M)?(\d+S)?', duration).groups()
  except:  return 0
  else:    return 3600 * js_int(match[0]) + 60 * js_int(match[1]) + js_int(match[2])
harroguk commented 3 years ago

No problem, won't be able to check anything until tomorrow now, pesky children :) will let you know how it goes.

harroguk commented 3 years ago

Turns out I lied. I made the change sat on the bathroom floor on my mobile phone whilst potty training my youngest.

It works, just needs pushing to master.

As always thanks for the help, I will fire you some money when I find your PayPal on the Plex website again.

ZeroQI commented 3 years ago

Well did it on the phone too to be honest... Donation link at the bottom of the readme.