Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plexmediatagger.py command fails : traceback - KeyError: 'size' #23

Open
nodenineinc opened this issue Oct 9, 2021 · 5 comments
Open
Assignees

Comments

@nodenineinc
Copy link

nodenineinc commented Oct 9, 2021

Just pulled the most recent zip onto a mac system running 10.12.6 (due to compatibility issues with recording hardware it must remain on this rev of OSX). I have plex media server running locally on this host and the plexmediatagger.py connects just fine it seems, but the command fails immediately once it finds the media library and starts processing.

PlexMediaTagger-master chris$ python -V
Python 2.7.10

PlexMediaTagger-master chris$ ./plexmediatagger.py -tfbvv
FORCE MODE ENABLED. THIS WILL BYPASS ANY 'HAS THIS BEEN DONE BEFORE' CHECKS
======================================================================================= Plex Media Tagger Started ========================================================================================
Connecting to PMS at localhost:32400
Get contents: http://localhost:32400/library/sections
Processing sections
Processing section 1/1 : 'Movies' ========================================================================================================================================================================
Get contents: http://localhost:32400/library/sections/1/all
Traceback (most recent call last):
File "./plexmediatagger.py", line 297, in
sys.exit(main())
File "./plexmediatagger.py", line 254, in main
section_processor.process_section(section_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 38, in process_section
self.process_movie_section_element(section_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 141, in process_movie_section_element
selected_movie_items = self.get_selection_for_media_container_element(movies_media_container_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 67, in get_selection_for_media_container_element
list_of_items = [MovieItem(self.opts, item) for item in media_container_element.getchildren()]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/MovieItem.py", line 17, in init
self.media_items = [MediaItem(self.opts, self, media_element) for media_element in self.video.findall("Media")]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/MediaItem.py", line 23, in init
self.part_items = [PartItem(self.opts, self, part_element) for part_element in self.media_element.findall("Part")]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/PartItem.py", line 24, in init
self.size = self.part_element.attrib['size']
KeyError: 'size'

@ccjensen
Copy link
Owner

Haven't used the tool in a while, but I'll take a look. Maybe something change in the json

@ccjensen ccjensen self-assigned this Oct 10, 2021
@ccjensen
Copy link
Owner

ccjensen commented Oct 10, 2021

hmmm, this does not reproduce with my set up, though I am running macOS 11.5 with Python 2.7.16.
Do you feel comfortable editing the source code to get more logs? If so, at PartItem.py at line 24 could you add:

logging.debug( "foobar part_element %s" % self.part_element.attrib )

to make it be:

        <>
        self.duration = self.part_element.get('duration', "")
        logging.debug( "foobar part_element %s" % self.part_element.attrib )
        self.size = self.part_element.attrib['size']
        <>

and then re-run ./plexmediatagger.py -tfbvv ?

@nodenineinc
Copy link
Author

nodenineinc commented Oct 11, 2021

Thank you for the follow up. I applied the logging syntax you requested. I also scaled back the media library to a single file instead of the full library of content (~700 films) and the command does actually seem to run & complete with just a single title.

If I add back in the full film library though, the routine starts crashing again.

1 Film in library output:
PlexMediaTagger-master chris$ python plexmediatagger.py -tvv
====================================================================================================== Plex Media Tagger Started =======================================================================================================
Connecting to PMS at localhost:32400
Get contents: http://localhost:32400/library/sections
List of sections for Plex Library
0. Movies
empty input equals all
Section to process $
Processing sections
Processing section 1/1 : 'Movies' ======================================================================================================================================================================================================
Get contents: http://localhost:32400/library/sections/1/all
foobar part_element {'audioProfile': 'lc', 'file': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4', 'container': 'mp4', 'has64bitOffsets': '0', 'optimizedForStreaming': '1', 'duration': '7402175', 'key': '/library/parts/12193/1598237792/file.mp4', 'videoProfile': 'high', 'id': '12193', 'size': '1983717287'}
Type part of the item(s) name or leave empty for full list Movies's content
Item name $
List of items in Movies
0. About Time (2013)
empty input equals all
Item # to select $
Get contents: http://localhost:32400/library/metadata/6651
foobar part_element {'audioProfile': 'lc', 'file': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4', 'container': 'mp4', 'has64bitOffsets': '0', 'optimizedForStreaming': '1', 'duration': '7402175', 'key': '/library/parts/12193/1598237792/file.mp4', 'videoProfile': 'high', 'id': '12193', 'size': '1983717287'}
processing 1/1 movies : About Time (2013) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
processing 1/1 media_items
processing 1/1 part_items
original path /Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4
modified path /Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4
File untagged
original path /Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4
modified path /Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4
tagging...
Downloading artwork...
saving artwork to /var/folders/0f/c2dqpcmd5wb49ws90g5lnvs80000gn/T/About Time (2013).jpg
'Tags added' arguments: ['/Users/chris/Downloads/PlexMediaTagger-master/SublerCLI', '-metadata', '{Comments:I_T_U_N_E_S::::R_69::::PC_0::::D_1633908953}{Cover Art:/var/folders/0f/c2dqpcmd5wb49ws90g5lnvs80000gn/T/About Time (2013).jpg}{Media Kind:9}{Name:About Time}{Artist:Richard Curtis}{Genre:Comedy}{Release Date:2013-09-04}{Description:What if every moment in life came with a second chance?}{Long Description:At the age of 21, Tim discovers he can travel in time and change what happens and has happened in his own life. His decision to make his world a better place by getting a girlfriend turns out not to be as easy as you might think.}{Rating:R}{Cast:Domhnall Gleeson, Rachel McAdams, Bill Nighy, Lydia Wilson, Lindsay Duncan, Richard Cordery, Joshua McGuire, Tom Hollander, Margot Robbie, Will Merrick, Vanessa Kirby, Tom Hughes, Clemmie Dugdale, Harry Hadden-Paton, Mitchell Mullen, Lisa Eichhorn, Jenny Rainsford, Natasha Powell, Catherine Steadman, Tom Stourton, Sophie Brown, Molly Seymour, Tom Godwin, Philip Voss, Matilda Sturridge, Matthew C. Martino, Lee Asquith-Coe, Haruka Abe, Lee Nicholas Harris, Richard E. Grant, Richard Griffiths}{Director:Richard Curtis}{Screenwriters:Richard Curtis}{Studio:Working Title Films}{HD Video:1}', '-source', '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4', '-destination', '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4_tmp']
'Tags added': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/About Time (2013).mp4'
Replacing old file with tagged one...
Section 'Movies' processed
Processing sections completed
===================================================================================================== Plex Media Tagger Completed ======================================================================================================
Metadata embedded: 1, Failed: 0, Total: 1
Parts processed: 1
Execution Duration: 0:02:49

Full media library processing output:
PlexMediaTagger-master chris$ python plexmediatagger.py -tvv
======================================================================================= Plex Media Tagger Started ========================================================================================
Connecting to PMS at localhost:32400
Get contents: http://localhost:32400/library/sections
List of sections for Plex Library
0. Movies
empty input equals all
Section to process $
Processing sections
Processing section 1/1 : 'Movies' ========================================================================================================================================================================
Get contents: http://localhost:32400/library/sections/1/all
foobar part_element {'audioProfile': 'lc', 'file': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/8 Mile (2002).mp4', 'container': 'mp4', 'has64bitOffsets': '0', 'optimizedForStreaming': '0', 'duration': '6623958', 'key': '/library/parts/7146/1585264797/file.mp4', 'videoProfile': 'main', 'id': '7146', 'size': '560507190'}
foobar part_element {'hasThumbnail': '1', 'audioProfile': 'lc', 'file': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/The 13th Warrior (1999).mp4', 'container': 'mp4', 'has64bitOffsets': '0', 'optimizedForStreaming': '0', 'duration': '6160572', 'key': '/library/parts/10648/1515744766/file.mp4', 'videoProfile': 'main', 'id': '10648', 'size': '1316304608'}

truncating the list of files that are read in from the plex media library

foobar part_element {'audioProfile': 'lc', 'file': '/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/Le Mans (1971).mp4', 'container': 'mp4', 'has64bitOffsets': '0', 'optimizedForStreaming': '0', 'duration': '6518436', 'key': '/library/parts/6314/1478608836/file.mp4', 'videoProfile': 'main', 'id': '6314', 'size': '638856706'}
foobar part_element {'key': '/library/parts/6285/0/file.mp4', 'id': '6285', 'file': u'/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/L\xe9on - The Professional (1994).mp4'}
Traceback (most recent call last):
File "plexmediatagger.py", line 297, in
sys.exit(main())
File "plexmediatagger.py", line 254, in main
section_processor.process_section(section_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 38, in process_section
self.process_movie_section_element(section_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 141, in process_movie_section_element
selected_movie_items = self.get_selection_for_media_container_element(movies_media_container_element)
File "/Users/chris/Downloads/PlexMediaTagger-master/SectionProcessor.py", line 67, in get_selection_for_media_container_element
list_of_items = [MovieItem(self.opts, item) for item in media_container_element.getchildren()]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/MovieItem.py", line 17, in init
self.media_items = [MediaItem(self.opts, self, media_element) for media_element in self.video.findall("Media")]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/MediaItem.py", line 23, in init
self.part_items = [PartItem(self.opts, self, part_element) for part_element in self.media_element.findall("Part")]
File "/Users/chris/Downloads/PlexMediaTagger-master/Items/PartItem.py", line 25, in init
self.size = self.part_element.attrib['size']
KeyError: 'size'

With the logging enabled, I do see that the routine is halting only partway through the list of media files and is tracebacking upon reading in a title "Léon - The Professional (1994)" (note the accent character on the 'e'). These files were all auto-named based on the data pulled in from TheMovieDB (via the FileBot renaming utility), so that's the syntax I've been respecting since it seems to be best aligned with what plex/jellyfin actually reference in their metadata lookups. Not sure if this character set is perhaps the issue of the size of the list of files.

@ccjensen
Copy link
Owner

ccjensen commented Oct 11, 2021

it's weird. it's like the result returned from the plex back end is not quite valid. So this entry looks fine:

{
  "audioProfile": "lc",
  "file": "/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/Le Mans (1971).mp4",
  "container": "mp4",
  "has64bitOffsets": "0",
  "optimizedForStreaming": "0",
  "duration": "6518436",
  "key": "/library/parts/6314/1478608836/file.mp4",
  "videoProfile": "main",
  "id": "6314",
  "size": "638856706"
}

but this one has less metadata about the item (specifically the size attribute is missing):

{
  "key": "/library/parts/6285/0/file.mp4",.
  "id": "6285",
  "file": "/Users/chris/chris1/media/movies/iTunes/iTunes Media/PLEX-PROCESSING/L\xe9on - The Professional (1994).mp4"
}

could you try moving that file aside, deleting the entry from plex, updating the library to make sure it is gone, then run the script making sure everything works, and then re-add the file and see if things start failing?
I'm hoping that by re-importing the item the missing metadata will get populated.

If that doesn't fix it, then you must be right and it's something to do with the accented letter

@nodenineinc
Copy link
Author

Sorry for the belated reply - it may take me a day or two to have a chance to circle back to this, but I will definitely try what you mention and respond as soon as I can. I really appreciate the assistance in getting to the bottom of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants