Git Product home page Git Product logo

Comments (9)

Swayam25 avatar Swayam25 commented on July 18, 2024 1

@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.

phw avatar phw commented on July 18, 2024 1

Glad I could help :)

from mutagen.

phw avatar phw commented on July 18, 2024

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.

phw avatar phw commented on July 18, 2024

See also https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE

from mutagen.

Swayam25 avatar Swayam25 commented on July 18, 2024

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.

Swayam25 avatar Swayam25 commented on July 18, 2024

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.

phw avatar phw commented on July 18, 2024

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.

Swayam25 avatar Swayam25 commented on July 18, 2024

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.

Swayam25 avatar Swayam25 commented on July 18, 2024
PictureType.COVER_FRONT

yeah its working player issue. [resolved]

from mutagen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.