question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to add metadata when writing file

See original GitHub issue

Hey all,

I was working with OGG Vorbis export and needed to add a metadata field to the file (here: OGG Vorbis Comment). I couldn’t see how this was possible with PySoundfile, so I used the mutagen library instead. It feels a bit hacky to write the file and then read it again to modify the metadata and then save again. Example:

import soundfile
import mutagen

# Write OGG file
soundfile.write('test_file.ogg', data, sr, format='ogg', subtype='vorbis')

# Read OGG file, add metadata and save again
file = mutagen.File('test_file.ogg')
tags_new = file.tags
tags_new['ARTIST'] = 'TEST ARTIST NAME"
file.tags = tags_new
file.save()

Ideally I think something like this would be handy:

import soundfile

# Write OGG file with metadata
tags_new = dict()
tags_new['ARTIST'] = 'TEST ARTIST NAME'
soundfile.write('test_file.ogg', data, sr, format='ogg', subtype='vorbis', tags=tags_new)

Nothing urgent, but probably a nice feature that could be added at some point. The more annoying part is probably making sure it works for each individual file type, as tags work differently for the different formats (MP3, OGG, WAV,…).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bastibecommented, Nov 17, 2021

Open a file, use the dict-like accessor to read or write the metadata:

with soundfile.Soundfile('test_file.wav') as file:
    file['artis'] = 'John Doe'
    album = file['album']

Available fields are:

  • title
  • copyright
  • software
  • artist
  • comment
  • date
  • album
  • license
  • tracknumber
  • genre

The feature is not supported for all file types.

1reaction
bastibecommented, Jan 20, 2021

You can already edit the following metadata fields: title, copyright, software, artist, comment, date, album, license, tracknumber, and genre, using e.g. file['artist'] = 'Picasso'. Beyond that, however, no metadata is accessible through our underlying library, libsndfile.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add Metadata to Your Image Files - Artwork Archive
Right-click on the image and select “Properties” · In the window that appears, you can change the file name, add tags, write a...
Read more >
What is a file's metadata and how to edit it in Windows?
Metadata is information stored in almost any type of file. It can include your name, your company or organization's name, the name of...
Read more >
The 7 best metadata editors available in 2021 - Canto
1. MyMeta. MyMeta is a Windows-based system that allows users to edit media file metadata. If you've ever tried to edit metadata manually,...
Read more >
How to Add Metadata to Images and Video
Open up the folder on your computer that contains the image or video file. · PC users: Right-click on the image, and select...
Read more >
Adding Metadata to Your Images
If you don't use Adobe Lightroom, you can also add metadata to your image file from Adobe Bridge. In the Bridge be aware...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found