]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/aftonbladet.py
debian/copyright: Fix lintian's dep5-copyright-license-name-not-unique.
[youtubedl] / youtube_dl / extractor / aftonbladet.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class AftonbladetIE(InfoExtractor):
9 _VALID_URL = r'http://tv\.aftonbladet\.se/webbtv.+?(?P<id>article[0-9]+)\.ab(?:$|[?#])'
10 _TEST = {
11 'url': 'http://tv.aftonbladet.se/webbtv/nyheter/vetenskap/rymden/article36015.ab',
12 'info_dict': {
13 'id': 'article36015',
14 'ext': 'mp4',
15 'title': 'Vulkanutbrott i rymden - nu släpper NASA bilderna',
16 'description': 'Jupiters måne mest aktiv av alla himlakroppar',
17 'timestamp': 1394142732,
18 'upload_date': '20140306',
19 },
20 }
21
22 def _real_extract(self, url):
23 video_id = self._match_id(url)
24 webpage = self._download_webpage(url, video_id)
25
26 # find internal video meta data
27 meta_url = 'http://aftonbladet-play.drlib.aptoma.no/video/%s.json'
28 internal_meta_id = self._html_search_regex(
29 r'data-aptomaId="([\w\d]+)"', webpage, 'internal_meta_id')
30 internal_meta_url = meta_url % internal_meta_id
31 internal_meta_json = self._download_json(
32 internal_meta_url, video_id, 'Downloading video meta data')
33
34 # find internal video formats
35 format_url = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
36 internal_video_id = internal_meta_json['videoId']
37 internal_formats_url = format_url % internal_video_id
38 internal_formats_json = self._download_json(
39 internal_formats_url, video_id, 'Downloading video formats')
40
41 formats = []
42 for fmt in internal_formats_json['formats']['http']['pseudostreaming']['mp4']:
43 p = fmt['paths'][0]
44 formats.append({
45 'url': 'http://%s:%d/%s/%s' % (p['address'], p['port'], p['path'], p['filename']),
46 'ext': 'mp4',
47 'width': int_or_none(fmt.get('width')),
48 'height': int_or_none(fmt.get('height')),
49 'tbr': int_or_none(fmt.get('bitrate')),
50 'protocol': 'http',
51 })
52 self._sort_formats(formats)
53
54 return {
55 'id': video_id,
56 'title': internal_meta_json['title'],
57 'formats': formats,
58 'thumbnail': internal_meta_json.get('imageUrl'),
59 'description': internal_meta_json.get('shortPreamble'),
60 'timestamp': int_or_none(internal_meta_json.get('timePublished')),
61 'duration': int_or_none(internal_meta_json.get('duration')),
62 'view_count': int_or_none(internal_meta_json.get('views')),
63 }