blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.71k stars 304 forks source link

"no attribute year" in sort_by_dates when trying to create playlist #184

Closed minorsecond closed 5 years ago

minorsecond commented 5 years ago

Getting the following error when trying to create an "aired today" playlist. This is with the latest edit to playlist_manager.py. I've gone through and made sure that I haven't forgotten anything a few times and got the same result each time.

python playlist_manager.py --jbop historyToday --libraries Movies --action add

'NoneType' object has no attribute 'year' Traceback (most recent call last): File "playlist_manager.py", line 282, in sort_by_dates ad_year = video.originallyAvailableAt.year AttributeError: 'NoneType' object has no attribute 'year'

blacktwin commented 5 years ago

Do you have any recently deleted Movies that have not been clean out? Trying Cleaning Trashcan. That or the Movie doesn't have that metadata field. You should have a log file now, can you share that?

minorsecond commented 5 years ago

Here's the log contents. Interestingly, it's also not picking up "TV Shows" at all.

I'll try cleaning the trash.

2019-09-05 07:56:47,526:playlist_manager:build_playlist:Libraries are not defined for historyToday. Use --libraries.
Traceback (most recent call last):
  File "playlist_manager.py", line 513, in build_playlist
    keys_list = get_content(libraries, jbop, filters, search, limit)
  File "playlist_manager.py", line 463, in get_content
    child_lst += item_date
TypeError: 'NoneType' object is not iterable
2019-09-05 07:57:30,933:playlist_manager:build_playlist:Libraries are not defined for historyToday. Use --libraries.
Traceback (most recent call last):
  File "playlist_manager.py", line 513, in build_playlist
    keys_list = get_content(libraries, jbop, filters, search, limit)
  File "playlist_manager.py", line 463, in get_content
    child_lst += item_date
TypeError: 'NoneType' object is not iterable
2019-09-05 07:58:09,952:playlist_manager:sort_by_dates:'NoneType' object has no attribute 'year'
Traceback (most recent call last):
  File "playlist_manager.py", line 282, in sort_by_dates
    ad_year = video.originallyAvailableAt.year
AttributeError: 'NoneType' object has no attribute 'year'
2019-09-05 08:01:47,730:playlist_manager:build_playlist:Libraries are not defined for historyToday. Use --libraries.
Traceback (most recent call last):
  File "playlist_manager.py", line 513, in build_playlist
    keys_list = get_content(libraries, jbop, filters, search, limit)
  File "playlist_manager.py", line 463, in get_content
    child_lst += item_date
TypeError: 'NoneType' object is not iterable
2019-09-05 08:01:57,780:playlist_manager:build_playlist:Libraries are not defined for historyToday. Use --libraries.
Traceback (most recent call last):
  File "playlist_manager.py", line 513, in build_playlist
    keys_list = get_content(libraries, jbop, filters, search, limit)
  File "playlist_manager.py", line 463, in get_content
    child_lst += item_date
TypeError: 'NoneType' object is not iterable
2019-09-05 08:02:50,932:playlist_manager:build_playlist:Libraries are not defined for historyToday. Use --libraries.
Traceback (most recent call last):
  File "playlist_manager.py", line 513, in build_playlist
    keys_list = get_content(libraries, jbop, filters, search, limit)
  File "playlist_manager.py", line 463, in get_content
    child_lst += item_date
TypeError: 'NoneType' object is not iterable
2019-09-05 08:03:10,788:playlist_manager:sort_by_dates:'NoneType' object has no attribute 'year'
Traceback (most recent call last):
  File "playlist_manager.py", line 282, in sort_by_dates
    ad_year = video.originallyAvailableAt.year
AttributeError: 'NoneType' object has no attribute 'year'
2019-09-05 08:08:32,969:playlist_manager:sort_by_dates:'NoneType' object has no attribute 'year'
Traceback (most recent call last):
  File "playlist_manager.py", line 282, in sort_by_dates
    ad_year = video.originallyAvailableAt.year
AttributeError: 'NoneType' object has no attribute 'year'
minorsecond commented 5 years ago

Cleaning trash didn't work.

blacktwin commented 5 years ago

What are you using for your media agents for Plex?

minorsecond commented 5 years ago

For both plex movie and the movie database, I have

blacktwin commented 5 years ago

Check a Movie's XML for addedAt? You may need to refresh metadata if it's not there.

Also, what agent are you using for your Movies library? image

minorsecond commented 5 years ago

Refreshing metadata didn't help. I checked a few movies and the addedAt value was present.

I'm using Plex Movie.

blacktwin commented 5 years ago

Edit the following to:

    except Exception as e:
        logger.error(vars(video))
        logger.exception(e)
        # exit()

