I was just in the middle of trying to tag some of my media so they would look proper in iTunes…and on a whim I thought to check to see what the Plex forums had to offer…As usual, found just what I was looking for.
So, I just wanted to say thanks for the fantastic work. I was up and running in minutes and it works great.
I feel that the command line does the trick and completely understand the benefits when working cross platform. Needless to say, I think it is great as is. However, a full mac app would be able to benefit those less open to playing in the command line (no matter how simple this is). Either way, I’m looking forward to sharing this with some friends who are fellow Plex users…even if I have to run the commands myself.
Thanks again.
thanks for the feedback 
If I feel bored further down the line, I will look into creating a full mac app. Glad to hear the script worked well for you!
Item # to select <br /> processing 1/202 movies : 9/11 (2002)<br /> File untagged<br /> tagging...<br /> Downloading artwork...<br /> Traceback (most recent call last):<br /> File "./plexmediatagger.py", line 156, in <module><br /> sys.exit(main())<br /> File "./plexmediatagger.py", line 138, in main<br /> section_processor.process_section(section_to_process)<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py", line 28, in process_section<br /> self.process_movie_section(section)<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py", line 109, in process_movie_section<br /> self.process_file(movie)<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py", line 161, in process_file<br /> self.tag_file(media_item)<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py", line 240, in tag_file<br /> tag_cmd.append(media_item.tag_string()) #also downloads the artwork<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/MovieMetadataParser.py", line 66, in tag_string<br /> self.get_local_image_path()<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/MovieMetadataParser.py", line 58, in get_local_image_path<br /> self.local_image_path = request_handler.download_image(self.name(), partial_image_url)<br /> File "/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/PmsRequestHandler.py", line 73, in download_image<br /> with open(image_path, "wb") as local_file:<br /> IOError: [Errno 2] No such file or directory: '/var/folders/s_/tc1vbj0n1615725d1xhhmt5c0000gp/T/9/11 (2002).jpg'<br /> MB-Max:ccjensen-PlexMediaTagger-ce1c51b max
hi relax,
so I see the name of your movie that is causing trouble is “9/11 (2002).”. Are you trying to run the script on something that is not os x, because these are the rules for os x file names:
*source: http://www.comentum.com/File-Systems-HFS-FAT-UFS.html*
So the issue is that the forward slash in the file name should not be a "legal" character, and is being interpreted as a file called "11 (2002).". I could look for this and create a workaround, but I don't really understand how you could be allowed to name this file with one of the "restricted" characters :)
Hi, I’m running it on a Lion MacBook.
See a screenshot of the file in the finder
files.me.com/mmanfrin/h91i8v
Anyway, I just removed it for the sake of giving a try and I still have errors:
processing 24/201 movies : Christine (1983)
File untagged
tagging…
Downloading artwork…
Traceback (most recent call last):
File “./plexmediatagger.py”, line 156, in
sys.exit(main())
File “./plexmediatagger.py”, line 138, in main
section_processor.process_section(section_to_process)
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py”, line 28, in process_section
self.process_movie_section(section)
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py”, line 109, in process_movie_section
self.process_file(movie)
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py”, line 161, in process_file
self.tag_file(media_item)
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/SectionProcessor.py”, line 240, in tag_file
tag_cmd.append(media_item.tag_string()) #also downloads the artwork
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/MovieMetadataParser.py”, line 69, in tag_string
hd_value = “%d” % (1 if self.is_HD() else 0)
File “/Users/max/Downloads/ccjensen-PlexMediaTagger-ce1c51b/MediaItemMetadataParser.py”, line 57, in is_HD
resolution = mediaNode.attrib[‘videoResolution’]
File “lxml.etree.pyx”, line 2184, in lxml.etree._Attrib.getitem (src/lxml/lxml.etree.c:47381)
KeyError: ‘videoResolution’
MB-Max:ccjensen-PlexMediaTagger-ce1c51b max$
Once I removed that movie as well, everything went fine and all the remainings were tagged.
hmmm, it's crashing because the pas has no videoResolution for that item, which I assumed would never be true… it would be interesting if you could re-add that item (causing a full re-analyze of the media item) and see if that fixes it? I can add in more error checking, but I think it should be a safe assumption that all video item's should have some resolution :)
Hello ccjensen,
I havent had time to experiment with your app so this might be stupid question, but is this tool able to UPDATE metadata tags?
It seems that routinely obscure shows do not have metadata when i add them to PLex but in couple of days it seems plex is able to download additional metadata that are entered in thetvdb database so it’d be cool when i run my cron job that it would append/replace metadata as well.
Thanks
Interesting idea. Currently the only way to do so would be to tell the script to rewrite ALL the tags in all the files, which will accomplish what you are looking for albeit a bit wasteful.
A solution might be for the script to store the the “date last modified” from the PMS for each file in the comment attribute of the file, and then compare these two when batch writing the tags. Would/Does that make sense?
guess that didn’t make sense? 
People still using this? Everyone happy with it? Feature requests?
Sorry ccjensen for not answering any sooner.
Personally, I had to go back and start experimenting with iFlicks/iVI apps since they also convert files into iTunes friendly format. I would LOVE to have same metadata in iTunes as I've got in Plex but manually encoding files is just not an option. Sometimes I'm out of the house for 2-3 days and girlfriend does not get her Shows in iTunes and I'm in trouble :-)
So if you're looking for feature request, it would be to take avi/mkv file, convert it to mp4 file, embed Plex metadata and then update metadata when needed as you described in your previous post.
Talk about quick fix :-)
I am having problems getting lxml installed on 10.5.8. There are a lot of build errors.
It starts with libxml/schematron.h not found (no such file or directory) and the rest (I guess) are then follow up errors on that.
What am I missing?
Thanks and Cheers,
alex
I don't have a leopard machine to test on, but there are a bunch of alternative ways here:
http://stackoverflow.com/questions/1277124/how-do-you-install-lxml-on-os-x-leopard-without-using-macports-or-fink
yea, that's not going to happen :)
That said, this tool would fit perfectly into a script that would automate that for you. Something along the lines of a script watching a downloads folder for new video files, it goes through a "should I transcode this step" before it's placed into the plex folder hierarchy, plex scans and downloads the metadata and upon completion of that my script runs to embed the data and finally your script would add any new files to iTunes :)
I used to have a script that did pretty much this exact job just without the plex metadata fetcher as there wasn't a good tool to do that job back then.
Well what you described is good and I could get around scripting it ( if I call in sick for next 2 weeks :-) ) & feasible but I do not want mp4's in my Plex library. I want my originals in Plex and mp4 COPIES (iPad, AppleTV2 playable format) in iTunes. As far as I understand it your script can only embed metadata to files that are in Plex' database, NOT exact same filenames (duplicates) but in mp4 format residing elsewhere.
For example my goal is to have "Married with Children - S01E01.mkv" in Plex' source directory/database and " Married with Children - S01E01.mp4" in iTunes library. Then run your script every 30 or so minutes and sync PLex' metadata database updates to iTunes' copy.
Cron job could initiate syncing and script could identify the two 'copies' by simply parsing file name. ( obviously iTunes sorting/renaming would have to be turned off for that to work )
I hope this makes sense.
yea, the “double copy of each file” scenario sounds pretty niche 
That said, it shouldn’t be too hard to modify my python script to accomplish what you require.
I am working on adding support for the ability to embed ratings and play count so that it can be loaded into iTunes (requires the help of an iTunes script to write the information to the iTunes database). Also adding the ability to detect that plex’s metadata for a movie has been updated, and therefore it should go ahead and update the embedded tags within the file.
work is completed so that rating and play count can be loaded into the iTunes database (these fields cannot be directly embedded as there isn’t a field for this kind of information). The tool will now also notice if a file that has previously been tagged now needs updating (i.e. the metadata has been changed in plex since the last time the tool processed this file).
That sounds great. I can’t wait to try the update when I get home.
Thank you for your continued efforts.
Just out of curiosity (and this might be completely out of scope or another topic)…but I was wondering if there might be a way to synchronize the watched/unwatched status of files between iTunes and Plex. A few other users have shown interested in such functionality here.
It sounds like a bit of a stretch since I assume this status isn’t tagged on the files but in the iTunes/Plex databases…but since you were able to get play count and ratings I thought I might ask. Thanks again.