]> git.llucax.com Git - software/subdivxget.git/commitdiff
Get all available pages
authorLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:09:46 +0000 (20:09 +0200)
committerLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:12:53 +0000 (20:12 +0200)
SubDivX pages the results, so we keep downloading the next page to get
all the available results until we can't find any subtitles in a page.

subdivxget

index aaa3d4468c042e72ed17910b50cd16b9f7d54df7..5f67edbfeb8852a47a2cbfcf89b1e83c522dc8d1 100755 (executable)
@@ -7,12 +7,13 @@ import subprocess
 import HTMLParser
 
 class SubDivXQuery:
-       def __init__(self, to_search):
+       def __init__(self, to_search, page_number):
                self.host = "www.subdivx.com"
                self.page = "/index.php"
                self.down_page = "/bajar.php"
                self.query = dict(
                        buscar = to_search,
+                       pg = page_number,
                        accion = 5,
                        masdesc = '',
                        subtitulos = 1,
@@ -85,22 +86,33 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
                                self.attr = 'fecha'
 
 
-def get_subs(query_str):
-       query = SubDivXQuery(query_str)
+def subdivx_get_subs(query_str):
+       page_number = 1
+       subs = []
+       while True:
+               query = SubDivXQuery(query_str, page_number)
+               url = urllib.urlopen(query.url)
+               parser = SubDivXHTMLParser(query.down_uri)
+
+               for line in url:
+                       parser.feed(line)
 
-       url = urllib.urlopen(query.url)
+               url.close()
 
-       parser = SubDivXHTMLParser(query.down_uri)
+               if not parser.subs:
+                       break
 
-       for line in url:
-               parser.feed(line)
+               subs.extend(parser.subs)
+               page_number += 1
 
-       url.close()
+       return sorted(subs, key=lambda s: int(s['downloads']), reverse=True)
 
+
+def get_subs(query_str):
        zip_exts = ('application/zip',)
        rar_exts = ('application/rar', 'application/x-rar-compressed')
 
-       for sub in sorted(parser.subs, key=lambda s: int(s['downloads']), reverse=True):
+       for sub in subdivx_get_subs(query_str):
                print '''\
        - %(title)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
          %(desc)s