[packages/griffith] use requests to download files
glen
glen at pld-linux.org
Sun Jun 5 14:53:38 CEST 2016
commit 2a7f8b8cd9a1d4551300f1324e626903e94be0de
Author: Elan Ruusamäe <glen at delfi.ee>
Date: Sun Jun 5 15:53:14 2016 +0300
use requests to download files
Kodi.py | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/Kodi.py b/Kodi.py
index 88a6468..85e7957 100644
--- a/Kodi.py
+++ b/Kodi.py
@@ -26,7 +26,7 @@ import os
import gutils
from lxml import etree
import tempfile
-from urllib2 import urlopen, URLError, HTTPError
+import requests
from movie import TempFileCleanup
import logging
@@ -173,9 +173,9 @@ class ImportPlugin(IP):
# import only "seen" movies
if not details['seen']:
- # importer will skip movie without title and original title
- self.itemindex = self.itemindex + 1
# increment for next iteration
+ self.itemindex = self.itemindex + 1
+ # importer will skip movie without title and original title
return details
for k,v in self.field_map.items():
@@ -230,17 +230,18 @@ class ImportPlugin(IP):
(fd, local_file) = tempfile.mkstemp(suffix=suffix, prefix=prefix)
log.debug("Downloading: %s as %s" % (url, local_file))
try:
- f = urlopen(url)
- os.write(fd, f.read())
+ # http://stackoverflow.com/a/13137873/2314626
+ r = requests.get(url, stream=True, timeout=0.1)
+ if r.status_code == 200:
+ for chunk in r.iter_content(1024):
+ os.write(fd, chunk)
os.close(fd)
- except HTTPError, e:
- log.error("HTTP Error: %s: %s" % (e.code, url))
- return None
- except URLError, e:
- log.error("URL Error: %s: %s" % (e.reason, url))
+ except requests.exceptions.RequestException as e:
+ log.error("HTTP Error: %s: %s" % (e, url))
return None
else:
+ log.debug("Downloaded: %s" % url)
self.tempfiles._tempfiles.append(local_file)
return local_file
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/griffith.git/commitdiff/8a0f2423e2e482c81bb413ce908a2165f4c8dda7
More information about the pld-cvs-commit
mailing list