]> git.llucax.com Git - software/subdivxget.git/commitdiff
Move unzipping to a separate function
authorLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:08:40 +0000 (20:08 +0200)
committerLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:12:55 +0000 (20:12 +0200)
subdivxget

index e938ac8e3b01c1d2254134922889f98573619c3b..1badd17958dec993ee180532e0b00583c0c61644 100755 (executable)
@@ -218,8 +218,21 @@ def subdivx_get_subs(query_str):
        return subs
 
 
-def get_subs(query_str, filters):
+def unzip_subs(fname):
        sub_exts = ('.srt', '.sub')
+       z = zipfile.ZipFile(fname, 'r')
+       z.printdir()
+       for fn in z.namelist():
+               if fn.endswith(sub_exts):
+                       if '..' in fn or fn.startswith('/'):
+                               error('Ignoring file with dangerous name: %s',
+                                               fn)
+                               continue
+                       echo('Extracting %s...', fn)
+                       z.extract(fn)
+
+
+def get_subs(query_str, filters):
        zip_exts = ('application/zip',)
        rar_exts = ('application/rar', 'application/x-rar-compressed')
 
@@ -236,15 +249,7 @@ def get_subs(query_str, filters):
                fname, headers = urlretrieve(sub['url'])
                if 'Content-Type' in headers:
                        if headers['Content-Type'] in zip_exts:
-                               z = zipfile.ZipFile(fname, 'r')
-                               z.printdir()
-                               for fn in z.namelist():
-                                       if fn.endswith(sub_exts):
-                                               if '..' in fn or fn.startswith('/'):
-                                                       error('Dangerous file name: %s', fn)
-                                                       continue
-                                               echo('Extracting %s...', fn)
-                                               z.extract(fn)
+                               unzip_subs(fname)
                        elif headers['Content-Type'] in rar_exts:
                                if subprocess.call(['rar', 'x', fname]) != 0:
                                        error('Error unraring file %s', fname)