ZeroQI / YouTube-Agent.bundle

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

KeyError: 'likeCount' #15

Closed ghost closed 5 years ago

ghost commented 5 years ago

Like and dislike count is disabled on the video in question: https://www.youtube.com/watch?v=MYxASuEqMlY

The error below is thrown when attempting to scrape the episode; it also ceases to continue with other any other episodes on the current job.

2018-09-07 11:20:48,823 (7efc87447700) :  INFO (__init__:397) - [ ] date:     "2015-09-16T07:46:08.000Z"
2018-09-07 11:20:48,823 (7efc87447700) :  INFO (__init__:398) - [ ] rating:   "9.0"
2018-09-07 11:20:48,823 (7efc87447700) :  INFO (__init__:399) - [ ] thumbs:   "https://i.ytimg.com/vi/7RVE3WRlR0A/sddefault.jpg"
2018-09-07 11:20:48,824 (7efc87447700) :  INFO (__init__:400) - [ ] duration: "PT1H19M18S"->"None"
2018-09-07 11:20:48,824 (7efc87447700) :  INFO (__init__:405) - [ ] director: "The Royal Institution"
2018-09-07 11:20:48,825 (7efc87447700) :  INFO (__init__:413) - [ ] genres:   "[u'Biology', u'Royal Institution', u'Science', u'Science & Technology', u'Science Communication', u'chemistry', u'Physics', u'Ri', u'Education']"
2018-09-07 11:20:48,825 (7efc87447700) :  INFO (__init__:360) - metadata.seasons[2015].episodes[346] "The Royal Institution - The Race to Crack the Genetic Code with Matthew Cobb - [MYxASuEqMlY].mkv"
2018-09-07 11:20:48,826 (7efc87447700) :  INFO (__init__:383) - # videoId [MYxASuEqMlY] not in Playlist/channel item list so loading video_details
2018-09-07 11:20:48,833 (7efc87447700) :  DEBUG (networking:161) - Fetching 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=MYxASuEqMlY&key=AIzaSyC2q8yjciNdlYRNdvwbb7NEcDxBkv1Cass' from the HTTP cache
2018-09-07 11:20:48,842 (7efc87447700) :  DEBUG (networking:166) - Requesting 'https://i.ytimg.com/vi/MYxASuEqMlY/sddefault.jpg'
2018-09-07 11:20:48,869 (7efc87447700) :  DEBUG (networking:198) - Not caching 'https://i.ytimg.com/vi/MYxASuEqMlY/sddefault.jpg' (content type 'image/jpeg' not cacheable in Agent plug-ins)
2018-09-07 11:20:48,870 (7efc87447700) :  CRITICAL (agentkit:1078) - Exception in the update function of agent named 'YouTube', called with guid 'com.plexapp.agents.youtube://youtube|UCYeF244yNGuFefuFKqxIAXw|The Royal Institution [UCYeF244yNGuFefuFKqxIAXw]?lang=xn' (most recent call last):
  File "/****/***/*****/*****/plex/usr/lib/plexmediaserver/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/agentkit.py", line 1076, in _update
    agent.update(obj, media, lang, **kwargs)
  File "/****/***/*****/*****/plex/Library/Application Support/Plex Media Server/Plug-ins/YouTube-Agent.bundle/Contents/Code/__init__.py", line 425, in update
    def update (self, metadata, media, lang, force ):  Update (metadata, media, lang, force,  False)
  File "/****/***/*****/*****/plex/Library/Application Support/Plex Media Server/Plug-ins/YouTube-Agent.bundle/Contents/Code/__init__.py", line 394, in Update
    rating                          = float(10*int(video_details['statistics']['likeCount'])/(int(video_details['statistics']['dislikeCount'])+int(video_details['statistics']['likeCount'])))
  File "/****/***/*****/*****/plex/usr/lib/plexmediaserver/Resources/Plug-ins-21ab172de/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 108, in <lambda>
    _getitem_           = lambda x, y: x.__getitem__(y),
KeyError: 'likeCount'
ZeroQI commented 5 years ago

@ewan2395 Please test and report

ZeroQI commented 5 years ago

@ewan2395 no answer in 2 weeks, closing.

suggalat commented 3 years ago

Hey You are getting a key error , because there is no value of likeCount in that particular video.Few People hide their no of likes,comments .....So, at that particular video,u get a key error. this happens with view count,dilsike count toooo you can try exception handling: like below..

try:
likeCount.append(int(vid_resp['items'][j]['statistics']['likeCount'])) except KeyError as l:
likeCount.append(0)