]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/aftonbladet.py
Update the changelog.
[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'https?://tv\.aftonbladet\.se/abtv/articles/(?P<id>[0-9]+)'
10 _TEST = {
11 'url': 'http://tv.aftonbladet.se/abtv/articles/36015',
12 'info_dict': {
13 'id': '36015',
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-metadata.cdn.drvideo.aptoma.no/video/%s.json'
28 player_config = self._parse_json(self._html_search_regex(
29 r'data-player-config="([^"]+)"', webpage, 'player config'), video_id)
30 internal_meta_id = player_config['aptomaVideoId']
31 internal_meta_url = meta_url % internal_meta_id
32 internal_meta_json = self._download_json(
33 internal_meta_url, video_id, 'Downloading video meta data')
34
35 # find internal video formats
36 format_url = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
37 internal_video_id = internal_meta_json['videoId']
38 internal_formats_url = format_url % internal_video_id
39 internal_formats_json = self._download_json(
40 internal_formats_url, video_id, 'Downloading video formats')
41
42 formats = []
43 for fmt in internal_formats_json['formats']['http']['pseudostreaming']['mp4']:
44 p = fmt['paths'][0]
45 formats.append({
46 'url': 'http://%s:%d/%s/%s' % (p['address'], p['port'], p['path'], p['filename']),
47 'ext': 'mp4',
48 'width': int_or_none(fmt.get('width')),
49 'height': int_or_none(fmt.get('height')),
50 'tbr': int_or_none(fmt.get('bitrate')),
51 'protocol': 'http',
52 })
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': internal_meta_json['title'],
58 'formats': formats,
59 'thumbnail': internal_meta_json.get('imageUrl'),
60 'description': internal_meta_json.get('shortPreamble'),
61 'timestamp': int_or_none(internal_meta_json.get('timePublished')),
62 'duration': int_or_none(internal_meta_json.get('duration')),
63 'view_count': int_or_none(internal_meta_json.get('views')),
64 }