]> git.llucax.com Git - software/subdivxget.git/blobdiff - subdivxget
Rename subtitle field title -> titulo
[software/subdivxget.git] / subdivxget
index 5f67edbfeb8852a47a2cbfcf89b1e83c522dc8d1..395eb35bfdf08b47480bc02364a61d9a79d5fa75 100755 (executable)
@@ -43,6 +43,8 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
                self.parsing = False
                self.subs = []
                self.attr = None
+               self.cur = None
+               self.in_script_style = False
 
        def handle_starttag(self, tag, attrs):
                attrs = dict(attrs)
@@ -52,6 +54,9 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
                        self.parsing = True
                if not self.parsing:
                        return
+               if tag == 'script' or tag == 'style':
+                       self.in_script_style = True
+                       return
                if tag == 'div':
                        if attrs.get('id') == 'buscador_detalle':
                                self.parsing = True
@@ -59,7 +64,7 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
                                self.attr = 'desc'
                elif tag == 'a':
                        if attrs.get('class') == 'titulo_menu_izq':
-                               self.attr = 'title'
+                               self.attr = 'titulo'
                        elif attrs.get('href', '').startswith(self.down_uri):
                                self.cur['url'] = attrs['href']
                if self.parsing:
@@ -67,23 +72,31 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
 
        def handle_endtag(self, tag):
                if self.parsing:
+                       if tag == 'script' or tag == 'style':
+                               self.in_script_style = False
+                               return
                        self.depth -= 1
                if self.depth == 0:
                        self.parsing = False
 
        def handle_data(self, data):
-               if self.parsing:
-                       data = data.strip()
-                       if self.attr is not None and data:
-                               self.cur[self.attr] = data
-                               self.attr = None
-                       elif data in ('Downloads:', 'Cds:', 'Comentarios:',
-                                       'Formato:'):
-                               self.attr = data[:-1].lower()
-                       elif data == 'Subido por:':
-                               self.attr = 'autor'
-                       elif data == 'el':
-                               self.attr = 'fecha'
+               if not self.parsing:
+                       return
+               data = data.strip()
+               # Hack to handle comments in <script> <style> which don't end
+               # up in handle_comment(), so we just ignore the whole tags
+               if self.in_script_style:
+                       return
+               if self.attr is not None and data:
+                       self.cur[self.attr] = data
+                       self.attr = None
+               elif data in ('Downloads:', 'Cds:', 'Comentarios:',
+                               'Formato:'):
+                       self.attr = data[:-1].lower()
+               elif data == 'Subido por:':
+                       self.attr = 'autor'
+               elif data == 'el':
+                       self.attr = 'fecha'
 
 
 def subdivx_get_subs(query_str):
@@ -114,7 +127,7 @@ def get_subs(query_str):
 
        for sub in subdivx_get_subs(query_str):
                print '''\
-       - %(title)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
+       - %(titulo)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
          %(desc)s
                DOWNLOADING ...
        ''' % sub