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