From 651607e354807916c1eaa0cbf50f3b172ec69844 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 4 Oct 2017 11:02:34 +0200 Subject: [PATCH] get text --- cdoseaplay/update.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cdoseaplay/update.py b/cdoseaplay/update.py index 2948e98..a57be4d 100755 --- a/cdoseaplay/update.py +++ b/cdoseaplay/update.py @@ -33,10 +33,16 @@ if os.path.exists(conf): def get_subtitle(url, name): try: - r = requests.get(url, stream=True) - with open('%s.tmp' % name, 'wb') as fd: - shutil.copyfileobj(r.raw, fd) - shutil.move('%s.tmp' % name, name) + r = requests.get(url) + if r.status_code == 200: + with open('%s.tmp' % name, 'w') as fd: + fd.write(r.text) + shutil.move('%s.tmp' % name, name) + else: + print('%s failed (%s)' % (url, r.status_code)) + except KeyboardInterrupt: + os.unlink(lock) + sys.exit(-1) except: pass @@ -90,6 +96,7 @@ def update_videos(): update_video(url, name) os.unlink(lock) + if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'subtitles': get_all_subtitles()