twentymin.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. try_get,
  5. )
  6. class TwentyMinutenIE(InfoExtractor):
  7. IE_NAME = '20min'
  8. _VALID_URL = r'''(?x)
  9. https?://
  10. (?:www\.)?20min\.ch/
  11. (?:
  12. videotv/*\?.*?\bvid=|
  13. videoplayer/videoplayer\.html\?.*?\bvideoId@
  14. )
  15. (?P<id>\d+)
  16. '''
  17. _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:(?:https?:)?//)?(?:www\.)?20min\.ch/videoplayer/videoplayer.html\?.*?\bvideoId@\d+.*?)\1']
  18. _TESTS = [{
  19. 'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
  20. 'md5': 'e7264320db31eed8c38364150c12496e',
  21. 'info_dict': {
  22. 'id': '469148',
  23. 'ext': 'mp4',
  24. 'title': '85 000 Franken für 15 perfekte Minuten',
  25. 'thumbnail': r're:https?://.*\.jpg$',
  26. },
  27. }, {
  28. 'url': 'http://www.20min.ch/videoplayer/videoplayer.html?params=client@twentyDE|videoId@523629',
  29. 'info_dict': {
  30. 'id': '523629',
  31. 'ext': 'mp4',
  32. 'title': 'So kommen Sie bei Eis und Schnee sicher an',
  33. 'description': 'md5:117c212f64b25e3d95747e5276863f7d',
  34. 'thumbnail': r're:https?://.*\.jpg$',
  35. },
  36. 'params': {
  37. 'skip_download': True,
  38. },
  39. }, {
  40. 'url': 'http://www.20min.ch/videotv/?cid=44&vid=468738',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. video = self._download_json(
  46. f'http://api.20min.ch/video/{video_id}/show',
  47. video_id)['content']
  48. title = video['title']
  49. formats = [{
  50. 'format_id': format_id,
  51. 'url': f'http://podcast.20min-tv.ch/podcast/20min/{video_id}{p}.mp4',
  52. 'quality': quality,
  53. } for quality, (format_id, p) in enumerate([('sd', ''), ('hd', 'h')])]
  54. description = video.get('lead')
  55. thumbnail = video.get('thumbnail')
  56. def extract_count(kind):
  57. return try_get(
  58. video,
  59. lambda x: int_or_none(x['communityobject'][f'thumbs_{kind}']))
  60. like_count = extract_count('up')
  61. dislike_count = extract_count('down')
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'description': description,
  66. 'thumbnail': thumbnail,
  67. 'like_count': like_count,
  68. 'dislike_count': dislike_count,
  69. 'formats': formats,
  70. }