1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-09 03:34:32 +01:00
youtube-dl/youtube_dl/extractor/aftonbladet.py

64 lines
2.6 KiB
Python
Raw Normal View History

# encoding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2015-04-04 18:19:34 +02:00
from ..utils import int_or_none
class AftonbladetIE(InfoExtractor):
2015-04-04 18:15:59 +02:00
_VALID_URL = r'http://tv\.aftonbladet\.se/webbtv.+?(?P<id>article[0-9]+)\.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',
'timestamp': 1394142732,
'upload_date': '20140306',
},
}
def _real_extract(self, url):
2015-02-03 10:18:32 +01:00
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
# find internal video meta data
meta_url = 'http://aftonbladet-play.drlib.aptoma.no/video/%s.json'
2014-03-10 10:27:40 +01:00
internal_meta_id = self._html_search_regex(
r'data-aptomaId="([\w\d]+)"', webpage, 'internal_meta_id')
internal_meta_url = meta_url % internal_meta_id
2014-03-10 10:27:40 +01:00
internal_meta_json = self._download_json(
internal_meta_url, video_id, 'Downloading video meta data')
# find internal video formats
format_url = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
internal_video_id = internal_meta_json['videoId']
internal_formats_url = format_url % internal_video_id
2014-03-10 10:27:40 +01:00
internal_formats_json = self._download_json(
internal_formats_url, video_id, 'Downloading video formats')
formats = []
2014-03-10 10:27:40 +01:00
for fmt in 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',
2015-04-04 18:19:34 +02:00
'width': int_or_none(fmt.get('width')),
'height': int_or_none(fmt.get('height')),
'tbr': int_or_none(fmt.get('bitrate')),
'protocol': 'http',
})
2014-03-10 10:27:40 +01:00
self._sort_formats(formats)
2014-03-10 10:27:40 +01:00
return {
'id': video_id,
'title': internal_meta_json['title'],
'formats': formats,
2015-04-04 18:19:34 +02:00
'thumbnail': internal_meta_json.get('imageUrl'),
'description': internal_meta_json.get('shortPreamble'),
'timestamp': int_or_none(internal_meta_json.get('timePublished')),
'duration': int_or_none(internal_meta_json.get('duration')),
'view_count': int_or_none(internal_meta_json.get('views')),
2014-03-10 10:27:40 +01:00
}