This will output the video object attributes as well as attempt to continue processing after an error is found.

minorsecond commented 5 years ago

Good idea. Here's what I got:

{'librarySectionID': '20', 'art': '/library/metadata/60146/art/1564177670', 'rating': None, 'addedAt': datetime.datetime(2019, 7, 26, 16, 31, 36), 'year': 2017, 'ratingKey': 60146, 'chapters': [], 'session': [], 'userRating': None, 'updatedAt': datetime.datetime(2019, 7, 26, 16, 47, 50), 'duration': 5797166, 'guid': 'com.plexapp.agents.imdb://tt5710514?lang=en', 'usernames': [], 'lastViewedAt': datetime.datetime(2019, 7, 29, 12, 43, 1), 'thumb': '/library/metadata/60146/thumb/1564177670', 'title': "I Don't Feel at Home in This World Anymore", 'tagline': None, 'contentRating': None, 'audienceRatingImage': None, 'sessionKey': None, 'collections': [], 'listType': 'video', '_server': <PlexServer:http://192.168.3.26:>, 'type': 'movie', 'transcodeSessions': [], 'ratingImage': None, 'playlistItemID': None, 'audienceRating': None, 'genres': [], 'originalTitle': None, 'producers': [], '_details_key': '/library/metadata/60146?checkFiles=1&includeExtras=1&includeRelated=1&includeOnDeck=1&includeChapters=1&includePopularLeaves=1&includeConcerts=1&includePreferences=1', 'studio': None, 'key': '/library/metadata/60146', 'originallyAvailableAt': None, '_data': <Element 'Video' at 0x7f9d12343510>, 'titleSort': "I Don't Feel at Home in This World Anymore", '_initpath': '/library/metadata/60146?checkFiles=1&includeExtras=1&includeRelated=1&includeOnDeck=1&includeChapters=1&includePopularLeaves=1&includeConcerts=1&includePreferences=1', 'viewOffset': 542000, 'viewCount': 0, 'roles': [], 'countries': [], 'fields': [<Field:thumb>, <Field:art>], 'viewedAt': None, 'summary': '', 'labels': [], 'players': [], 'directors': [], 'chapterSource': None, 'media': [<Media:110913>], 'writers': [], 'similar': [], 'primaryExtraKey': None}

and then

'NoneType' object has no attribute 'year'
Traceback (most recent call last):
  File "playlist_manager.py", line 282, in sort_by_dates
    ad_year = video.originallyAvailableAt.year
AttributeError: 'NoneType' object has no attribute 'year'

the originallyAvalableAt value is None. I checked the xml in Plex for that movie and the values are all there too.

blacktwin commented 5 years ago

Sorry originallyAvalableAt is what we're looking for, I misspoke before.

Edit these lines to:

    try:
        if video.isPartialObject():
            video = plex.fetchItem(video.ratingKey)
        ad_year = video.originallyAvailableAt.year

This will check if the video object is a Partial or Full object. It might be that for some reason the items that are failing don't have that originallyAvalableAt due to being a Partial object. Although it doesn't seem to matter on my end.

Also, with the previous edit, is there more than one item that was failing before? Anything special about the item that failed? Any difference with TV Shows vs Movies? I'm assuming that a Playlist was created, if you were using that command.

minorsecond commented 5 years ago

I got the same result after making that edit, unfortunately.

I'm getting that with more than one movie. It won't work with TV Shows for some reason, not even recognizing the option ("Libraries are not defined..").

No playlist is being created.

minorsecond commented 5 years ago

I should add that I updated Plex recently. Do you think it's possible that they made a change that's breaking something?

blacktwin commented 5 years ago

Show me your command string for TV Shows. Update shouldn't matter. Mine is set to auto update and I'm not seeing an issue.

minorsecond commented 5 years ago

python playlist_manager.py --jbop historyToday --libraries "TV Shows" --action add

By the way, thanks for taking the time to help me through this. It's greatly appreciated.

minorsecond commented 5 years ago

originallyAvailableAt isn't present in the Plex XML. I don't know what I thought I saw earlier, but it's not there.

Issue was fixed by rerunning the metadata. I guess it was stopped prematurely somehow the first time.

blacktwin commented 5 years ago

So can I close this issue? It's resolved?

minorsecond commented 5 years ago

I'm still trying to figure out why TV Shows isn't working, but that's a different issue. So I think so.

blacktwin commented 5 years ago

Fix incoming.

blacktwin commented 5 years ago

@minorsecond Please download the latest version and try again with TV shows.

minorsecond commented 5 years ago

Looks like that fixed it. Thank you!