简体   繁体   English

在Python中更改文件元数据

[英]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'. 我正在尝试更改Windows中的文件艺术家,文件名,评级,流派等,当您在“详细信息”中查看文件夹时会显示这些文件。

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. 需要使用.avi / .mkv一般电影文件,因为我做了很多编码。

I'm looking for a simple option as this is all I want to do. 我正在寻找一个简单的选项,因为这就是我想要做的。

Thanks 谢谢

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). (有些文件系统提供了自己的元数据,如NTFS和后来的那样,但这个特定的元数据来自文件本身,而不是来自文件系统)。

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). 要修改相关文件中的元数据,您可能可以使用Mutagen库 (假设这些是mp3 / aac / flac / vorbis /等等 - 可能还有其他具有不同元数据格式的音频格式)。

Mutagen is actualized. 诱变剂已实现。

I leave an example for change 3 atributes of all the files in the directory: 我留下了一个示例,用于更改目录中所有文件的3个属性:

import mutagen
from mutagen.mp4 import MP4
from os import scandir

ruta = './'
l_archivos = sorted([archivo.name for archivo in scandir(ruta) if archivo.is_file()])

mutagen.File(l_archivos[1])      # U: See the tags of the data

def edit_Media_Data():

    for f in range(len(l_archivos[:-1])):                 # A: A range of all the fields exept the script
        file = MP4(l_archivos[f])                         # A: Capture the file to edit
        file['©nam'] = l_archivos[f].replace('.mp4','')   # U: Take the file name and makeit the tittle
        file['©ART'] = 'Hector_Costa_Guzman'              # U: Edit the Autor
        file['©alb'] = 'Curso_Django'                     # U: Edit the Album
        file.pprint()
        file.save()  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM