Mutagen ID3 Python Library

Mutagen is a Python module to handle audio metadata.

UFID: Unique File Identifier

The unique file identifier is a reference to an external database that may contain more information about the work tagged with it. Like many ID3 tags, it can have multiple values. For example, you can link the song "Black Sabbath" by "Black Sabbath" as mt0030286828 in AllMusic, and as 153a3596-af03-36ed-976a-83fec8745732 in MusicBrainz.

Note that according to the definition of the UFID ID3 frame, the URLs should not be queries themselves. I guess that it might be a feature of the software that reads this tag to transform it to direct links. In the example used, those links would be: http://www.allmusic.com/song/black-sabbath-mt0030286828 and https://musicbrainz.org/work/153a3596-af03-36ed-976a-83fec8745732.

Let's see how to write UFID and read it back in Python, with Mutagen.

{% highlight python %}

from mutagen import id3 song = id3.ID3('test.mp3')

Note that there is no UFID tag in the beginning:

song.keys() dict_keys(['TPE1', 'TALB', 'APIC:', 'TDRC', 'TRCK', 'TPE2', 'TPOS', 'TIT2'])

Let's add two references:

amurl = 'http://www.allmusic.com/' amref = 'mt0030286828' mburl = 'https://musicbrainz.org/' mbref = '153a3596-af03-36ed-976a-83fec8745732' song.add(id3.UFID(owner=amurl, data=amref.encode())) song.add(id3.UFID(owner=mburl, data=mbref.encode()))

There are now two UFIDs:

song.keys() dict_keys(['UFID:https://musicbrainz.org/', 'TRCK', 'TPE1', 'UFID:http://www.allmusic.com/', 'TPE2', 'TALB', 'TIT2', 'APIC:', 'TPOS', 'TDRC'])

Read them back:

song['UFID:https://musicbrainz.org/'] UFID(owner='https://musicbrainz.org/', data=b'153a3596-af03-36ed-976a-83fec8745732') song['UFID:https://musicbrainz.org/'].owner 'https://musicbrainz.org/' song['UFID:https://musicbrainz.org/'].data b'153a3596-af03-36ed-976a-83fec8745732' song['UFID:https://musicbrainz.org/'].data.decode() '153a3596-af03-36ed-976a-83fec8745732' {% endhighlight %}

Note the use of encode() and decode() methods of unicode used for the data part of the frame, as it expects its contents to be bytes.

Hexadecimal Primary Key in Django Model

The following snippet of code will make the primary key in a Django model to be a hexadecimal string of 8 characters instead of an integer.

Read More →

Regular expressions in python-markdown2 (part 2)

This article is a look into the performance of one of the regular expressions used in the python-markdown2 Python module for converting Markdown syntax to HTML. It was initially written for pure fun, and in celebration of its own pointlessness, but eventually the changes proposed here made it upstream in pull request 207.

Read More →

Regular expressions in python-markdown2 (part 1)

This article is a look into the performance of one of the regular expressions used in the python-markdown2 Python module for converting Markdown syntax to HTML. It was initially written for pure fun, and in celebration of its own pointlessness, but eventually the changes proposed here made it upstream in pull request 204.

Read More →

web.py Deployment on Ubuntu 14.04

These instructions are a note to myself, on how to get web.py deployed on a new VM with Ubuntu 14.04, for development:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install --yes openssh-server 
sudo reboot

After the reboot:

sudo apt-get install --yes apache2 libapache2-mod-wsgi
sudo apt-get install --yes git
sudo mkdir /opt/web.py
sudo chown `whoami`:`whoami` /opt/web.py
cd /opt/web.py
git clone git://github.com/webpy/webpy.git
ln -s `pwd`/webpy/web .
cat <<EOF > index.py
import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()
EOF
python index.py

Notes and links from PyCon 2015

These are a couple of random links from things mentioned in talks during PyCon 2015, which took place in Dublin in October 2015. There were two tracks of talks and two tracks of workshops. One of the non-workshop tracks was almost dedicated to data processing with Python, and the other had various subjects. I followed the latter track.

PyCon 2015 was organized by Python Ireland, and took place on the 24th and 25th of October 2015.

Percona Webinar: What I Learned While Migrating MySQL On-Premises To Amazon RDS

I miss having the free time to attend Percona Webinars. They are really good.

This is a recording from a webinar presented by a Technical Account Manager at Percona, regarding experiences gained from the migration of a sizeable MySQL installation from onsite to AWS RDS. It's packed with valuable technical information, as are Percona webinars, typically.

Residual Risk

In the context of risk management, a residual risk is one that has been identified, but for any reason it cannot be dealt with.

Annual Loss Expectancy

In the context of risk management, the annual loss expectancy is an estimate of the monetary damage to the organization, from the realization of risks, over the course of one year. Calculation of ALE happens during a risk assessment.

About

Hello, I'm Marios Zindilis and this is my website. Opinions are my own. You also find me on LinkedIn and GitHub.

Unless otherwise specified, content is licensed under CC0.

Search