X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/9e7f72dcee48e4ced62061b559db75dcf9b79694..c84a8c9ad465608d565821914169f19f30b3b2c3:/src/archive/tasks.py?ds=sidebyside diff --git a/src/archive/tasks.py b/src/archive/tasks.py index 1eeeb28..76f640b 100644 --- a/src/archive/tasks.py +++ b/src/archive/tasks.py @@ -81,9 +81,10 @@ class AudioFormatTask(Task): 'parts_count': audiobook.parts_count, 'source_sha1': audiobook.source_sha1, } - api_call(user, UPLOAD_URL, data=data, files={ - "file": open(path, 'rb'), - }) + with open(path, 'rb') as f: + api_call(user, UPLOAD_URL, data=data, files={ + "file": f, + }) def run(self, uid, aid, publish=True): aid = int(aid) @@ -125,12 +126,12 @@ class Mp3Task(AudioFormatTask): # these shouldn't be staticmethods def id3_text(tag, text): - return tag(encoding=1, text=text) + return tag(encoding=3, text=text) def id3_url(tag, text): return tag(url=text) - def id3_comment(tag, text, lang=u'pol'): - return tag(encoding=1, lang=lang, desc=u'', text=text) - def id3_priv(tag, text, what=u''): + def id3_comment(tag, text, lang='pol'): + return tag(encoding=3, lang=lang, desc='', text=text) + def id3_priv(tag, text, what=''): return tag(owner='wolnelektury.pl?%s' % what, data=text.encode('utf-8')) TAG_MAP = { @@ -178,9 +179,8 @@ class Mp3Task(AudioFormatTask): if COVER_IMAGE: mime = mimetypes.guess_type(COVER_IMAGE) - f = open(COVER_IMAGE) - audio.add(id3.APIC(encoding=0, mime=mime, type=3, desc=u'', data=f.read())) - f.close() + with open(COVER_IMAGE, 'rb') as f: + audio.add(id3.APIC(encoding=0, mime=mime, type=3, desc='', data=f.read())) audio.save()