2011-09-01 9 views
10

एम्बेड एल्बम कला मैं, अगर नहीं, पता लगाने के लिए एक ऑडियो फ़ाइल एल्बम कला एम्बेडेड है या नहीं करना चाहते हैं और उस फाइल करने के लिए एल्बम कला को जोड़ने का तरीका। मैं उत्परिवर्तजनउत्परिवर्तजन: का पता लगाने और में एमपी 3, FLAC और mp4

1) एल्बम कला का पता लगा रहा उपयोग कर रहा हूँ।

from mutagen import File 
audio = File('music.ext') 
test each of audio.pictures, audio['covr'] and audio['APIC:'] 
    if doesn't raise an exception and isn't None, we found album art 

2) मैं एक एमपी 3 फ़ाइल में एल्बम कला एम्बेड करने के लिए इस पाया: How do you embed album art into an MP3 using Python?

कैसे मैं अन्य प्रारूपों में एल्बम कला एम्बेड करूं इस छद्म कोड की तुलना में एक सरल तरीका है?

संपादित करें: एम्बेड mp4

audio = MP4(filename) 
data = open(albumart, 'rb').read() 

covr = [] 
if albumart.endswith('png'): 
    covr.append(MP4Cover(data, MP4Cover.FORMAT_PNG)) 
else: 
    covr.append(MP4Cover(data, MP4Cover.FORMAT_JPEG)) 

audio.tags['covr'] = covr 
audio.save() 

उत्तर

5

एम्बेड flac:

from mutagen.flac import File, Picture, FLAC 

def add_flac_cover(filename, albumart): 
    audio = File(filename) 

    image = Picture() 
    image.type = 3 
    if albumart.endswith('png'): 
     mime = 'image/png' 
    else: 
     mime = 'image/jpeg' 
    image.desc = 'front cover' 
    with open(albumart, 'rb') as f: # better than open(albumart, 'rb').read() ? 
     image.data = f.read() 

    audio.add_picture(image) 
    audio.save() 

पूर्णता के लिए, का पता लगाने के चित्र

def pict_test(audio): 
    try: 
     x = audio.pictures 
     if x: 
      return True 
    except Exception: 
     pass 
    if 'covr' in audio or 'APIC:' in audio: 
     return True 
    return False 
+2

जहां चित्र() फ़ंक्शन से आता है? आपको आयात करने के लिए क्या करना है? – Danny

+4

यह "mutagen.flac आयात FLAC से, पिक्चर" आप होना चाहिए में शामिल हैं इस में आप – Danny

+0

फिलहाल soulution कोई '' '' '' में mutagen.flac''' File'''। '' '' '' '' '' '' '' '' '' '' 'फाइल कहां है, यह कहां से आती है? –

संबंधित मुद्दे