-1

我有一个简单的 Python 程序,可以从 MP3 文件中获取艺术作品。但是当我尝试在我的网页中打开生成的文件时,它没有加载。

这是我的代码:

#!"C:/Python32/python.exe"

import binascii
print('Content-type:image/jpeg\n\n\n')


mp3 = r'music.mp3'
mp3_File = open(mp3, "rb")
mp3_Data = mp3_File.read()
mp3_File.close()


hexs = str(binascii.hexlify(mp3_Data))

hexol = []

for ix in range(2, len(hexs)-1, 2):
    hex = hexs[ix]+hex_str[ix+1]
    hexol.append('|'+hex)

hex_str = "".join(hex_list)

img = hexs.split('|41|50|49|43')

p = img[1]
p = p.replace('|','')
p = p[:34*1500]
hexl = []
for ix in range(2, len(p)-1, 2):
    hex = p[ix]+p[ix+1]
    hexl.append(hex)

 art = open('C:\\hi.jpg','wb')
 art.write(binascii.unhexlify(''.join(hexl).encode('utf-8')))
 art.close()
 data = open('C:\\hi.jpg', 'rb').read()
 print(data)
4

1 回答 1

0

你的代码变成了

import mutagen
from flask import make_response
import os

music_dir = 'c:/www/music'

@app.route('/cover')
def cover_art():
    fname = 'music.mp3'
    mp3 = mutagen.File(os.path.join(music_dir, fname))
    art = mp3.tags['APIC:'].data
    def wsgi_app(environ, start_response):
        start_response('200 OK', [('Content-type', 'image/jpeg')])
        return art
    return make_response(wsgi_app)
于 2012-07-05T14:37:05.457 回答