• PYTHON > les tags mp3

      QU’EST-CE QUE LE TAG ID3

      ID3 (v1)

      Song title : 30 characters

      Artist : 30 characters

      Album : 30 characters

      Year : 4 characters

      Comment : 30 characters

      Genre : 1 byte

      ID3 v2

      AENC [Audio encryption]

      APIC [Attached picture]

      COMM [Comments]

      COMR [Commercial frame]

      ENCR [#sec4.26 Encryption method registration]

      EQUA [#sec4.13 Equalization]

      ETCO [#sec4.6 Event timing codes]

      GEOB [#sec4.16 General encapsulated object]

      GRID [#sec4.27 Group identification registration]

      IPLS [#sec4.4 Involved people list]

      LINK [#sec4.21 Linked information]

      MCDI [#sec4.5 Music CD identifier]

      MLLT [#sec4.7 MPEG location lookup table]

      OWNE [#sec4.24 Ownership frame]

      PRIV [#sec4.28 Private frame]

      PCNT [#sec4.17 Play counter]

      POPM [#sec4.18 Popularimeter]

      POSS [#sec4.22 Position synchronisation frame]

      RBUF [#sec4.19 Recommended buffer size]

      RVAD [#sec4.12 Relative volume adjustment]

      RVRB [#sec4.14 Reverb]

      SYLT [#sec4.10 Synchronized lyric/text]

      SYTC [#sec4.8 Synchronized tempo codes]

      TALB [#TALB Album/Movie/Show title]

      TBPM [#TBPM BPM (beats per minute)]

      TCOM [#TCOM Composer]

      TCON [#TCON Content type]

      TCOP [#TCOP Copyright message]

      TDAT [#TDAT Date]

      TDLY [#TDLY Playlist delay]

      TENC [#TENC Encoded by]

      TEXT [#TEXT Lyricist/Text writer]

      TFLT [#TFLT File type]

      TIME [#TIME Time]

      TIT1 [Content group description]

      TIT2 [Title/songname/content description]

      TIT3 [Subtitle/Description refinement]

      TKEY [#TKEY Initial key]

      TLAN [#TLAN Language(s)]

      TLEN [#TLEN Length]

      TMED [#TMED Media type]

      TOAL [#TOAL Original album/movie/show title]

      TOFN [#TOFN Original filename]

      TOLY [#TOLY Original lyricist(s)/text writer(s)]

      TOPE [#TOPE Original artist(s)/performer(s)]

      TORY [#TORY Original release year]

      TOWN [#TOWN File owner/licensee]

      TPE1 [#TPE1 Lead performer(s)/Soloist(s)]

      TPE2 [#TPE2 Band/orchestra/accompaniment]

      TPE3 [#TPE3 Conductor/performer refinement]

      TPE4 [#TPE4 Interpreted, remixed, or otherwise modified by]

      TPOS [#TPOS Part of a set]

      TPUB [#TPUB Publisher]

      TRCK [#TRCK Track number/Position in set]

      TRDA [#TRDA Recording dates]

      TRSN [#TRSN Internet radio station name]

      TRSO [#TRSO Internet radio station owner]

      TSIZ [#TSIZ Size]

      TSRC [#TSRC ISRC (international standard recording code)]

      TSSE [#TSEE Software/Hardware and settings used for encoding]

      TYER [#TYER Year]

      TXXX [#TXXX User defined text information frame]

      UFID [#sec4.1 Unique file identifier]

      USER [#sec4.23 Terms of use]

      USLT [#sec4.9 Unsychronized lyric/text transcription]

      WCOM [#WCOM Commercial information]

      WCOP [#WCOP Copyright/Legal information]

      WOAF [#WOAF Official audio file webpage]

      WOAR [#WOAR Official artist/performer webpage]

      WOAS [#WOAS Official audio source webpage]

      WORS [#WORS Official internet radio station homepage]

      WPAY [#WPAY Payment]

      WPUB [#WPUB Publishers official webpage]

      WXXX [#WXXX User defined URL link frame]

      MUTAGEN

      import mutagen

      Getting Started

      The File functions takes any audio file, guesses its type and returns a FileType instance or None.

      import mutagen
      audio = mutagen.File("fochoer.ogg")
      audio
      {'album': [u'Always Outnumbered, Never Outgunned'],
       'title': [u'The Way It Is'],
       'artist': [u'The Prodigy'],
       'tracktotal': [u'12'],
       'albumartist': [u'The Prodigy'],
       'date': [u'2004'],
       'tracknumber': [u'11'],
      audio.info.pprint()
      u'Ogg Vorbis, 346.43 seconds, 499821 bps'

       

      FLAC file, sets its title, prints all tag data, then saves the file.

      from mutagen.flac import FLAC
      
      audio = FLAC("fichier.flac")
      audio["title"] = u"An example"
      audio.pprint()
      audio.save()

       

      Durée et bitrate of an MP3 file

      from mutagen.mp3 import MP3
      audio = MP3("example.mp3")
      print(audio.info.length)
      print(audio.info.bitrate)

       

      effacer les tags from an MP3 file

      from mutagen.id3 import ID3
      audio = ID3("fichier.mp3")
      audio.delete()

       

      Unicode

      Mutagen has full Unicode support for all formats. When you assign text strings, we strongly recommend using Python unicode objects rather than str objects. If you use str objects, Mutagen will assume they are in UTF-8 (This does not apply to filenames)

      Multiple Values

      Most tag formats support multiple values for each key, so when you access then (e.g. audio["title"]) you will get a list of strings rather than a single one ([u"An example"] rather than u"An example"). Similarly, you can assign a list of strings rather than a single one.

      Metadata

      Metadata is a mixture between FileType and Tags and is used for tagging formats which are not depending on a container format. They can be attached to any file. This includes ID3 and APEv2.

      >>> from mutagen.id3 import ID3
      >>> m = ID3("08. Firestarter.mp3")
      >>> type(m)
      <class 'mutagen.id3.ID3'>
      >>>

      MutagenError

      The MutagenError exception is the base class for all custom exceptions in mutagen.

      from mutagen import MutagenError
      
      try:
          f = OggVorbis("11. The Way It Is.ogg")
      except MutagenError:
          print("Loading failed :(")

       

       

       

       

       

       

       

       

       

       

      AVEC LE MODULE eyeD3

      import eyed3

      AFFICHER LES TAGS

      audio = eyed3.load('/chemin/fichier.mp3')
      
      if audio.tag.isV1():
         print('VERSION: V1')
      if audio.tag.isV2():
         print('VERSION: V2')
      print (f'ARTIST => {audio.tag.artist}') # ARTISTE
      print (f'ALBUM: {audio.tag.album}')
      print (f'TITLE: {audio.tag.title}')
      print (f'TRACK: {audio.tag.track_num}')
      print (f'ALBUM_ARTIST: {audio.tag.album_artist}')
      print (f'COMMENTS: {audio.tag.comments}')
      print (f'BPM: {audio.tag.bpm}')
      print (f'PLAY_COUNT: {audio.tag.play_count}')
      print (f'publisher: {audio.tag.publisher}')
      print (f'cd_id: {audio.tag.cd_id}')
      # comments
      # bpm
      # play_count
      # publisher
      # cd_id

      LES IMAGES

      description

      mime_type

      Y-a-t-il des images et combien ?

      if len(audio.tag.images)>0:
         print (f'il y a {len(audio.tag.images)} images')

       

      print (f'description: {audio.tag.images[0].description}')

      Liste des types d’images

      audio.tag.images[0].picture_type

       

      0 = Autre, 1 = icone 32×32 (PNG), 2 = Autre icone, 3 = Cover (front), 4 = Cover (back), 5 = Leaflet page

      6 Media (ex. label side of CD), 7 = Lead artist/lead performer/soloist, 8 = Artist/performer, 9 = Conductor

      10 = Band / Orchestra, 11 = Composer, 12 = Lyricist / text writer, 13 = Recording Location, 14 = During recording, 15 = During performance

      16 = Movie/video screen capture, 17 = A bright coloured fish, 18 = Illustration, 19 = Band / artist / LOGO, 20 = Publisher / Studio logotype

      Parcourir les images

      for imageinfo in audio.tag.images:
         ...

       

      .image_data - données brutes (binaires) de l’image

      .mime_type - ex: "image/jpg"

      .picture_type - n° de type d’image (voir plus haut)

      .description - description de l’image

       

      audio.tag.images[x]

      Insérer une image

      # read image into memory
      imagedata = open("image.jpg","rb").read()
      
      # append image to tags
      audio.tag.images.set(3,imagedata,"image/jpeg",u"une petite description")
      
      # write it back
      audio.tag.save()

       

      3 => Front Cover, 4 means Back Cover, 0 for other.

       

      Extraire une image du fichier

      Si il n’y a qu’une seule image dans le fichier :

       

      binary_data = audio.tag.images[0].image_data
      with open("d:/image.png", "wb") as img:
         img.write(binary_data)

      Supprimer une image

      Supprimer TOUTES les images :

      x.tag.images.remove('')

       

      Supprimer l’image de type 3 :

      x.tag.images.remove(3)

      RENOMMER UN FICHIER AVEC SES TAGS

      import os
      new_filename = "{0}-{1}.mp3".format(audio.tag.artist, audio.tag.title)
      os.rename('fichier.mp3', new_filename)

       

      CHANGER OU ÉCRIRE UN TAG

       

      # audio.tag.artist = u"CLASSIC 21″

      # audio.tag.save()

       

      # clear() Reset all tag data.

      # setTextFrame(*args, **kwargs)

      # getTextFrame(fid)

       

      # images

      # encoding_date

      # release_date The date the audio was released. This is NOT the original date the work was released, instead it is more like the pressing or version of the release. Original release date is usually what is intended but many programs use this frame and/or don’t distinguish between the two.

      # original_release_date The date the work was originally released.

      # recording_date The date of the recording. Many applications use this for release date regardless of the fact that this value is rarely known, and release dates are more correct.

      # tagging_date

      # lyrics

      # disc_num

      # objects

      # privates

      # popularities

      # genre

      # non_std_genre

      # user_text_frames

      # commercial_url

      # copyright_url

      # audio_file_url

      # audio_source_url

      # artist_url

      # internet_radio_url

      # payment_url

      # publisher_url

      # user_url_frames

      # unique_file_ids

      # terms_of_use

       

      # save(filename=None, version=None, encoding=None, backup=False, preserve_file_time=False, max_padding=None) # Save the tag. If filename is not give the value from the file_info member is used, or a TagException is raised. The version argument can be used to select an ID3 version other than the version read. Select text encoding with ``encoding or use the existing (or default) encoding. If backup is True the orignal file is preserved; likewise if preserve_file_time is True the file´s modification/access times are not updated.

       

      # static remove(filename, version=(3, None, None), preserve_file_time=False)

      # chapters

      # table_of_contents

      # album_type

      # artist_origin Returns a 3-tuple: (city, state, country)

      # frameiter(fids=None)[source] A iterator for tag frames. If fids is passed it must be a list of frame IDs to filter and return.

       

      changer les commentaires

      t = Tag()
      t.comments.set(u"Gritty, yo!")

       

       

 

Aucun commentaire

 

Laissez un commentaire