don't save 404

This commit is contained in:
j 2017-10-05 01:44:12 +02:00
parent 777f884a25
commit 6b0d0b4db6

View file

@ -70,14 +70,17 @@ def update_video(url, name):
print(url) print(url)
try: try:
r = requests.get(url, stream=True) r = requests.get(url, stream=True)
with open('%s.tmp' % name, 'wb') as fd: if r.status_code == 200:
shutil.copyfileobj(r.raw, fd) with open('%s.tmp' % name, 'wb') as fd:
ox.avinfo('%s.tmp' % name)['duration'] shutil.copyfileobj(r.raw, fd)
shutil.move('%s.tmp' % name, name) ox.avinfo('%s.tmp' % name)['duration']
mtime = time.mktime(datetime.strptime(r.headers.get("Last-Modified"), "%a, %d %b %Y %X GMT").timetuple()) shutil.move('%s.tmp' % name, name)
os.utime(name, (mtime, mtime)) mtime = time.mktime(datetime.strptime(r.headers.get("Last-Modified"), "%a, %d %b %Y %X GMT").timetuple())
ox.avinfo(name)['duration'] os.utime(name, (mtime, mtime))
get_subtitle(url.replace('1080p.mp4', lang + '.srt'), name.replace('.mp4', '.srt')) 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: except KeyboardInterrupt:
os.unlink(lock) os.unlink(lock)
sys.exit(-1) sys.exit(-1)