enzyme
enzyme copied to clipboard
Attachments, Tags to and from xml, Bracket-access for tags, Recursive SimpleTags
Restarting from my old pull requests, here are all my changes in one request.
- Attachments
MKV has now as "attachments" list of Attachment object with all the Mastroka elements: Name, Description, Mime Type and Data. Data is a BytesIO object with the raw binary data of the attachment. A keyword argument in MKV.init "load_attachments" can turn off the rawData reading, saving some memory space.
- Recursive SimpleTags
Like in the Mastroka docs, SimpleTags can contain children SimpleTags.
- Tags to and from xml
Convenience functions using xml.etree.ElementTree Elements
-
mkv.tags_from_xml(xmlElement)
: Load Tag data from a xml Element and append it to the mkv.tags. -
xmlElement = mkv.tags_to_xml()
: Write a xml element from the Tags in a mkv.
This is useful for saving changed tag data with mkvpropedit. Also, it could be used (as I do) to create a MKV-like object from another type of file (not mkv).
- Bracket-accsess for tags
Convenience getitem. MKV object can be bracket-accessed with a targettype (or targettypevalue) and this returns a list of all tags corresponding to this targettype. The sames apply for tags which return a list of simpletags corresponding to the requested name. They both return lists because you could have multiple SimpleTags with the same Name.
Ex.
Return the first tag with a targettypevalue of 50: mkv[50][0]
Return this tag's first simpletag with name 'TITLE': mkv[50][0]['TITLE'][0]
- Tag addition and nesting
To easily add SimpleTags to a Tag, you can now use the division operator.
Ex. Adding a SimpleTag ACTOR with string "John Smith" and sub-simpletag CHARACTER with string "Foo Bar" to the first tag with targettypevalue of 50.
mkv[50][0] / SimpleTag('ACTOR', string='John Smith') / SimpleTag('CHARACTER', string='Foo Bar')
This formalism is, I think, useful when using enzyme interactively.
It seems that the getsizeof() I was doing in some tests about the attachments was not returning the same value as on my machine. It depends on the filesystem I guess. So, instead, I take the integer division by 1000 and compare this approximate value.
I'm not sure about the bracket access for tags, I find it confusing. mkv[50] isn't something very explicit. However something like mkv.tags[50] looks better.
Same for the div thing, not very intuitive. I can't think of another python object that uses the div operator that way. List extends uses the +
operator and it doesn't support nesting. Even BeautifulSoup I think doesn't go that far in tag/xml nesting operations.
For the div functionality, I was thinking of the pathlib.Path
object which use something similar. Perhaps, your are right and it is not intuitive. I'll remove it on next commit.
For the bracket access, I also agree, but I wanted it to be simple as a getItem. I have an idea I'll suggest in next commit.
There. Removed the div's and simply renamed the __getitem__
by a getTag()
function. Everything else is the same. I find it a bit less coherent than the bracket access but, at the same time, more explicit, as you said. mkv.tags[50]
would have been the best, but mkv.tags
is already a list and I couldn't think of a simple workaround.
Can you remove the last commit and submit a new PR for that change? Also you need to update the unittests accordingly as travis fails.
Woups. Forgot about the unittests this time... Sorry. But another pull request it will be.