Tool to embed PMS held metadata in to mp4 file

hmmm, guess I must have changed that at some point. I am gone for the weekend, but remind me if you don’t hear anything by next weekend. Odds are I might make it user configurable (by passing in a flag).

I dont know if this already has been discussed, but exporting subtitles to folders is working like a charm on my Ubuntu HTPC.



Thanks for letting me know. Nice thing about the "assets" exporting is that it's just pure python, no compiled tool needed, so it should be pretty cross platform. I am still trying to figure out the best way to export tv-show/season/episode artwork. I will probably end up exporting the assets to the same folder that the files reside in.



That is correct. It is a dual core atom 1.8ghz and it was one of the main selling points for me. I believe the + models of synology began to carry intel chips in 2010.

I am confused are you suggesting that I should be able to run this application? I googled SublerCLI and it seems to be mac only which I cant help but take issue with.. why would they make a CMD application that is not *nix cross platform anyway? http://code.google.com/p/subler/downloads/detail?name=SublerCLI-0.15b.zip&can=2&q= and theres no plans to make this cross platform http://code.google.com/p/subler/issues/detail?id=116

I won't try to get guess why it's mac only, but what I was suggesting is that if you can find a different tool (one that _does_ work your system) that has the ability to embed metadata into m4v/mp4 files, then I could include that with the script and dynamically switch between the tools depending on what system my tool is running on.


Hey, just wanted to see if you still might be able to take a look at this (episode thumbs). Thanks.

Hey,

As expected, life got busy and it got forgotten :slight_smile:

I hacked in a quick change that should get things working the way you want (added a new optional flag (–tag-tv-prefer-season-artwork). I will probably try and make the solution less “hacky” in the future, but for now it should suffice!

Let me know if I broke anything!

Hey no worries, life comes first. Hope it was the good kind of busy.



I’ll give it a go tonight and let you know if anything comes up. And, just amazing turn around time, hope this didn’t put a damper on your Sunday evening.



As always, thanks for all your work and putting up with needy people like me.

added a “–stats” flag today that spits out some interesting tidbits about the items that were processed (or if you run the tool with -b it will be for all the video items in your library).



Something along the lines of:

============ Items Processed Statistics ===========

Number of items: 6654

---------------------------------------------

Number of Movies: 1358

Number of TV Episodes: 5296

---------------------------------------------

Total Duration: 6 months, 22 days, 16 hours, 33 minutes, 16 seconds

Average Duration: 44 minutes, 4 seconds

---------------------------------------------

Total TV Episodes Duration: 4 months, 18 days, 14 hours, 15 minutes, 13 seconds

Average TV Episode Duration: 37 minutes, 41 seconds

---------------------------------------------

Total Movies Duration: 2 months, 6 days, 2 hours, 18 minutes, 3 seconds

Average Movie Duration: 1 hour, 9 minutes, 1 second


Sorry it has taken me so long, but I want to have a look at embedding data into mkv's. Do you know of any apps that display the data that's embedded, so that I can double-check that the script is doing the right thing?


I have an idea.

From my research no such application exists however from what I have read the tags are just kept in an xml file inside the mkv. Mkvmerge and mkvextract are cli applications found in the MVKToolsNIX package (Its completely cross platform) and theoretically you could write a script using these apps to remux the mkv with a tag xml generated from the plex db. I assume you could do the same thing for mp4 type files with MP4box cli tools (also cross platform). I found the matroska docs that should outline how such an XML should be structured http://matroska.org/technical/specs/tagging/example-video.html

Also: http://forum.videohelp.com/threads/326119-%5BSOLVED%5D-How-to-tag-an-mkv-mka-file?p=2023503&viewfull=1#post2023503

edit: then again it may end up being less work to just communicate with the author of subler and make the app cross platform and add support for mkv.

From what I have been able to determine, mp4box does not support adding all the tags that subler does (i.e. a lot of the iTunes specific ones). The subler dev has traditionally been very mac centric, so I highly doubt he can be coerced into making it cross platform ;)
That said, I am more than happy to add support for mkv's if you can provide an example of how you would use the tools to embed the tags (like what the xml file's contents would be, and what the command line arguments would be).


ccjensen, I should tell you that I have no real need for this functionality I just think your script is a cool feature and I am trying to throw out ideas to make it better since its such a good idea. I would like to see this kind of functionality built into plex eventually so it can auto tag your files for you. Anyway, I guess what I want to say is I want to help you/this in whatever way I can but I dont really know python or python scripting.

