Changing a files metadata in Python

前端 未结 2 1966
别跟我提以往
别跟我提以往 2020-12-16 04:25

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,

2条回答
  •  庸人自扰
    2020-12-16 05:08

    Mutagen is actualized.

    I leave an example for change 3 atributes of all the files in the directory:

    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()  
    

提交回复
热议问题