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