### Tag Structure Example (FLAC) Source: https://github.com/aadsm/jsmediatags/blob/master/README.md An example of the expected tag object structure for FLAC files, including common shortcuts. ```APIDOC ## FLAC Tag Structure Example ### Description This example shows the structure of a tag object for a FLAC file, illustrating the `type`, `version`, and `tags` properties. The `tags` object contains both shortcut names and detailed tag information. ### Request Body ```json { "type": "FLAC", "version": "1", "tags": { "title": "16/12/95", "artist": "Sam, The Kid", "album": "Pratica(mente)", "track": "12", "picture": ... } } ``` ### Response #### Success Response (200) - **type** (string) - The type of the tag (e.g., "FLAC"). - **version** (string) - The version of the tag format. - **tags** (object) - An object containing the media tags. It includes shortcut names that point to tag data and specific tag names with their `id` and `data`. ``` -------------------------------- ### React Native Usage: Read Media Tags from Local File Path Source: https://context7.com/aadsm/jsmediatags/llms.txt Shows how to read media tags from a local file path in a React Native application. It requires installing additional dependencies and provides examples for direct reading and wrapping the functionality in a Promise for async/await usage. Dependencies: jsmediatags, buffer, react-native-fs. ```javascript const jsmediatags = require('jsmediatags'); new jsmediatags.Reader('/path/to/song.mp3') .read({ onSuccess: (tag) => { console.log('Title:', tag.tags.title); console.log('Artist:', tag.tags.artist); console.log('Album:', tag.tags.album); }, onError: (error) => { console.log('Error:', error.type, error.info); } }); async function getMediaTags(filePath) { return new Promise((resolve, reject) => { new jsmediatags.Reader(filePath) .setTagsToRead(['title', 'artist', 'album', 'picture']) .read({ onSuccess: (tag) => resolve(tag), onError: (error) => reject(error) }); }); } try { const tag = await getMediaTags('/path/to/song.mp3'); console.log('Title:', tag.tags.title); } catch (error) { console.log('Failed to read tags:', error); } ``` -------------------------------- ### JS MediaTags Usage in React Native Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Provides instructions and code examples for using JS MediaTags within a React Native application. It requires additional dependencies and demonstrates both direct usage and promise-based integration. ```bash npm install --save jsmediatags buffer react-native-fs ``` ```javascript const jsmediatags = require('jsmediatags'); new jsmediatags.Reader('/path/to/song.mp3') .read({ onSuccess: (tag) => { console.log('Success!'); console.log(tag); }, onError: (error) => { console.log('Error'); console.log(error); } }); ``` ```javascript new Promise((resolve, reject) => { new jsmediatags.Reader('/path/to/song.mp3') .read({ onSuccess: (tag) => { console.log('Success!'); resolve(tag); }, onError: (error) => { console.log('Error'); reject(error); } }); }) .then(tagInfo => { // handle the onSuccess return }) .catch(error => { // handle errors }); ``` -------------------------------- ### MP4 Tag Output Structure Source: https://github.com/aadsm/jsmediatags/blob/master/README.md An example of the data structure returned by JS MediaTags when parsing an MP4 tag. It shows the file type and any associated metadata tags. ```javascript { type: "MP4", ftyp: "M4A", version: 0, tags: { "©too": { id: "©too", size: 35, description: 'Encoding Tool', data: 'Lavf53.24.2' } } } ``` -------------------------------- ### ID3v2 Tag Output Structure Source: https://github.com/aadsm/jsmediatags/blob/master/README.md An example of the data structure returned by JS MediaTags when parsing an ID3v2 tag. It includes metadata like artist, album, track, and detailed tag information. ```javascript { type: "ID3", version: "2.4.0", major: 4, revision: 0, tags: { artist: "Sam, The Kid", album: "Pratica(mente)", track: "12", TPE1: { id: "TPE1", size: 14, description: "Lead performer(s)/Soloist(s)", data: "Sam, The Kid" }, TALB: { id: "TALB", size: 16, description: "Album/Movie/Show title", data: "Pratica(mente)" }, TRCK: { id: "TRCK", size: 3, description: "Track number/Position in set", data: "12", } }, size: 34423, flags: { unsynchronisation: false, extended_header: false, experimental_indicator: false, footer_present: false } } ``` -------------------------------- ### Configuring Node.js Environment Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Demonstrates how to import file and tag readers in a Node.js environment, showing both runtime compilation via Babel and pre-compiled production paths. ```javascript // Runtime compilation require('babel-core/register'); var NodeFileReader = require('./src/NodeFileReader'); var ID3v2TagReader = require('./src/ID3v2TagReader'); // Compiled code var NodeFileReader = require('./build2/NodeFileReader'); var ID3v2TagReader = require('./build2/ID3v2TagReader'); ``` -------------------------------- ### Read Audio Tags in NodeJS (Simple API) Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Demonstrates the simple API for reading all tags from an audio file in a NodeJS environment. It takes a file path and provides success and error callbacks. ```javascript var jsmediatags = require("jsmediatags"); jsmediatags.read("./music-file.mp3", { onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.log(':(', error.type, error.info); } }); ``` -------------------------------- ### Development: NodeJS Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Instructions for setting up the development environment for jsmediatags, specifically for NodeJS. ```APIDOC ## Development: NodeJS ### Description This section covers the development setup for jsmediatags using NodeJS, including options for runtime compilation and using pre-compiled code. ### NodeJS (With Runtime Compilation) Requires `babel-core/register`. ```javascript require('babel-core/register'); var NodeFileReader = require('./src/NodeFileReader'); var ID3v2TagReader = require('./src/ID3v2TagReader'); // ... other imports ``` ### NodeJS (With Compiled Code (faster)) First, run `npm run build` to generate JavaScript code in the `build2` directory. ```javascript var NodeFileReader = require('./build2/NodeFileReader'); var ID3v2TagReader = require('./build2/ID3v2TagReader'); // ... other imports ``` To automatically recompile source code on changes, run `npm run watch`. ``` -------------------------------- ### Common Tag Shortcuts Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Lists the supported shortcut names for accessing common media tags. ```APIDOC ## Common Tag Shortcuts ### Description The `tags` object provides human-readable shortcut names for commonly used media tags, simplifying access to tag data. ### Parameters #### Query Parameters - **title** (string) - The title of the track. - **artist** (string) - The artist of the track. - **album** (string) - The album the track belongs to. - **year** (string) - The release year of the track. - **comment** (string) - Any comments associated with the track. - **track** (string) - The track number. - **genre** (string) - The genre of the track. - **picture** (object) - Album artwork information. - **lyrics** (string) - The lyrics of the track. ``` -------------------------------- ### Browser Usage: Read Media Tags from File Input and Blob Source: https://context7.com/aadsm/jsmediatags/llms.txt Demonstrates how to read media tags from a File object (obtained from an HTML file input) or a Blob object in a browser environment. It includes handling success and error callbacks, and displaying album artwork. Dependencies: JS MediaTags library included via script tag or CommonJS module. ```javascript const jsmediatags = window.jsmediatags; document.getElementById("fileInput").addEventListener("change", function(event) { const file = event.target.files[0]; jsmediatags.read(file, { onSuccess: function(tag) { console.log("Title:", tag.tags.title); console.log("Artist:", tag.tags.artist); if (tag.tags.picture) { const { data, format } = tag.tags.picture; let base64String = ""; for (let i = 0; i < data.length; i++) { base64String += String.fromCharCode(data[i]); } const img = document.getElementById("albumArt"); img.src = `data:${format};base64,${window.btoa(base64String)}`; } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); }); jsmediatags.read("https://example.com/audio/track.mp3", { onSuccess: function(tag) { document.getElementById("songTitle").textContent = tag.tags.title; document.getElementById("songArtist").textContent = tag.tags.artist; }, onError: function(error) { if (error.type === "xhr") { console.log("Network error:", error.info, error.xhr); } } }); ``` -------------------------------- ### JS MediaTags Tag Shortcuts Reference Source: https://context7.com/aadsm/jsmediatags/llms.txt Illustrates the use of convenient shortcut names provided by JS MediaTags for accessing common metadata tags (title, artist, album, etc.) across different audio formats like ID3, MP4, and FLAC. This simplifies tag retrieval by mapping format-specific identifiers to consistent shortcut keys. ```javascript const jsmediatags = require("jsmediatags"); jsmediatags.read("./song.mp3", { onSuccess: function(tag) { // Available shortcuts (work across ID3, MP4, and FLAC): const shortcuts = { title: tag.tags.title, // ID3: TIT2/TT2, MP4: ©nam, FLAC: TITLE artist: tag.tags.artist, // ID3: TPE1/TP1, MP4: ©ART, FLAC: ARTIST album: tag.tags.album, // ID3: TALB/TAL, MP4: ©alb, FLAC: ALBUM year: tag.tags.year, // ID3: TYER/TYE, MP4: ©day, FLAC: DATE comment: tag.tags.comment, // ID3: COMM/COM, MP4: ©cmt, FLAC: COMMENT track: tag.tags.track, // ID3: TRCK/TRK, MP4: trkn, FLAC: TRACKNUMBER genre: tag.tags.genre, // ID3: TCON/TCO, MP4: ©gen, FLAC: GENRE picture: tag.tags.picture, // ID3: APIC/PIC, MP4: covr, FLAC: PICTURE block lyrics: tag.tags.lyrics // ID3: USLT/ULT, MP4: ©lyr }; console.log("Song info:"); Object.entries(shortcuts).forEach(([key, value]) => { if (value !== undefined) { if (key === 'picture') { console.log(` ${key}: ${value.format} (${value.data.length} bytes)`); } else { console.log(` ${key}: ${value}`); } } }); }, onError: function(error) { console.log("Error:", error); } }); ``` -------------------------------- ### Configuration API: Customize JS MediaTags Behavior Source: https://context7.com/aadsm/jsmediatags/llms.txt Illustrates how to use the `jsmediatags.Config` class to customize the library's behavior. This includes setting XHR timeouts, disabling HTTP headers, avoiding HEAD requests, and adding or removing custom file and tag readers. This allows for fine-tuning network requests and extending tag reading capabilities. ```javascript const jsmediatags = require("jsmediatags"); jsmediatags.Config.setXhrTimeoutInSec(60); jsmediatags.Config.setDisallowedXhrHeaders(["Range", "If-Modified-Since"]); jsmediatags.Config.EXPERIMENTAL_avoidHeadRequests(); const CustomFileReader = require('./CustomFileReader'); jsmediatags.Config.addFileReader(CustomFileReader); const CustomTagReader = require('./CustomTagReader'); jsmediatags.Config.addTagReader(CustomTagReader); const ID3v1TagReader = require('jsmediatags/build2/ID3v1TagReader'); jsmediatags.Config.removeTagReader(ID3v1TagReader); jsmediatags.Config.setXhrTimeoutInSec(10); jsmediatags.read("https://slow-server.com/large-file.mp3", { onSuccess: function(tag) { console.log("Tags loaded:", tag.tags); }, onError: function(error) { if (error.type === "xhr" && error.info.includes("Timeout")) { console.log("Request timed out, server too slow"); } } }); ``` -------------------------------- ### Browser Usage of JS MediaTags Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Shows how to use JS MediaTags in a web browser, including including the library via a script tag and accessing it as a global object or CommonJS module. It supports reading from remote hosts, Blob, and File objects. ```javascript var jsmediatags = window.jsmediatags; ``` ```javascript var jsmediatags = require("jsmediatags"); ``` ```javascript jsmediatags.read("http://www.example.com/music-file.mp3", { onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.log(error); } }); ``` ```javascript jsmediatags.read(blob, ...); ``` ```javascript inputTypeFile.addEventListener("change", function(event) { var file = event.target.files[0]; jsmediatags.read(file, ...); }, false); ``` -------------------------------- ### Read Metadata from Buffers and Byte Arrays Source: https://context7.com/aadsm/jsmediatags/llms.txt Demonstrates how to parse audio tags directly from Node.js Buffer objects or JavaScript byte arrays. This is useful for processing file data already loaded into memory. ```javascript const jsmediatags = require("jsmediatags"); const fs = require("fs"); const buffer = fs.readFileSync("./song.mp3"); jsmediatags.read(buffer, { onSuccess: function(tag) { console.log("Type:", tag.type); console.log("Title:", tag.tags.title); console.log("Artist:", tag.tags.artist); }, onError: function(error) { console.log("Error:", error.type, error.info); } }); const byteArray = Array.from(buffer); jsmediatags.read(byteArray, { onSuccess: function(tag) { console.log("Tags:", tag.tags); }, onError: function(error) { console.log("Error:", error); } }); ``` -------------------------------- ### Displaying Album Artwork Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Converts binary picture data into a base64 string and assigns it to an image source. This is necessary for rendering album covers extracted from media files. ```javascript const { data, format } = result.tags.picture; let base64String = ""; for (const i = 0; i < data.length; i++) { base64String += String.fromCharCode(data[i]); } img.src = `data:${data.format};base64,${window.btoa(base64String)}`; ``` -------------------------------- ### Specify File and Tag Readers in JS MediaTags Source: https://context7.com/aadsm/jsmediatags/llms.txt Demonstrates how to explicitly set file readers (NodeFileReader, XhrFileReader) and tag readers (ID3v2TagReader, MP4TagReader, FLACTagReader) for advanced control over metadata extraction in JS MediaTags. This bypasses automatic detection for specific file types or reading environments. ```javascript const jsmediatags = require("jsmediatags"); const NodeFileReader = require("jsmediatags/build2/NodeFileReader"); const XhrFileReader = require("jsmediatags/build2/XhrFileReader"); const ID3v2TagReader = require("jsmediatags/build2/ID3v2TagReader"); const MP4TagReader = require("jsmediatags/build2/MP4TagReader"); const FLACTagReader = require("jsmediatags/build2/FLACTagReader"); // Force Node.js file reader for local files new jsmediatags.Reader("./song.mp3") .setFileReader(NodeFileReader) .setTagReader(ID3v2TagReader) .read({ onSuccess: function(tag) { console.log("ID3v2 tags:", tag.tags); }, onError: function(error) { console.log("Error:", error); } }); // Force XHR reader for remote files with specific tag reader new jsmediatags.Reader("https://example.com/track.m4a") .setFileReader(XhrFileReader) .setTagReader(MP4TagReader) .read({ onSuccess: function(tag) { console.log("MP4 tags:", tag.tags); }, onError: function(error) { console.log("Error:", error); } }); // Read FLAC file with explicit reader new jsmediatags.Reader("./album.flac") .setTagReader(FLACTagReader) .read({ onSuccess: function(tag) { console.log("FLAC tags:", tag.tags); }, onError: function(error) { console.log("Error:", error); } }); ``` -------------------------------- ### Picture Data Handling Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Explains how to access and display album artwork data from the `picture` tag. ```APIDOC ## Picture Data Handling ### Description The `picture` tag contains an array buffer of the album artwork image and its content type. This section provides a code example to convert this data into a displayable image format. ### Request Body ```javascript { "type": "FLAC", "tags": { "picture": { "data": [Uint8Array], // Array buffer of image bytes "format": "image/jpeg" // Content type of the image } } } ``` ### Request Example ```javascript const { data, format } = result.tags.picture; let base64String = ""; for (let i = 0; i < data.length; i++) { base64String += String.fromCharCode(data[i]); } img.src = `data:${format};base64,${window.btoa(base64String)}`; ``` ### Response #### Success Response (200) - **picture.data** (ArrayBuffer) - The raw image data. - **picture.format** (string) - The MIME type of the image (e.g., "image/jpeg"). ``` -------------------------------- ### Read All Tags with jsmediatags Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Demonstrates how to read all metadata tags from an audio file. The jsmediatags.read method uses an asynchronous callback pattern to return tag data. ```javascript jsmediatags.read("filename.mp3", { onSuccess: function(tag) { var tags = tag.tags; alert(tags.artist + " - " + tags.title + ", " + tags.album); } }); ``` -------------------------------- ### Read MP4/M4A Metadata Source: https://context7.com/aadsm/jsmediatags/llms.txt Explains how to extract iTunes-style metadata from MP4/M4A files. It covers accessing standard tags, raw atom data, and embedded album artwork. ```javascript const jsmediatags = require("jsmediatags"); jsmediatags.read("./audio.m4a", { onSuccess: function(tag) { console.log("Type:", tag.type); console.log("Title:", tag.tags.title); if (tag.tags["trkn"]) { console.log("Track number:", tag.tags["trkn"].data.track); } if (tag.tags.picture) { console.log("Cover art size:", tag.tags.picture.data.length); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); ``` -------------------------------- ### Read Specific Audio Tags in NodeJS (Advanced API) Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Illustrates the advanced API for reading specific tags (e.g., 'title', 'artist') from an audio file using a URL in NodeJS. This method allows for more control over which tags are fetched. ```javascript var jsmediatags = require("jsmediatags"); new jsmediatags.Reader("http://www.example.com/music-file.mp3") .setTagsToRead(["title", "artist"]) .read({ onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.log(':(', error.type, error.info); } }); ``` -------------------------------- ### Read FLAC Metadata Source: https://context7.com/aadsm/jsmediatags/llms.txt Shows how to read VorbisComment metadata blocks from FLAC files. Includes logic for accessing standard tags and FLAC-specific picture blocks. ```javascript const jsmediatags = require("jsmediatags"); jsmediatags.read("./audio.flac", { onSuccess: function(tag) { console.log("Type:", tag.type); console.log("Title:", tag.tags.title); if (tag.tags.picture) { console.log("Picture format:", tag.tags.picture.format); console.log("Picture data length:", tag.tags.picture.data.length); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); ``` -------------------------------- ### Simple API - Read All Tags Source: https://context7.com/aadsm/jsmediatags/llms.txt The `jsmediatags.read()` function provides a simple way to read all tags from an audio file. It automatically detects the file format and extracts metadata including title, artist, album, track number, and album artwork. ```APIDOC ## Simple API - Read All Tags ### Description Reads all available tags from an audio file using a simple, unified API. Automatically detects file format and extracts common metadata. ### Method `jsmediatags.read(source, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const jsmediatags = require("jsmediatags"); jsmediatags.read("./music/song.mp3", { onSuccess: function(tag) { console.log("Tag type:", tag.type); console.log("Version:", tag.version); console.log("Title:", tag.tags.title); console.log("Artist:", tag.tags.artist); console.log("Album:", tag.tags.album); console.log("Year:", tag.tags.year); console.log("Track:", tag.tags.track); console.log("Genre:", tag.tags.genre); console.log("TPE1 Frame:", tag.tags.TPE1); }, onError: function(error) { console.log("Error type:", error.type); console.log("Error info:", error.info); } }); ``` ### Response #### Success Response (200) - **tag** (object) - An object containing the tag information. - **type** (string) - The type of tag format (e.g., "ID3"). - **version** (string) - The version of the tag format (e.g., "2.4.0"). - **tags** (object) - An object containing the extracted metadata fields (e.g., title, artist, album, picture). #### Response Example ```json { "type": "ID3", "version": "2.4.0", "tags": { "title": "My Song", "artist": "Artist Name", "album": "Album Name", "year": "2023", "track": "5", "genre": "Rock", "TPE1": { "id": "TPE1", "size": 14, "description": "Lead performer(s)/Soloist(s)", "data": "Artist Name" } } } ``` ``` -------------------------------- ### Selective Tag Reading with Reader Class Source: https://context7.com/aadsm/jsmediatags/llms.txt Utilizes the Reader class for performance optimization by specifying only required tags. This approach supports both remote URLs and local files, allowing for targeted metadata extraction. ```javascript const jsmediatags = require("jsmediatags"); // Read only specific tags from a remote URL new jsmediatags.Reader("https://example.com/music/song.mp3") .setTagsToRead(["title", "artist", "picture"]) .read({ onSuccess: function(tag) { console.log("Title:", tag.tags.title); console.log("Artist:", tag.tags.artist); // Access album artwork if present if (tag.tags.picture) { const { data, format } = tag.tags.picture; console.log("Picture format:", format); console.log("Picture data length:", data.length); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); // Read raw ID3 frame identifiers new jsmediatags.Reader("./song.mp3") .setTagsToRead(["COMM", "TCON", "WXXX", "APIC"]) .read({ onSuccess: function(tag) { if (tag.tags.COMM) { console.log("Comment:", tag.tags.COMM.data); } if (tag.tags.TCON) { console.log("Content type:", tag.tags.TCON.data); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); ``` -------------------------------- ### HTTP Access Control (CORS) Configuration Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Details the necessary HTTP headers for proper CORS configuration when using jsmediatags with HTTP requests. ```APIDOC ## HTTP Access Control (CORS) Configuration ### Description To ensure proper functionality with HTTP requests, especially for partial file reads, the server must be configured to handle specific headers. This includes allowing `If-Modified-Since` and `Range` headers, and exposing `Content-Length` and `Content-Range` headers. ### Request #### OPTIONS Request Response Headers ``` Access-Control-Allow-Headers: If-Modified-Since, Range ``` #### Response Headers ``` Access-Control-Expose-Headers: Content-Length, Content-Range ``` ### Note The library will still function without these headers, but it will download the entire file instead of only the necessary bytes for tag reading. ``` -------------------------------- ### File and Tag Reader Selection Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Explains how jsmediatags automatically selects file and tag readers and how to specify them manually. ```APIDOC ## File and Tag Reader Selection ### Description jsmediatags automatically selects the appropriate file reader (e.g., for URLs or local paths) and tag reader (based on file signature). Advanced users can manually specify which readers to use. ### Reference #### `jsmediatags.Reader` - **`setTagsToRead(tags: Array)`**: Specify which tags to read. - **`setFileReader(fileReader: typeof MediaFileReader)`**: Use a specific file reader. - **`setTagReader(tagReader: typeof MediaTagReader)`**: Use a specific tag reader. - **`read({onSuccess, onError})`**: Initiate the tag reading process. #### `jsmediatags.Config` - **`addFileReader(fileReader: typeof MediaFileReader)`**: Add a custom file reader. - **`addTagReader(tagReader: typeof MediaTagReader)`**: Add a custom tag reader. - **`setDisallowedXhrHeaders(disallowedXhrHeaders: Array)`**: Prevent specific XHR headers for CORS. - **`setXhrTimeoutInSec(timeoutInSec: number)`**: Set the timeout for HTTP requests (0 for no timeout, defaults to 30s). ``` -------------------------------- ### jsmediatags.read Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Reads metadata tags from a specified media file source using a simple callback-based interface. ```APIDOC ## jsmediatags.read ### Description Reads metadata tags from a local file path, URL, Blob, or File object. ### Method N/A (Library Method) ### Endpoint jsmediatags.read(source, callbacks) ### Parameters #### Path Parameters - **source** (string|Blob|File) - Required - The path to the file, a remote URL, or a Blob/File object. #### Request Body - **onSuccess** (function) - Required - Callback function executed when tags are successfully read. Receives a tag object. - **onError** (function) - Required - Callback function executed if an error occurs. Receives an error object. ### Request Example jsmediatags.read("./music-file.mp3", { onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.log(error); } }); ### Response #### Success Response (200) - **tag** (object) - An object containing metadata fields such as type, version, and a tags object containing specific metadata keys. #### Response Example { "type": "ID3", "version": "2.4.0", "tags": { "artist": "Artist Name", "album": "Album Title" } } ``` -------------------------------- ### Advanced Reader API - Selective Tag Reading Source: https://context7.com/aadsm/jsmediatags/llms.txt The `jsmediatags.Reader` class provides fine-grained control over tag reading, allowing you to specify which tags to read and which file/tag readers to use. This is useful for optimizing performance when you only need specific metadata. ```APIDOC ## Advanced Reader API - Selective Tag Reading ### Description Provides fine-grained control over tag reading, allowing specification of which tags to read and which readers to use. Useful for performance optimization when only specific metadata is needed. ### Method `new jsmediatags.Reader(source).setTagsToRead(tags).read(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Read only specific tags from a remote URL new jsmediatags.Reader("https://example.com/music/song.mp3") .setTagsToRead(["title", "artist", "picture"]) .read({ onSuccess: function(tag) { console.log("Title:", tag.tags.title); console.log("Artist:", tag.tags.artist); if (tag.tags.picture) { const { data, format } = tag.tags.picture; console.log("Picture format:", format); console.log("Picture data length:", data.length); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); // Read raw ID3 frame identifiers new jsmediatags.Reader("./song.mp3") .setTagsToRead(["COMM", "TCON", "WXXX", "APIC"]) .read({ onSuccess: function(tag) { if (tag.tags.COMM) { console.log("Comment:", tag.tags.COMM.data); } if (tag.tags.TCON) { console.log("Content type:", tag.tags.TCON.data); } }, onError: function(error) { console.log("Error:", error.type, error.info); } }); ``` ### Response #### Success Response (200) - **tag** (object) - An object containing the requested tag information. - **tags** (object) - An object containing the extracted metadata fields specified in `setTagsToRead`. #### Response Example ```json { "tags": { "title": "Song Title", "artist": "Artist Name", "picture": { "data": [37, 80, 78, 71, 13, 10, 26, 10, /* ... binary data ... */ ], "format": "image/jpeg" } } } ``` ``` -------------------------------- ### jsmediatags.read(source, callbacks) Source: https://context7.com/aadsm/jsmediatags/llms.txt Reads metadata tags from a given source (file path, Buffer, or byte array) and returns the result via success or error callbacks. ```APIDOC ## jsmediatags.read(source, callbacks) ### Description Reads metadata tags from an audio source. Supports file paths, Node.js Buffer objects, and byte arrays. ### Method N/A (Library function) ### Parameters #### Path Parameters - **source** (string|Buffer|Array) - Required - The file path, buffer, or byte array containing the audio data. - **callbacks** (object) - Required - An object containing `onSuccess` and `onError` callback functions. ### Request Example jsmediatags.read("./song.mp3", { onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.error(error); } }); ### Response #### Success Response (200) - **type** (string) - The format of the tags (e.g., "ID3", "MP4", "FLAC"). - **tags** (object) - The extracted metadata fields (e.g., title, artist, album, picture). #### Response Example { "type": "ID3", "tags": { "title": "Song Title", "artist": "Artist Name", "picture": { "format": "image/jpeg", "data": [...] } } } ``` -------------------------------- ### Read Specific Tags with jsmediatags Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Shows how to filter for specific metadata tags using the jsmediatags.Reader class. This approach is more efficient when only a subset of information is required. ```javascript new jsmediatags.Reader("filename.mp3") .setTagsToRead(["COMM", "TCON", "WXXX"]) .read({ onSuccess: function(tag) { var tags = tag.tags; alert(tags.COMM.data + " - " + tags.TCON.data + ", " + tags.WXXX.data); } }); ``` -------------------------------- ### Handle Errors in jsmediatags Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Illustrates how to implement error handling when reading tags. The onError callback provides an error object containing the error type and details. ```javascript new jsmediatags.Reader("filename.mp3") .setTagsToRead(["comment", "track", "lyrics"]) .read({ onSuccess: function(tag) { var tags = tag.tags; alert(tags.comment + " - " + tags.track + ", " + tags.lyrics); }, onError: function(error) { if (error.type === "xhr") { console.log("There was a network error: ", error.xhr); } } }); ``` -------------------------------- ### jsmediatags.Reader Source: https://github.com/aadsm/jsmediatags/blob/master/README.md Advanced interface for reading metadata, allowing for specific tag filtering and configuration. ```APIDOC ## jsmediatags.Reader ### Description Provides an advanced, chainable API for reading metadata, useful for specifying which tags to retrieve. ### Method N/A (Class Constructor) ### Endpoint new jsmediatags.Reader(source) ### Parameters #### Path Parameters - **source** (string) - Required - The URL or path to the media file. #### Request Body - **setTagsToRead** (array) - Optional - An array of strings representing the specific tags to retrieve (e.g., ['title', 'artist']). ### Request Example new jsmediatags.Reader("http://example.com/file.mp3") .setTagsToRead(["title", "artist"]) .read({ onSuccess: function(tag) { console.log(tag); }, onError: function(error) { console.log(error); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.