From 6b0d0b4db6b5b04a9818154f9230ca905ecdc218 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 5 Oct 2017 01:44:12 +0200 Subject: [PATCH] don't save 404 --- cdoseaplay/update.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cdoseaplay/update.py b/cdoseaplay/update.py index a57be4d..3010612 100755 --- a/cdoseaplay/update.py +++ b/cdoseaplay/update.py @@ -70,14 +70,17 @@ def update_video(url, name): print(url) try: r = requests.get(url, stream=True) - with open('%s.tmp' % name, 'wb') as fd: - shutil.copyfileobj(r.raw, fd) - ox.avinfo('%s.tmp' % name)['duration'] - shutil.move('%s.tmp' % name, name) - mtime = time.mktime(datetime.strptime(r.headers.get("Last-Modified"), "%a, %d %b %Y %X GMT").timetuple()) - os.utime(name, (mtime, mtime)) - ox.avinfo(name)['duration'] - get_subtitle(url.replace('1080p.mp4', lang + '.srt'), name.replace('.mp4', '.srt')) + if r.status_code == 200: + with open('%s.tmp' % name, 'wb') as fd: + shutil.copyfileobj(r.raw, fd) + ox.avinfo('%s.tmp' % name)['duration'] + shutil.move('%s.tmp' % name, name) + mtime = time.mktime(datetime.strptime(r.headers.get("Last-Modified"), "%a, %d %b %Y %X GMT").timetuple()) + os.utime(name, (mtime, mtime)) + ox.avinfo(name)['duration'] + get_subtitle(url.replace('1080p.mp4', lang + '.srt'), name.replace('.mp4', '.srt')) + else: + raise Exception('failed to download %s (%s)' % (url, r.status_code)) except KeyboardInterrupt: os.unlink(lock) sys.exit(-1)