WHEW. hopefully that fixes shit.
This commit is contained in:
parent
7df88af36b
commit
7215e98e96
60
podloader.py
60
podloader.py
@ -261,19 +261,14 @@ def transcodeOGG(conf):
|
|||||||
mediafile])
|
mediafile])
|
||||||
return(mediafile)
|
return(mediafile)
|
||||||
|
|
||||||
def tagMP3(conf, mediafile):
|
def imgConv(imgfile):
|
||||||
# This appears to not work.
|
|
||||||
# http://id3.org/id3v2.3.0#Attached_picture
|
|
||||||
# http://id3.org/id3v2.4.0-frames (section 4.14)
|
|
||||||
# https://stackoverflow.com/questions/7275710/mutagen-how-to-detect-and-embed-album-art-in-mp3-flac-and-mp4
|
|
||||||
# https://stackoverflow.com/questions/409949/how-do-you-embed-album-art-into-an-mp3-using-python
|
|
||||||
magic_file = magic.open(magic.MAGIC_MIME)
|
|
||||||
magic_file.load()
|
|
||||||
imgmime = magic_file.file(conf['tags']['img']).split(';')[0]
|
|
||||||
# Rockbox (and probably some other clients) don't like progressive JPEGs and stuff. SO let's fix that.
|
# Rockbox (and probably some other clients) don't like progressive JPEGs and stuff. SO let's fix that.
|
||||||
# Thanks to the io module, we don't even need to write a new file out.
|
# Thanks to the io module, we don't even need to write a new file out.
|
||||||
img_meta = {}
|
img_meta = {}
|
||||||
with Image.open(conf['tags']['img']) as img_data:
|
magic_file = magic.open(magic.MAGIC_MIME)
|
||||||
|
magic_file.load()
|
||||||
|
img_meta['mime'] = magic_file.file(imgfile).split(';')[0]
|
||||||
|
with Image.open(imgfile) as img_data:
|
||||||
img_meta['height'] = img_data.height
|
img_meta['height'] = img_data.height
|
||||||
img_meta['width'] = img_data.width
|
img_meta['width'] = img_data.width
|
||||||
img_meta['depth'] = img_data.bits
|
img_meta['depth'] = img_data.bits
|
||||||
@ -294,11 +289,20 @@ def tagMP3(conf, mediafile):
|
|||||||
icc_profile = img_data.info.get('icc_profile'),
|
icc_profile = img_data.info.get('icc_profile'),
|
||||||
subsampling = 'keep')
|
subsampling = 'keep')
|
||||||
else:
|
else:
|
||||||
with open(conf['tags']['img']) as f:
|
with open(imgfile) as f:
|
||||||
img_stream = f.read()
|
img_stream = f.read()
|
||||||
# Be kind, please rewind.
|
# Be kind, please rewind.
|
||||||
# Don't sue me, Blockbuster. lol
|
# Don't sue me, Blockbuster. lol
|
||||||
img_stream.seek(0)
|
img_stream.seek(0)
|
||||||
|
return(img_stream, img_meta)
|
||||||
|
|
||||||
|
|
||||||
|
def tagMP3(conf, mediafile):
|
||||||
|
# http://id3.org/id3v2.3.0#Attached_picture
|
||||||
|
# http://id3.org/id3v2.4.0-frames (section 4.14)
|
||||||
|
# https://stackoverflow.com/questions/7275710/mutagen-how-to-detect-and-embed-album-art-in-mp3-flac-and-mp4
|
||||||
|
# https://stackoverflow.com/questions/409949/how-do-you-embed-album-art-into-an-mp3-using-python
|
||||||
|
img_stream, img_meta = imgConv(conf['tags']['img'])
|
||||||
print('{0}: Now adding tags to {1}...'.format(datetime.datetime.now(), mediafile))
|
print('{0}: Now adding tags to {1}...'.format(datetime.datetime.now(), mediafile))
|
||||||
tag = ID3(mediafile)
|
tag = ID3(mediafile)
|
||||||
tag.add(TALB(encoding = 3,
|
tag.add(TALB(encoding = 3,
|
||||||
@ -318,7 +322,8 @@ def tagMP3(conf, mediafile):
|
|||||||
tag.add(TRCK(encoding = 3,
|
tag.add(TRCK(encoding = 3,
|
||||||
text = [conf['tags']['track']]))
|
text = [conf['tags']['track']]))
|
||||||
tag.add(COMM(encoding = 3,
|
tag.add(COMM(encoding = 3,
|
||||||
lang = '\x00\x00\x00',
|
#lang = '\x00\x00\x00', # I'm not sure why we're sending three NULLs, but best to be explicit.
|
||||||
|
lang = 'eng',
|
||||||
desc = 'Description provided by Podloader. https://git.square-r00t.net/Podloader',
|
desc = 'Description provided by Podloader. https://git.square-r00t.net/Podloader',
|
||||||
text = [conf['tags']['comment']]))
|
text = [conf['tags']['comment']]))
|
||||||
tag.add(WXXX(encoding = 3,
|
tag.add(WXXX(encoding = 3,
|
||||||
@ -339,23 +344,19 @@ def tagOGG(conf, mediafile):
|
|||||||
# https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
|
# https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
|
||||||
# https://xiph.org/flac/format.html#metadata_block_picture
|
# https://xiph.org/flac/format.html#metadata_block_picture
|
||||||
# https://github.com/quodlibet/mutagen/issues/200
|
# https://github.com/quodlibet/mutagen/issues/200
|
||||||
magic_file = magic.open(magic.MAGIC_MIME)
|
img_stream, img_meta = imgConv(conf['tags']['img'])
|
||||||
magic_file.load()
|
|
||||||
imgmime = magic_file.file(conf['tags']['img']).split(';')[0]
|
|
||||||
with open(conf['tags']['img'], 'rb') as f:
|
|
||||||
img_raw = f.read()
|
|
||||||
picture = Picture()
|
picture = Picture()
|
||||||
picture.data = img_raw
|
picture.data = img_stream
|
||||||
picture.type = 3
|
picture.type = 3
|
||||||
picture.description = '{0} ({1})'.format(conf['tags']['artist'],
|
picture.description = '{0} ({1})'.format(conf['tags']['artist'],
|
||||||
conf['tags']['comment'])
|
conf['tags']['comment'])
|
||||||
picture.mime = imgmime
|
picture.mime = img_meta['mime']
|
||||||
picture.width = 3000
|
picture.width = img_meta['width']
|
||||||
picture.height = 3000
|
picture.height = img_meta['height']
|
||||||
picture.depth = 24
|
picture.depth = img_meta['bits']
|
||||||
picture_data = picture.write()
|
containered_data = picture.write()
|
||||||
encoded_data = base64.b64encode(picture_data)
|
encoded_data = base64.b64encode(containered_data)
|
||||||
vcomment_value = encoded_data.decode("ascii"
|
img_tag = encoded_data.decode('ascii')
|
||||||
print('{0}: Now adding tags to {1}...'.format(datetime.datetime.now(), mediafile))
|
print('{0}: Now adding tags to {1}...'.format(datetime.datetime.now(), mediafile))
|
||||||
tag = OggVorbis(mediafile)
|
tag = OggVorbis(mediafile)
|
||||||
tag['TITLE'] = conf['episode']['pretty_title']
|
tag['TITLE'] = conf['episode']['pretty_title']
|
||||||
@ -371,7 +372,7 @@ def tagOGG(conf, mediafile):
|
|||||||
tag['CONTACT'] = conf['tags']['url']
|
tag['CONTACT'] = conf['tags']['url']
|
||||||
tag['ENCODED-BY'] = conf['tags']['encoded']
|
tag['ENCODED-BY'] = conf['tags']['encoded']
|
||||||
tag['ENCODER'] = conf['tags']['encoded']
|
tag['ENCODER'] = conf['tags']['encoded']
|
||||||
tag['METADATA_BLOCK_PICTURE'] = img_stream
|
tag['METADATA_BLOCK_PICTURE'] = [img_tag]
|
||||||
tag.save()
|
tag.save()
|
||||||
|
|
||||||
def getSHA256(mediafile):
|
def getSHA256(mediafile):
|
||||||
@ -379,7 +380,7 @@ def getSHA256(mediafile):
|
|||||||
mediafile))
|
mediafile))
|
||||||
filehash = hashlib.sha256()
|
filehash = hashlib.sha256()
|
||||||
with open(mediafile, 'rb') as f:
|
with open(mediafile, 'rb') as f:
|
||||||
for chunk in iter(lambda: f.read(4096), b""):
|
for chunk in iter(lambda: f.read(4096), b''):
|
||||||
filehash.update(chunk)
|
filehash.update(chunk)
|
||||||
return(filehash.hexdigest())
|
return(filehash.hexdigest())
|
||||||
|
|
||||||
@ -592,7 +593,7 @@ def argParse():
|
|||||||
exit(1)
|
exit(1)
|
||||||
return(args)
|
return(args)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
conf = confArgs(configParse(), argParse())
|
conf = confArgs(configParse(), argParse())
|
||||||
mp3 = transcodeMP3(conf)
|
mp3 = transcodeMP3(conf)
|
||||||
tagMP3(conf, mp3)
|
tagMP3(conf, mp3)
|
||||||
@ -607,3 +608,6 @@ if __name__ == "__main__":
|
|||||||
signEp('ogg')
|
signEp('ogg')
|
||||||
uploadFile()
|
uploadFile()
|
||||||
print('{0}: Finished.'.format(datetime.datetime.now()))
|
print('{0}: Finished.'.format(datetime.datetime.now()))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Reference in New Issue
Block a user