Comments (9)
@phw Thank you your kind support. I have no more words to express my feeling towards you. You solved a problem due to which I was struggling from many days.
from mutagen.
Glad I could help :)
from mutagen.
First you should use a flac.Picture
and not the APIC ID3 frame.
Then the data needs to be encoder as a base64 ASCII string. See this code for an example:
https://github.com/metabrainz/picard/blob/master/picard/formats/vorbis.py#L319
from mutagen.
See also https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
from mutagen.
See also https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
Modify my code. I am totally confused I have tried more than 10 ways and my brain got messed so pls..
from mutagen.
I updated the code still it's not adding artwork. [doesn't print errors]
class AddMetaData:
"""
Adds metadata to audio file
:param file: file path
:param art_url: album art url
"""
def __init__(self, file, art_url):
art_data = requests.get(art_url).content
audio = OggVorbis(file)
pic = Picture()
pic.type = 3
pic.mime = "image/jpeg"
pic.data = art_data
pic_data = pic.write()
pic_data = base64.b64encode(pic_data).decode("ascii")
audio["metadata_block_picture"] = [pic_data]
audio.save(file)
from mutagen.
Yep, your code is correct. That will ad the image. How do you determine that it did not work?
For a full working example this here adds the tag properly:
import base64
import requests
from mutagen.oggvorbis import OggVorbis
from mutagen.id3 import PictureType
from mutagen.flac import Picture
class AddMetaData:
"""
Adds metadata to audio file
:param file: file path
:param art_url: album art url
"""
def __init__(self, file, art_url):
art_data = requests.get(art_url).content
audio = OggVorbis(file)
pic = Picture()
pic.type = PictureType.COVER_FRONT
pic.mime = "image/jpeg"
pic.data = art_data
pic_data = pic.write()
pic_data = base64.b64encode(pic_data).decode("ascii")
audio["metadata_block_picture"] = [pic_data]
audio.save(file)
file = "./music.ogg"
art_url = "https://fanart.tv/media/overview/5.jpg"
AddMetaData(file, art_url)
Check the result with MP3Tag or Picard to check the tag is present.
from mutagen.
Yep, your code is correct. That will ad the image. How do you determine that it did not work?
For a full working example this here adds the tag properly:
import base64 import requests from mutagen.oggvorbis import OggVorbis from mutagen.id3 import PictureType from mutagen.flac import Picture class AddMetaData: """ Adds metadata to audio file :param file: file path :param art_url: album art url """ def __init__(self, file, art_url): art_data = requests.get(art_url).content audio = OggVorbis(file) pic = Picture() pic.type = PictureType.COVER_FRONT pic.mime = "image/jpeg" pic.data = art_data pic_data = pic.write() pic_data = base64.b64encode(pic_data).decode("ascii") audio["metadata_block_picture"] = [pic_data] audio.save(file) file = "./music.ogg" art_url = "https://fanart.tv/media/overview/5.jpg" AddMetaData(file, art_url)Check the result with MP3Tag or Picard to check the tag is present.
Lemme change my player and see
from mutagen.
PictureType.COVER_FRONT
yeah its working player issue. [resolved]
from mutagen.
Related Issues (20)
- Write into FLAC files via cli HOT 1
- File objects with no tags cast to boolean as false
- wav file bps incorrectly identified as absurdly high value HOT 3
- Unclear what the build system is HOT 5
- Mutagen updates ID3v1 tags but does not save ID3v2 tags HOT 4
- MP4.save() makes phone videos unreadable (Invalid NAL unit size)
- Having problems figuring out how to write to ID3 tags for MP3's HOT 3
- Updating APIC tag leads to empty cover art on Spotify's local files
- Performance on NFS-mounted files much helped by specifying buffering HOT 1
- mutagen-inspect shows tag data but mid3cp shows HOT 4
- OGG Vorbis file save fails: mutagen.ogg.error: unable to read full header; got b'\x00\x00' HOT 3
- Can't open wav ripped from DVD audio: Invalid Chunk - ordinal not in range(128) HOT 6
- OGG Vorbis: wrong (playback) duration / length reported on opus audio HOT 1
- "Universal" audio metadata class HOT 3
- Extensible wave format support HOT 2
- FLAC objects that compare equal do not have the same hash value
- mid3v2 not working with .opus files. HOT 4
- Add support for Audiobooks (.m4b) tags to EasyMP4
- Help with implementing ID3v3.2 spec in dart
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mutagen.