]> git.llucax.com Git - software/subdivxget.git/commitdiff
Add command line option to avoid downloading
authorLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:07:19 +0000 (20:07 +0200)
committerLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:17:26 +0000 (20:17 +0200)
subdivxget

index 1badd17958dec993ee180532e0b00583c0c61644..597110cbcb820cd0dc1d3d53fb25358eeda502ed 100755 (executable)
@@ -233,6 +233,7 @@ def unzip_subs(fname):
 
 
 def get_subs(query_str, filters):
+       global opts
        zip_exts = ('application/zip',)
        rar_exts = ('application/rar', 'application/x-rar-compressed')
 
@@ -246,6 +247,8 @@ def get_subs(query_str, filters):
   %(desc)s
        DOWNLOADING ...
 ''', **sub)
+               if opts.list_only:
+                       continue
                fname, headers = urlretrieve(sub['url'])
                if 'Content-Type' in headers:
                        if headers['Content-Type'] in zip_exts:
@@ -260,5 +263,30 @@ def get_subs(query_str, filters):
                        error('No Content-Type!')
 
 
-get_subs(sys.argv[1], sys.argv[2:])
+def parse_args(argv):
+       from optparse import OptionParser
+       parser = OptionParser(usage="%prog [OPTIONS] QUERY [FILTER ...]",
+                       description="""
+Download subtitles from subdivx.com searching the string QUERY. If FILTERs are
+specified, only subtitles that matches all those filters are downloaded.
+Filters have the format "X:fitler", where X is a field specification: t=titulo,
+d=desc, a=autor, f=formato, c=comentarios, C=cds, F=fecha and D=downloads.
+filter is a string that should be found on that field (case insensitive). If
+the format specifier is not known (or there isn't one) the filter string is
+looked in all the fields.
+                       """.strip())
+       parser.add_option("-l", "--list-only",
+                       default=False, action='store_true',
+                       help="Don't download the subtitles, just list them")
+
+       (opts, args) = parser.parse_args()
+       if not args:
+              parser.error("Missing query string")
+
+       return (args[0], args[1:], opts)
+
+(query_str, filters, opts) = parse_args(sys.argv)
+
+get_subs(query_str, filters)
+