Commits

Petar Marić committed eb9d15a

Refactored video download URLs detection code to use compiled XPath expressions, leading to performance improvements

Comments (0)

Files changed (1)

metaTED/crawler/get_talk_info.py

     'standard': 'Regular',
     'high': 'High',
 }
-_QUALITIES_XPATH_FMT = "//a[@href='%s']/ancestor::node()[name()='tr']/td[5]/a"
+_VIDEO_QUALITIES_XPATH = XPath(
+    '//a[@href=$relative_talk_url]/ancestor::node()[name()="tr"]/td[5]/a'
+)
 
 
 class NoDownloadsFound(Exception):
     """
     return dict(
         (a.text.strip(), urljoin(SITE_URL, a.get('href')))
-        for a in _get_talk_list_document().xpath(
-            _QUALITIES_XPATH_FMT % urlsplit(talk_url).path
+        for a in _VIDEO_QUALITIES_XPATH(
+            _get_talk_list_document(),
+            relative_talk_url=urlsplit(talk_url).path
         )
     )