Fix for AniDB list downloading

This commit is contained in:
echel0n 2014-07-15 00:17:08 -07:00
parent 4a061d4dd2
commit 703da76d80
1 changed files with 37 additions and 12 deletions

View File

@ -58,29 +58,52 @@ def get_file_size(path):
size = os.path.getsize(path)
return size
def _remove_file_failed(file):
try:
os.remove(file)
except:
pass
def download_file(url, filename):
try:
r = requests.get(url, stream=True, verify=False)
with open(filename, 'wb') as fp:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
fp.write(chunk)
fp.flush()
except requests.HTTPError, e:
_remove_file_failed(filename)
return False
except requests.ConnectionError, e:
return False
except requests.Timeout, e:
return False
except Exception:
_remove_file_failed(filename)
return False
return True
def get_anime_titles_xml(path):
daily_dump = requests.get("http://raw.githubusercontent.com/ScudLee/anime-lists/master/animetitles.xml")
with open(path, "wb") as f:
f.write(daily_dump.content)
return download_file("https://raw.githubusercontent.com/ScudLee/anime-lists/master/animetitles.xml", path)
def get_anime_list_xml(path):
daily_dump = requests.get("http://raw.githubusercontent.com/ScudLee/anime-lists/master/anime-list.xml")
with open(path, "wb") as f:
f.write(daily_dump.content)
return download_file("https://raw.githubusercontent.com/ScudLee/anime-lists/master/anime-list.xml", path)
def read_anidb_xml(filePath=None):
if not filePath:
filePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "animetitles.xml")
if not os.path.isfile(filePath):
get_anime_titles_xml(filePath)
if not get_anime_titles_xml(filePath):
return
else:
mtime = os.path.getmtime(filePath)
if time.time() > mtime + 24 * 60 * 60:
get_anime_titles_xml(filePath)
if not get_anime_titles_xml(filePath):
return
return read_xml_into_etree(filePath)
@ -90,11 +113,13 @@ def read_tvdb_map_xml(filePath=None):
filePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "anime-list.xml")
if not os.path.isfile(filePath):
get_anime_list_xml(filePath)
if not get_anime_list_xml(filePath):
return
else:
mtime = os.path.getmtime(filePath)
if time.time() > mtime + 24 * 60 * 60:
get_anime_list_xml(filePath)
if not get_anime_list_xml(filePath):
return
return read_xml_into_etree(filePath)