diff --git a/lib/svtplay_dl/service/__init__.py b/lib/svtplay_dl/service/__init__.py index 9dcb06a..06fb246 100644 --- a/lib/svtplay_dl/service/__init__.py +++ b/lib/svtplay_dl/service/__init__.py @@ -39,20 +39,35 @@ class Service(object): pass +def opengraph_get(html, prop): + """ + Extract specified OpenGraph property from html. + + >>> opengraph_get('
>> opengraph_get('>> opengraph_get(']*property="og:' + prop + '" content="([^"]*)"', html) + if match is None: + match = re.search(']*content="([^"]*)" property="og:' + prop + '"', html) + if match is None: + return None + return match.group(1) + + class OpenGraphThumbMixin(object): """ Mix this into the service class to grab thumbnail from OpenGraph properties. """ def get_thumbnail(self, options): data = get_http_data(self.url) - match = re.search(r'', data) - if match is None: - return - download_thumbnail(options, match.group(1)) + url = opengraph_get(data, "image") + if url is None: + return + download_thumbnail(options, url) from svtplay_dl.service.aftonbladet import Aftonbladet