I did go ahead and look at the tools in mkvtoolsnix and the two that i believe look most helpful to your script are mkvinfo and mkvpropedit. Here is the man page for all the cmd line switches to use these in a script.

[Mkvinfo -- Print information about elements in Matroska(tm) files](http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvinfo.html)
[Mkvpropedit -- Modify properties of existing Matroska(tm) files without a complete remux](http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvpropedit.html)

I could try to write a quick script to take advantage of these but again I dont know python and I doubt you want batch or vb... Tell me what else you need or if I can help?


Hi ccjensen, thanks again for a great tool. I have for various reasons switched from Ubuntu to Windows 7 on my HTPC, and I once again was about to use this plugin to extract some subtitle files. However, after installing Python 2.7 and your latest version of plexmediatagger, I run into some problems.

I am running the command: 'python plexmediatagger.py --subtitles' on the same machine as PMS is currently running on. I then get the following error messages:


F:\ccjensen-PlexMediaTagger-298cb12>C:\Python27\python.exe plexmediatagger.py --<br />
subtitles<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 118<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 130<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 138<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 140<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 140<br />
Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 145<br />
Section to process $Traceback (most recent call last):<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 51<br />
, in emit<br />
    self.output_colorized(message)<br />
  File "F:\ccjensen-PlexMediaTagger-298cb12\ColorizingStreamHandler.py", line 86<br />
, in output_colorized<br />
    h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)<br />
NameError: global name 'ctypes' is not defined<br />
Logged from file plexmediatagger.py, line 201



Did I miss something? I could not find anything in the documentation saying I need any extra libraries or such for Python..

Looking forward for your reply :)

Update:

Now I see that if i click enter (instead of ctrl+c and abort), it actually asks me for user input. It simply does not show me the correct output asking which series and seasons to check. If i click enter on all input steps (wildcard, export from every video) it just spams similar error messages. All are related to "ctypes not defined".

Yea, I haven’t figured out how to do colored output in a windows terminal, so I (thought) I had put in a fallback where it would just not colorize the text. Obviously not working :slight_smile:



Anyway, do me a favor:

  1. Open the windows terminal
  2. start a python interactive shell by typing in “python”
  3. type “import OS”
  4. type “os.name”
  5. let me know what value gets printed out to the console.



    So this is what it looked like when I did it on my mac:

<br />
$ python<br />
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) <br />
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin<br />
Type "help", "copyright", "credits" or "license" for more information.<br />
>>> import os<br />
>>> os.name<br />
'posix'<br />
>>> exit()<br />
$ <br />




ipx,

Currently this script requires Mac OS to run as it uses [subler](http://code.google.com/p/subler/)

I believe ipx is trying to use the subtitle exporting, which should work as it doesn't rely on a compiled tool (it's pure python):)


Hi, thanks for the quick reply :)

Using the commands above, my Windows 7 install responded with 'nt'.

Update: Looking at your code, in ColorizingStreamHandler.py, there was a section "if os.name != 'nt':". When I simply switched != for ==, the script now works but with some small errors in the text output. Im referring to "33m" and such - i guess that is the color coding? See sample below:


<br />
F:\ccjensen-PlexMediaTagger-298cb12>C:\Python27\python.exe plexmediatagger.py --<br />
subtitles<br />
?[33m============ Plex Media Tagger Started ============?[0m<br />
?[33mConnecting to PMS at localhost:32400?[0m<br />
List of sections for Plex Library<br />
0. Movies<br />
1. TV<br />
?[32mempty input equals all?[0m<br />
Section to process $1<br />
?[33mProcessing sections...?[0m<br />
?[33mProcessing section 1/1 : 'TV'...?[0m<br />
   Type part of the item(s) name or leave empty for full list TV's content<br />
Item name $<br />




All good, I seem to be able to export my subtitles and still read the output now. :)

I have added a “hack” in the code so that if it is an “nt” system and ctypes is not available, then it removes all the color commands from the text and prints it out plain.

I also tried installing ctypes into my python 2.7.2 installation on a windows 7 machine from here:

http://python.net/crew/theller/ctypes/



made the output all pretty and colorful again :slight_smile:

Hi, thanks for this. Have been looking for a tool that will sync up metadata from Plex into my MP4 collection.



I am having a few problems though, when running the plexmediatagger.py -t command. Effectively I am able to successfully navigate through the sections and list all my movies however if I then select a specific movie or all movies, the following results each and every time.



Item # to select $<br />
========== Terminating Plex Media Tagger ==========



Any ideas? Is there anyway to enable any debugging for the tool?

I am running the tool under OS X 10.7.2 on the same system as my PMS 0.9.5.2 server.