logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

twentymin.py (2860B)


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