1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-15 17:21:24 +01:00
youtube-dl/youtube_dl/extractor/twentymin.py

92 lines
2.8 KiB
Python
Raw Normal View History

2016-01-03 21:33:08 +01:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
2017-01-18 16:05:11 +01:00
from ..utils import (
int_or_none,
try_get,
)
2016-01-03 21:33:08 +01:00
class TwentyMinutenIE(InfoExtractor):
IE_NAME = '20min'
2017-01-18 16:05:11 +01:00
_VALID_URL = r'''(?x)
https?://
(?:www\.)?20min\.ch/
(?:
videotv/*\?.*?\bvid=|
videoplayer/videoplayer\.html\?.*?\bvideoId@
)
(?P<id>\d+)
'''
2016-01-03 21:33:08 +01:00
_TESTS = [{
'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
2017-01-09 21:19:55 +01:00
'md5': 'e7264320db31eed8c38364150c12496e',
2016-01-03 21:33:08 +01:00
'info_dict': {
'id': '469148',
2017-01-09 21:19:55 +01:00
'ext': 'mp4',
2016-01-03 21:33:08 +01:00
'title': '85 000 Franken für 15 perfekte Minuten',
2017-01-18 16:05:11 +01:00
'thumbnail': r're:https?://.*\.jpg$',
},
2017-01-09 21:19:55 +01:00
}, {
2017-01-18 16:05:11 +01:00
'url': 'http://www.20min.ch/videoplayer/videoplayer.html?params=client@twentyDE|videoId@523629',
2017-01-09 21:19:55 +01:00
'info_dict': {
'id': '523629',
'ext': 'mp4',
'title': 'So kommen Sie bei Eis und Schnee sicher an',
2017-01-18 16:05:11 +01:00
'description': 'md5:117c212f64b25e3d95747e5276863f7d',
'thumbnail': r're:https?://.*\.jpg$',
},
'params': {
'skip_download': True,
},
2016-01-03 21:33:08 +01:00
}, {
'url': 'http://www.20min.ch/videotv/?cid=44&vid=468738',
'only_matching': True,
}]
2017-01-18 16:05:11 +01:00
@staticmethod
def _extract_urls(webpage):
return [m.group('url') for m in re.finditer(
2017-08-08 00:41:38 +02:00
r'<iframe[^>]+src=(["\'])(?P<url>(?:(?:https?:)?//)?(?:www\.)?20min\.ch/videoplayer/videoplayer.html\?.*?\bvideoId@\d+.*?)\1',
2017-01-18 16:05:11 +01:00
webpage)]
2016-01-03 21:33:08 +01:00
def _real_extract(self, url):
2017-01-18 16:05:11 +01:00
video_id = self._match_id(url)
2016-01-03 21:33:08 +01:00
2017-01-18 16:05:11 +01:00
video = self._download_json(
'http://api.20min.ch/video/%s/show' % video_id,
video_id)['content']
2016-01-03 21:33:08 +01:00
2017-01-18 16:05:11 +01:00
title = video['title']
2017-01-18 16:05:11 +01:00
formats = [{
'format_id': format_id,
'url': 'http://podcast.20min-tv.ch/podcast/20min/%s%s.mp4' % (video_id, p),
'quality': quality,
} for quality, (format_id, p) in enumerate([('sd', ''), ('hd', 'h')])]
self._sort_formats(formats)
2016-01-03 21:33:08 +01:00
2017-01-18 16:05:11 +01:00
description = video.get('lead')
thumbnail = video.get('thumbnail')
2016-01-03 21:33:08 +01:00
2017-01-18 16:05:11 +01:00
def extract_count(kind):
return try_get(
video,
lambda x: int_or_none(x['communityobject']['thumbs_%s' % kind]))
2016-01-03 21:33:08 +01:00
2017-01-18 16:05:11 +01:00
like_count = extract_count('up')
dislike_count = extract_count('down')
2017-01-09 21:19:55 +01:00
2016-01-03 21:33:08 +01:00
return {
'id': video_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
2017-01-18 16:05:11 +01:00
'like_count': like_count,
'dislike_count': dislike_count,
2017-01-09 21:19:55 +01:00
'formats': formats,
2016-01-03 21:33:08 +01:00
}