Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a files metadata in Python

Ok, I've searched around here but haven't found anything pointing to a solid answer.

I'm trying to change a files artist, filename, rating, genre etc in windows, which shows up when you view folders in 'details'.

At the moment I have the files I wish to edit in a list and I am iterating through them, but as I said I am not sure how to change it for each file in the list.

def Files(The_FileList):
'''Changes each files metadata'''
for each_file in The_FileList:

    #clueless here.

return The_FileList

needs to work with .avi/.mkv general movie files as I do alot of encoding.

I'm looking for a simple option as this is all I want to do.

Thanks

like image 607
code_by_night Avatar asked Jun 21 '10 00:06

code_by_night


People also ask

Can you change the metadata of a file?

Click the File tab. Click Info to view the document properties. To add or change properties, hover your pointer over the property you want to update and enter the information. Note that for some metadata, such as Author, you'll have to right-click on the property and choose Remove or Edit.

How do I add metadata to a file in Python?

You can make use of extended file attributes which is a filesystem feature that do just what you want: store custom metadata along files. In Python, this is implemented by the os module through setxattr() and getxattr() functions.


1 Answers

In many cases (and in this case), metadata is file-type specific. (Some filesystems offer their own metadata, as NTFS and later do, but this particular metadata is coming from the file itself, and not from the filesystem).

To modify the metadata in the files in question, you probably can use the Mutagen library (assuming these are mp3/aac/flac/vorbis/etc. - there are probably other audio formats that have a different metadata format).

like image 61
Nick Bastin Avatar answered Oct 21 '22 11:10

Nick Bastin