diff options
author | Mattias Harrysson <mattias@trixz.se> | 2014-03-09 16:59:18 +0100 |
---|---|---|
committer | Mattias Harrysson <mattias@trixz.se> | 2014-03-09 16:59:18 +0100 |
commit | 27865b21690064b040cd8c38089b6524f80292e3 (patch) | |
tree | de98f5c012b25f82dbf611438e77970089d0718a /youtube_dl | |
parent | edb7fc5435ef522753aa0a17a018edc1dbea2ade (diff) |
[aftonbladet] add extractor for aftonbladet.se
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/extractor/__init__.py | 1 | ||||
-rw-r--r-- | youtube_dl/extractor/aftonbladet.py | 66 |
2 files changed, 67 insertions, 0 deletions
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index f35ee4941..d43e6b764 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -1,5 +1,6 @@ from .academicearth import AcademicEarthCourseIE from .addanime import AddAnimeIE +from .aftonbladet import AftonbladetIE from .anitube import AnitubeIE from .aparat import AparatIE from .appletrailers import AppleTrailersIE diff --git a/youtube_dl/extractor/aftonbladet.py b/youtube_dl/extractor/aftonbladet.py new file mode 100644 index 000000000..568ffc160 --- /dev/null +++ b/youtube_dl/extractor/aftonbladet.py @@ -0,0 +1,66 @@ +# encoding: utf-8 +from __future__ import unicode_literals + +import datetime +import re + +from .common import InfoExtractor + + +class AftonbladetIE(InfoExtractor): + _VALID_URL = r'^http://tv\.aftonbladet\.se/webbtv.+(?P<video_id>article\d+)\.ab$' + _TEST = { + 'url': 'http://tv.aftonbladet.se/webbtv/nyheter/vetenskap/rymden/article36015.ab', + 'info_dict': { + 'id': 'article36015', + 'ext': 'mp4', + 'title': 'Vulkanutbrott i rymden - nu släpper NASA bilderna', + 'description': 'Jupiters måne mest aktiv av alla himlakroppar', + 'upload_date': '20140306', + }, + } + + def _real_extract(self, url): + mobj = re.search(self._VALID_URL, url) + + video_id = mobj.group('video_id') + webpage = self._download_webpage(url, video_id) + + # find internal video meta data + META_URL = 'http://aftonbladet-play.drlib.aptoma.no/video/%s.json' + internal_meta_id = self._html_search_regex(r'data-aptomaId="([\w\d]+)"', webpage, 'internal_meta_id') + internal_meta_url = META_URL % internal_meta_id + internal_meta_json = self._download_json(internal_meta_url, video_id, 'Downloading video meta data') + + # find internal video formats + FORMATS_URL = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s' + internal_video_id = internal_meta_json['videoId'] + internal_formats_url = FORMATS_URL % internal_video_id + internal_formats_json = self._download_json(internal_formats_url, video_id, 'Downloading video formats') + + self.report_extraction(video_id) + formats = [] + for fmt in reversed(internal_formats_json['formats']['http']['pseudostreaming']['mp4']): + p = fmt['paths'][0] + formats.append({ + 'url': 'http://%s:%d/%s/%s' % (p['address'], p['port'], p['path'], p['filename']), + 'ext': 'mp4', + 'width': fmt['width'], + 'height': fmt['height'], + 'tbr': fmt['bitrate'], + 'protocol': 'http', + }) + + timestamp = datetime.datetime.fromtimestamp(internal_meta_json['timePublished']) + upload_date = timestamp.strftime('%Y%m%d') + + return [{ + 'id': video_id, + 'title': internal_meta_json['title'], + 'formats': formats, + 'thumbnail': internal_meta_json['imageUrl'], + 'description': internal_meta_json['shortPreamble'], + 'upload_date': upload_date, + 'duration': internal_meta_json['duration'], + 'view_count': internal_meta_json['views'], + }] |