### Gio File Example with Mutagen Source: https://mutagen.readthedocs.io/en/latest/user/filelike Provides an example of using Mutagen with a file-like object created from a remote URL using PyGObject and the giofile library. This demonstrates reading audio metadata from an online resource. ```python import mutagen import giofile from gi.repository import Gio gio_file = Gio.File.new_for_uri("http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus") cancellable = Gio.Cancellable.new() with giofile.open(gio_file, "rb", cancellable=cancellable) as gfile: print(mutagen.File(gfile).pprint()) ``` -------------------------------- ### Gio Example: Reading Audio Metadata from a URL Source: https://mutagen.readthedocs.io/en/latest/_sources/user/filelike.rst This example shows how to use the `giofile` library with PyGObject and Gio to open a remote audio file (Opus format) via a URL. It then uses Mutagen to read and print the metadata of the audio file. ```python import mutagen import giofile from gi.repository import Gio gio_file = Gio.File.new_for_uri( "http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus") cancellable = Gio.Cancellable.new() with giofile.open(gio_file, "rb", cancellable=cancellable) as gfile: print(mutagen.File(gfile).pprint()) ``` -------------------------------- ### Load Audio File and Display Metadata (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/gettingstarted.rst Loads an audio file using Mutagen's generic File function, guesses the audio type, and displays its metadata. It returns a FileType instance or None if the file cannot be processed. This is a foundational step for interacting with audio files. ```python import mutagen audio = mutagen.File("11. The Way It Is.ogg") print(audio) print(audio.info.pprint()) ``` -------------------------------- ### Load Audio File and Get Metadata (Python) Source: https://mutagen.readthedocs.io/en/latest/user/gettingstarted Loads an audio file, infers its type, and returns a FileType instance. It can access and display metadata like album, artist, and track information. ```Python >>> import mutagen >>> mutagen.File("11. The Way It Is.ogg") {'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'], >>> _.info.pprint() u'Ogg Vorbis, 346.43 seconds, 499821 bps' ``` -------------------------------- ### Handle Invalid FLAC File Error (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/gettingstarted.rst Demonstrates attempting to load a non-FLAC file (an Ogg Vorbis file in this case) as a FLAC file, which correctly raises a `MutagenError` (specifically `FLACNoHeaderError`). This illustrates error handling for incorrect file type parsing. ```python import mutagen.flac try: mutagen.flac.FLAC("11. The Way It Is.ogg") except mutagen.flac.FLACNoHeaderError as e: print(e) ``` -------------------------------- ### Get MP3 Length and Bitrate (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/gettingstarted.rst Loads an MP3 audio file and retrieves its playback length in seconds and its bitrate in bps. This utilizes the `mutagen.mp3` module and accesses the `info` attribute for audio stream details. ```python from mutagen.mp3 import MP3 audio = MP3("example.mp3") print(audio.info.length) print(audio.info.bitrate) ``` -------------------------------- ### Load FLAC File, Set Title, and Save (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/gettingstarted.rst Loads a FLAC audio file, modifies its 'title' tag, prints all tag data for review, and then saves the changes to the file. This snippet requires the `mutagen.flac` module and demonstrates basic metadata editing. ```python from mutagen.flac import FLAC audio = FLAC("example.flac") audio["title"] = u"An example" audio.pprint() audio.save() ``` -------------------------------- ### Python APEv2 Tag Case Sensitivity Example Source: https://mutagen.readthedocs.io/en/latest/user/apev2 Demonstrates the change in APEv2 tag key case sensitivity introduced in Mutagen 1.8. Earlier versions treated keys case-insensitively, while later versions use standard string comparisons. This snippet requires the Mutagen library. ```python from mutagen.apev2 import APEv2 tag = APEv2() tag["Foo"] = "Bar" print("foo" in tag.keys()) ``` ```python print("foo" in tag) ``` -------------------------------- ### Gio Example Output Source: https://mutagen.readthedocs.io/en/latest/_sources/user/filelike.rst The expected output when running the Python script that uses Gio and Mutagen to read metadata from a remote Opus audio file. It displays audio information and various metadata tags. ```sh $ python example.py Ogg Opus, 228.11 seconds (audio/ogg) ENCODER=opusenc from opus-tools 0.1.5 artist=Ehren Starks title=Paper Lights album=Lines Build Walls date=2005-09-05 copyright=Copyright 2005 Ehren Starks license=http://creativecommons.org/licenses/by-nc-sa/1.0/ organization=magnatune.com ``` -------------------------------- ### Add Multiple Cover Images to MP3 using Python Source: https://mutagen.readthedocs.io/en/latest/api/id3_frames This example shows how to add multiple cover images to an MP3 file. It addresses the challenge of ensuring unique HashKeys for each APIC frame by utilizing the `salt` attribute when descriptions are not unique. ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType tags = ID3('example.mp3') image_filenames = ['example.jpeg', 'example.png'] for image_filename in image_filenames: image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() apic = APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data ) while apic.HashKey in tags: apic.salt += ' ' tags.add(apic) tags.save() ``` -------------------------------- ### Using EasyID3 with MP3 Files (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/id3.rst This example shows how to configure the mutagen.mp3.MP3 class to use EasyID3 as its default ID3 handler. This ensures that MP3 files are loaded and manipulated using the simplified EasyID3 interface instead of the full ID3 class. The `pprint()` method is used to display the tag information. ```python from mutagen.easyid3 import EasyID3 from mutagen.mp3 import MP3 audio = MP3("example.mp3", ID3=EasyID3) audio.pprint() ``` -------------------------------- ### EasyID3: Using with MP3 Class (Python) Source: https://mutagen.readthedocs.io/en/latest/user/id3 This code demonstrates how to configure the `mutagen.mp3.MP3` class to use `EasyID3` for handling ID3 tags. This allows the use of the `MP3` class while benefiting from the simplified interface of `EasyID3` for tag editing. ```python from mutagen.easyid3 import EasyID3 from mutagen.mp3 import MP3 audio = MP3("example.mp3", ID3=EasyID3) audio.pprint() ``` -------------------------------- ### Handle MutagenError Exception in Python Source: https://mutagen.readthedocs.io/en/latest/_sources/user/classes.rst Provides an example of how to handle potential errors when loading audio files with Mutagen. It uses a try-except block to catch MutagenError exceptions, which are raised for various loading or processing issues. ```python from mutagen import MutagenError try: f = OggVorbis("11. The Way It Is.ogg") except MutagenError: print("Loading failed :(") ``` -------------------------------- ### Control MP3 Tag Padding with Callbacks in Python Source: https://mutagen.readthedocs.io/en/latest/user/padding Demonstrates how to control MP3 tag padding using custom callback functions with the Mutagen library. It shows examples for removing all padding, using the default implementation, and preserving existing padding without adding new padding. Requires the Mutagen library. ```python from mutagen.mp3 import MP3 def no_padding(info): # this will remove all padding return 0 def default_implementation(info): # this is the default implementation, which can be extended return info.get_default_padding() def no_new_padding(info): # this will use existing padding but never add new one return max(info.padding, 0) f = MP3("somefile.mp3") f.save(padding=no_padding) f.save(padding=default_implementation) f.save(padding=no_new_padding) ``` -------------------------------- ### EasyID3: Listing Valid Keys (Python) Source: https://mutagen.readthedocs.io/en/latest/user/id3 This Python code snippet uses the EasyID3 class from Mutagen to print a list of all valid keys that can be edited through its simplified interface. This is useful for understanding the scope of EasyID3's functionality. ```python from mutagen.easyid3 import EasyID3 print(EasyID3.valid_keys.keys()) ``` -------------------------------- ### Access ID3 Tags as Dictionary Keys Source: https://mutagen.readthedocs.io/en/latest/user/id3 Shows how to view all available ID3 tag frames for an audio file using the dictionary interface. This is useful for inspecting the tags present in a file. The keys represent frame hashes. ```python >>> mutagen.File("01. On The Road Again.mp3").keys() [u'TXXX:replaygain_album_peak', u'RVA2:track', u'APIC:picture', u'UFID:http://musicbrainz.org', 'TDRC', u'TXXX:replaygain_track_peak', 'TIT2', u'RVA2:album', u'TXXX:replaygain_track_gain', u'TXXX:MusicBrainz Album Id', 'TRCK', 'TPE1', 'TALB', u'TXXX:MusicBrainz Album Artist Id', u'TXXX:replaygain_album_gain'] >>> ``` -------------------------------- ### Retrieve All ID3 Frames of a Type (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/id3.rst Illustrates how to fetch all frames of a specific type (e.g., 'TXXX') from an ID3 tag. The `getall` method is used, which is useful when multiple frames of the same type can exist. This example retrieves all 'TXXX' frames and prints their contents. ```pycon >>> for frame in mutagen.File("01. On The Road Again.mp3").tags.getall("TXXX"): ... frame ... TXXX(encoding=, desc=u'replaygain_album_peak', text=[u'1.00000000047']) TXXX(encoding=, desc=u'replaygain_track_peak', text=[u'1.00000000047']) TXXX(encoding=, desc=u'replaygain_track_gain', text=[u'-7.429688 dB']) TXXX(encoding=, desc=u'MusicBrainz Album Id', text=[u'be6fb9b0-5073-4633-aefa-c559554f28e5']) TXXX(encoding=, desc=u'MusicBrainz Album Artist Id', text=[u'815a0279-558c-4522-ac3b-6a1e259e95b5']) TXXX(encoding=, desc=u'replaygain_album_gain', text=[u'-7.429688 dB']) ``` -------------------------------- ### ID3 Paired Text Frame Example (Python) Source: https://mutagen.readthedocs.io/en/latest/api/id3_frames Shows how to use ID3 Paired Text Frames, which store lists of people and their roles or contributions. These frames inherit from `PairedTextFrame` and are suitable for data like involved people or musicians' credits. ```python from mutagen.id3 import PairedTextFrame # Example of creating a PairedTextFrame for Involved People List (TIPL) # Each item in the list is a tuple of (role, person) involved_people_frame = PairedTextFrame(encoding=1, people=[('Producer', 'Bob Ezrin'), ('Engineer', 'Alan Parsons')]) print(f"Involved People: {involved_people_frame.people}") # Example of creating a PairedTextFrame for Musicians Credits List (TMCL) musicians_credits_frame = PairedTextFrame(encoding=1, people=[('Guitar', 'David Gilmour'), ('Bass', 'Roger Waters')]) print(f"Musicians Credits: {musicians_credits_frame.people}") ``` -------------------------------- ### Set Cover Image using APIC Frame in Mutagen Source: https://mutagen.readthedocs.io/en/latest/_sources/api/id3_frames.rst Demonstrates how to set a single cover image for an audio file using the APIC frame in Mutagen. It includes steps for reading the image, determining its MIME type, and adding it to the ID3 tags. ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType image_filename = 'example.jpeg' image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() tags = ID3('example.mp3') tags.setall('APIC', [APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data )]) ``` -------------------------------- ### Set Cover Image in MP3 using Python Source: https://mutagen.readthedocs.io/en/latest/api/id3_frames This example demonstrates how to set the cover image for an MP3 file using Mutagen's APIC frame. It reads an image file, determines its MIME type, and associates it with the album's front cover. ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType image_filename = 'example.jpeg' image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() tags = ID3('example.mp3') tags.setall('APIC', [APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data )]) tags.save() ``` -------------------------------- ### Set Multiple Cover Images using APIC Frame in Mutagen Source: https://mutagen.readthedocs.io/en/latest/_sources/api/id3_frames.rst Explains how to embed multiple cover images into an audio file using Mutagen's APIC frame. This involves handling potential `HashKey` collisions by utilizing the `salt` attribute of the APIC object. ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType tags = ID3('example.mp3') image_filenames = ['example.jpeg', 'example.png'] for image_filename in image_filenames: image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() apic = APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data ) while apic.HashKey in tags: apic.salt += ' ' tags.add(apic) ``` -------------------------------- ### Mutagen File Initialization with File Names and Objects Source: https://mutagen.readthedocs.io/en/latest/_sources/user/filelike.rst Demonstrates how to initialize Mutagen's File type using either a file name string or a file-like object. It also shows how to explicitly specify whether a filename or file object is being passed to avoid type guessing. ```python MP3("myfile.mp3") MP3(myfileobj) MP3(filename="myfile.mp3") MP3(fileobj=myfileobj) ``` -------------------------------- ### Delete ID3 Tag from MP3 (Python) Source: https://mutagen.readthedocs.io/en/latest/_sources/user/gettingstarted.rst Loads an MP3 audio file with ID3 tags and removes all of them using the `delete()` method. This operation is irreversible, so caution is advised. It requires the `mutagen.id3` module. ```python from mutagen.id3 import ID3 audio = ID3("example.mp3") audio.delete() ``` -------------------------------- ### Main Module Source: https://mutagen.readthedocs.io/en/latest/api/index Core classes and functions for general file operations and version information. ```APIDOC ## Main Module ### Description Provides fundamental classes for file handling and access to library version information. ### Classes * **File()**: Represents a generic audio file. * **FileType**: Base class for specific file type handlers. * `FileType.info`: Get file information. * `FileType.tags`: Access file tags. * `FileType.pprint()`: Pretty print file details. * `FileType.add_tags()`: Add or update tags. * `FileType.mime`: Get the MIME type of the file. * `FileType.save()`: Save changes to the file. * `FileType.delete()`: Delete the file. * **Tags**: Represents the tags associated with an audio file. * `Tags.pprint()`: Pretty print the tags. * **Metadata**: Class for managing metadata. * `Metadata.save()`: Save metadata. * `Metadata.delete()`: Delete metadata. * **StreamInfo**: Information about audio streams within a file. * `StreamInfo.pprint()`: Pretty print stream information. * **PaddingInfo**: Information about padding in the audio file. * `PaddingInfo.padding`: Get padding size. * `PaddingInfo.size`: Get total padding size. * `PaddingInfo.get_default_padding()`: Get default padding value. * **MutagenError**: Base exception class for Mutagen errors. ### Other Classes and Functions * `version`: Library version string. * `version_string`: Library version string. * `text`: Function for text handling. * `bytes`: Function for bytes handling. * `fspath`: Function for file path handling. * `fileobj`: Function for file object handling. * `filething`: Utility for file handling. * `PaddingFunction()`: Function related to padding. ``` -------------------------------- ### Mutagen FileType/Metadata Initialization with File Objects Source: https://mutagen.readthedocs.io/en/latest/user/filelike Demonstrates initializing Mutagen's FileType or Metadata with either a filename or a file-like object. It also shows how to explicitly specify the file object using named arguments if automatic type detection fails. Mutagen expects the file offset to be at 0. ```python import mutagen # Using a filename mutagen.File("myfile.mp3") # Using a file-like object myfileobj = open("myfile.mp3", "rb") mutagen.File(myfileobj) # Explicitly specifying filename mutagen.File(filename="myfile.mp3") # Explicitly specifying file object mutagen.File(fileobj=myfileobj) ``` -------------------------------- ### FLAC Module Overview Source: https://mutagen.readthedocs.io/en/latest/_sources/api/flac.rst Provides an overview of the FLAC module, including key classes like FLAC, StreamInfo, Picture, CueSheet, and SeekTable. ```APIDOC ## Mutagen FLAC Module ### Description This module provides support for reading and writing FLAC audio files. It exposes classes for handling FLAC file metadata, stream information, embedded pictures, cue sheets, and seek tables. ### Key Classes - **`mutagen.flac.FLAC`**: The primary class for interacting with FLAC files. It inherits from `mutagen.File` and provides methods for accessing and modifying FLAC-specific tags and metadata. - **`mutagen.flac.StreamInfo`**: Represents the stream information of a FLAC file, including sample rate, channels, and sample count. - **`mutagen.flac.Picture`**: Represents an embedded picture within a FLAC file. - **`mutagen.flac.CueSheet`**: Represents a cue sheet, used for track indexing within a FLAC file. - **`mutagen.flac.CueSheetTrack`**: Represents a single track within a cue sheet. - **`mutagen.flac.CueSheetTrackIndex`**: Represents an index point for a track within a cue sheet. - **`mutagen.flac.SeekTable`**: Represents the seek table for a FLAC file, used for seeking within the audio stream. ### Usage Example (Conceptual) ```python from mutagen.flac import FLAC # Load a FLAC file audio = FLAC("example.flac") # Access tags print(audio.tags) # Modify tags if 'title' in audio.tags: audio.tags['title'] = 'New Title' # Save changes audio.save() # Access stream info print(audio.info) ``` ``` -------------------------------- ### Chapter Extension: Adding Chapters to ID3 Tag (Python) Source: https://mutagen.readthedocs.io/en/latest/user/id3 This Python code snippet shows how to add chapter information to an ID3 tag using Mutagen. It defines a Table of Contents (CTOC) frame and two Chapter (CHAP) frames, each with start and end times and associated title sub-frames, before saving the changes. ```python from mutagen.id3 import ID3, CTOC, CHAP, TIT2, CTOCFlags audio = ID3("example.mp3") audio.add( CTOC(element_id=u"toc", flags=CTOCFlags.TOP_LEVEL | CTOCFlags.ORDERED, child_element_ids=[u"chp1", "chp2"], sub_frames=[ TIT2(text=[u"I'm a TOC"]), ])) audio.add( CHAP(element_id=u"chp1", start_time=0, end_time=42000, sub_frames=[ TIT2(text=[u"I'm the first chapter"]), ])) audio.add( CHAP(element_id=u"chp2", start_time=42000, end_time=84000, sub_frames=[ TIT2(text=[u"I'm the second chapter"]), ])) audio.save() ``` -------------------------------- ### EasyMP3 Class Source: https://mutagen.readthedocs.io/en/latest/api/mp3 A simplified interface for MP3 files using EasyID3 for tags. ```APIDOC ## class mutagen.mp3.EasyMP3 ### Description Like `MP3`, but uses `EasyID3` for tags, providing a simpler way to access common metadata fields. ### Method N/A (Class definition) ### Endpoint N/A (Local library class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from mutagen.mp3 import EasyMP3 audio = EasyMP3("example.mp3") audio['title'] = 'New Title' audio.save() ``` ### Response #### Success Response (Object Instance) - **info** (`MPEGInfo`) - Object containing MPEG audio stream information. - **tags** (`mutagen.easyid3.EasyID3`) - Object containing EasyID3 tags. #### Response Example ```json { "info": { "length": 245.67, "channels": 2, "bitrate": 192000, "sample_rate": 44100, "encoder_info": "LAME 3.100", "bitrate_mode": "VBR" }, "tags": { "title": "Song Title", "artist": "Artist Name" } } ``` ``` -------------------------------- ### ID3v2.3/4 Frames - APIC (Attached Picture) Source: https://mutagen.readthedocs.io/en/latest/_sources/api/id3_frames.rst Documentation and examples for the APIC frame, used for embedding images in ID3 tags. ```APIDOC ## ID3v2.3/4 Frames - APIC (Attached Picture) ### Description The `APIC` frame allows for embedding images within ID3 tags, commonly used for album artwork. ### Class `mutagen.id3.APIC(owner='', preview_start=0, preview_length=0, data=b'')` ### Parameters - **owner** (str) - Optional - The owner of the picture. - **preview_start** (int) - Optional - The start offset of the preview. - **preview_length** (int) - Optional - The length of the preview. - **data** (bytes) - Required - The binary data of the image. - **encoding** (Encoding) - Optional - The text encoding (default: UTF-16). - **mime** (str) - Optional - The MIME type of the image (e.g., 'image/jpeg'). - **type** (PictureType) - Optional - The type of picture (e.g., front cover). - **desc** (str) - Optional - A description of the picture. ### Request Example ```python from mutagen.id3 import APIC, PictureType # Example of creating an APIC frame apic_frame = APIC( mime='image/jpeg', type=PictureType.COVER_FRONT, desc='Cover Art', data=b'\x89PNG\r\n\x1a\n...' # Replace with actual image data ) ``` ### Response #### Success Response (200) - **APIC object**: An instance of the `mutagen.id3.APIC` class representing the attached picture. #### Response Example ```python # Example of an APIC object (representation may vary) , desc='Cover Art', size=12345> ``` ### Examples: To set the cover image for a file you may, for example, do it this way: ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType image_filename = 'example.jpeg' image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() tags = ID3('example.mp3') tags.setall('APIC', [APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data )]) tags.save() ``` Setting multiple cover images is a tad more complicated. Since tags in Mutagen are identified by their `HashKey`, each APIC needs to have a unique `HashKey`. Usually, `HashKey`s in Mutagen are set as `:`, but this would mean that `APIC`s couldn't have the same description. To that end, the `APIC` class has the `salt` attribute, which exists only to be added to the `HashKey` – that is to say, `APIC`s' `HashKey`s are set as `APIC:`. Thus, to add multiple cover images, you can either ensure that each `APIC` has a unique description, or you can add to `salt`: ```python import mimetypes from mutagen.id3 import ID3, APIC, PictureType tags = ID3('example.mp3') image_filenames = ['example.jpeg', 'example.png'] for image_filename in image_filenames: image_mime_type = mimetypes.guess_file_type(image_filename)[0] with open(image_filename, 'rb') as f: image_data = f.read() apic = APIC( mime=image_mime_type, type=PictureType.COVER_FRONT, data=image_data ) while apic.HashKey in tags: apic.salt += ' ' tags.add(apic) tags.save() ``` ``` -------------------------------- ### Mutagen File Handling Source: https://mutagen.readthedocs.io/en/latest/api/base This section explains how to open multimedia files using the Mutagen library. It covers the `mutagen.File` function, its parameters, return types, and potential errors. ```APIDOC ## `mutagen.File` Function ### Description Guesses the type of the file and tries to open it. The file type is decided by several things, such as the first 128 bytes, the filename extension, and the presence of existing tags. If no appropriate type could be found, `None` is returned. ### Method `mutagen.File(_filething_, _options=None_, _easy=False_) ### Parameters #### Path Parameters - **filething** (_filething_) - Description of the file to be opened. - **options** (_Sequence[FileType]_ - Optional) - Sequence of `FileType` implementations, defaults to all included ones. - **easy** (_bool_ - Optional) - If the easy wrappers should be returned if available. For example `EasyMP3` instead of `MP3`. Defaults to `False`. ### Returns - **FileType** - A FileType instance for the detected type or `None` if the type couldn't be determined. ### Raises - **MutagenError** - In case the detected type fails to load the file. ### Usage Example ```python import mutagen.[format] metadata = mutagen.[format].Open(filename) ``` ### Request Body *Not applicable for this function.* ### Response #### Success Response (200) - **metadata** (dict-like object) - A dictionary-like object containing tags. Tags are generally a list of string-like values, but may have additional methods available depending on tag or format. They may also be entirely different objects for certain keys, again depending on format. #### Response Example ```json { "tag1": ["value1a", "value1b"], "tag2": ["value2"] } ``` ``` -------------------------------- ### Instantiate OggVorbis FileType in Python Source: https://mutagen.readthedocs.io/en/latest/_sources/user/classes.rst Demonstrates how to load an Ogg Vorbis audio file using the OggVorbis class from Mutagen. This involves creating an instance of OggVorbis, which represents the audio file and its associated metadata. ```python from mutagen.oggvorbis import OggVorbis f = OggVorbis("11. The Way It Is.ogg") type(f) ``` -------------------------------- ### ID3 Numeric Text Frame Example (Python) Source: https://mutagen.readthedocs.io/en/latest/api/id3_frames Illustrates the use of ID3 Numeric Text Frames, which store numerical metadata. These frames inherit from `NumericTextFrame` and typically use the `_text` attribute for their value. The example shows frames like Beats Per Minute and Audio Length. ```python from mutagen.id3 import NumericTextFrame # Example of creating a NumericTextFrame for Beats Per Minute (BPM) bpm_frame = NumericTextFrame(encoding=1, text=['120']) print(f"BPM: {bpm_frame.text[0]}") # Example of creating a NumericTextFrame for Audio Length (ms) length_frame = NumericTextFrame(encoding=1, text=['253000']) print(f"Audio Length (ms): {length_frame.text[0]}") # Example of creating a NumericTextFrame for iTunes Compilation Flag compilation_frame = NumericTextFrame(encoding=1, text=['1']) print(f"iTunes Compilation Flag: {compilation_frame.text[0]}") ``` -------------------------------- ### ID3v2.3/4 Frames - Other Frames Source: https://mutagen.readthedocs.io/en/latest/_sources/api/id3_frames.rst Documentation for various other ID3v2.3/4 frames. ```APIDOC ## ID3v2.3/4 Frames - Other Frames This section provides details on several other ID3v2.3/4 frames available in Mutagen. ### Frames - **`mutagen.id3.AENC(owner='', preview_start=0, preview_length=0, data=b'')`**: Audio Encryption frame. - **`mutagen.id3.ASPI(S=0, L=0, N=0, b=0, Fi=[])`**: Audio Seek Point Index frame. - **`mutagen.id3.CHAP(element_id='', start_time=0, end_time=0, start_offset=4294967295, end_offset=4294967295, sub_frames={})`**: Chapter frame. - **`mutagen.id3.COMM(encoding=, lang='XXX', desc='', text=[])`**: Comments frame. - **`mutagen.id3.COMR(encoding=, price='', valid_until='19700101', contact='', format=0, seller='', desc='')`**: Commercial Record frame. - **`mutagen.id3.CTOC(element_id='', flags=<0: 0>, child_element_ids=[], sub_frames={})`**: Table of Contents frame. - **`mutagen.id3.ENCR(owner='', method=128, data=b'')`**: Encryption Method frame. - **`mutagen.id3.EQU2(method=0, desc='', adjustments=[])`**: Equalization frame. - **`mutagen.id3.ETCO(format=1, events=[])`**: Event Timing Codes frame. - **`mutagen.id3.GEOB(encoding=, mime='', filename='', desc='', data=b'')`**: General Encapsulated Object frame. - **`mutagen.id3.GRID(owner='', group=128, data=b'')`**: Group Identification Registration frame. - **`mutagen.id3.GRP1(encoding=, text=[])`**: Group Role Name frame. - **`mutagen.id3.IPLS(encoding=, people=[])`**: Involved People List frame. - **`mutagen.id3.LINK(frameid='XXXX', url='', data=b'')`**: Attached Information frame. - **`mutagen.id3.MCDI(data=b'')`**: Music CD Identifier frame. ``` -------------------------------- ### WavPack File Handling in Python Source: https://mutagen.readthedocs.io/en/latest/api/wavpack This snippet demonstrates how to interact with WavPack files using the Mutagen library. It includes a class for handling WavPack files and a static method for scoring file compatibility. The WavPackInfo class provides access to stream information such as channels, length, sample rate, bits per sample, and version. Dependencies include the Mutagen library. ```python class _mutagen.wavpack.WavPack(_filething_): """WavPack reading and writing. WavPack is a lossless format that uses APEv2 tags. """ info: WavPackInfo @staticmethod def score(filename: fspath, fileobj: fileobj, header: bytes) -> int: """Returns a score for how likely the file can be parsed by this type. Parameters: filename: a file path fileobj: a file object open in rb mode. Position is undefined header: data of undefined length, starts with the start of the file. Returns: negative if definitely not a matching type, otherwise a score, the bigger the more certain that the file can be loaded. """ pass class _mutagen.wavpack.WavPackInfo(_fileobj_): """WavPack stream information.""" channels: int length: float sample_rate: int bits_per_sample: int version: int def pprint() -> text: """Print stream information.""" pass ``` -------------------------------- ### Mutagen ID3 Frame Base Classes Source: https://mutagen.readthedocs.io/en/latest/_sources/api/id3_frames.rst Overview of the base classes for ID3 frames in Mutagen. ```APIDOC ## Mutagen ID3 Frame Base Classes This section outlines the fundamental frame base classes provided by the Mutagen library for handling ID3 tags. ### Frame Base Classes - **`mutagen.id3.Frame()`**: The most basic frame class. - **`mutagen.id3.BinaryFrame(data=b'')`**: Represents frames containing binary data. - **`mutagen.id3.PairedTextFrame(encoding=, people=[])`**: For frames with text and associated people information. - **`mutagen.id3.TextFrame(encoding=, text=[])`**: Generic text frame. - **`mutagen.id3.UrlFrame(url='')`**: Frame for storing URLs. - **`mutagen.id3.NumericPartTextFrame(encoding=, text=[])`**: Text frame for numeric parts. - **`mutagen.id3.NumericTextFrame(encoding=, text=[])`**: Text frame for numeric values. - **`mutagen.id3.TimeStampTextFrame(encoding=, text=[])`**: Text frame for timestamps. - **`mutagen.id3.UrlFrameU(url='')`**: Another URL frame type. ```