]> git.llucax.com Git - software/subdivxget.git/blobdiff - subdivxget
Ignore br tags for tag depth calculations
[software/subdivxget.git] / subdivxget
index 1aecc66b904811165ec5b5f1bfd44798cd551d42..d7c32d1f61047a2a8ea3c7703bb87a74bf0f3b4a 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,15 +64,21 @@ 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:
+               # br are usually not closed, so ignore them in depth calculation
+               if self.parsing and tag != 'br':
                        self.depth += 1
 
        def handle_endtag(self, tag):
                if self.parsing:
-                       self.depth -= 1
+                       if tag == 'script' or tag == 'style':
+                               self.in_script_style = False
+                               return
+                       # see comment in handle_starttag()
+                       if tag != 'br':
+                               self.depth -= 1
                if self.depth == 0:
                        self.parsing = False
 
@@ -75,6 +86,10 @@ class SubDivXHTMLParser(HTMLParser.HTMLParser):
                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
@@ -115,7 +130,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