twentymin.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import remove_end
  6. class TwentyMinutenIE(InfoExtractor):
  7. IE_NAME = '20min'
  8. _VALID_URL = r'https?://(?:www\.)?20min\.ch/(?:videotv/*\?.*\bvid=(?P<id>\d+)|(?:[^/]+/)*(?P<display_id>[^/#?]+))'
  9. _TESTS = [{
  10. # regular video
  11. 'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
  12. 'md5': 'e7264320db31eed8c38364150c12496e',
  13. 'info_dict': {
  14. 'id': '469148',
  15. 'ext': 'mp4',
  16. 'title': '85 000 Franken für 15 perfekte Minuten',
  17. 'description': 'Was die Besucher vom Silvesterzauber erwarten können. (Video: Alice Grosjean/Murat Temel)',
  18. 'thumbnail': 'http://thumbnails.20min-tv.ch/server063/469148/frame-72-469148.jpg'
  19. }
  20. }, {
  21. # news article with video
  22. 'url': 'http://www.20min.ch/schweiz/news/story/-Wir-muessen-mutig-nach-vorne-schauen--22050469',
  23. 'md5': 'cd4cbb99b94130cff423e967cd275e5e',
  24. 'info_dict': {
  25. 'id': '469408',
  26. 'display_id': '-Wir-muessen-mutig-nach-vorne-schauen--22050469',
  27. 'ext': 'flv',
  28. 'title': '«Wir müssen mutig nach vorne schauen»',
  29. 'description': 'Kein Land sei innovativer als die Schweiz, sagte Johann Schneider-Ammann in seiner Neujahrsansprache. Das Land müsse aber seine Hausaufgaben machen.',
  30. 'thumbnail': 'http://www.20min.ch/images/content/2/2/0/22050469/10/teaserbreit.jpg'
  31. },
  32. 'skip': '"This video is no longer available" is shown both on the web page and in the downloaded file.',
  33. }, {
  34. # news article with video
  35. 'url': 'http://www.20min.ch/schweiz/news/story/So-kommen-Sie-bei-Eis-und-Schnee-sicher-an-27032552',
  36. 'md5': '372917ba85ed969e176d287ae54b2f94',
  37. 'info_dict': {
  38. 'id': '523629',
  39. 'display_id': 'So-kommen-Sie-bei-Eis-und-Schnee-sicher-an-27032552',
  40. 'ext': 'mp4',
  41. 'title': 'So kommen Sie bei Eis und Schnee sicher an',
  42. 'description': 'Schneegestöber und Glatteis führten in den letzten Tagen zu zahlreichen Strassenunfällen. Ein Experte erklärt, worauf man nun beim Autofahren achten muss.',
  43. 'thumbnail': 'http://www.20min.ch/images/content/2/7/0/27032552/83/teaserbreit.jpg',
  44. }
  45. }, {
  46. # YouTube embed
  47. 'url': 'http://www.20min.ch/ro/sports/football/story/Il-marque-une-bicyclette-de-plus-de-30-metres--21115184',
  48. 'md5': 'e7e237fd98da2a3cc1422ce683df234d',
  49. 'info_dict': {
  50. 'id': 'ivM7A7SpDOs',
  51. 'ext': 'mp4',
  52. 'title': 'GOLAZO DE CHILENA DE JAVI GÓMEZ, FINALISTA AL BALÓN DE CLM 2016',
  53. 'description': 'md5:903c92fbf2b2f66c09de514bc25e9f5a',
  54. 'upload_date': '20160424',
  55. 'uploader': 'CMM Castilla-La Mancha Media',
  56. 'uploader_id': 'RTVCM',
  57. },
  58. 'add_ie': ['Youtube'],
  59. }, {
  60. 'url': 'http://www.20min.ch/videotv/?cid=44&vid=468738',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'http://www.20min.ch/ro/sortir/cinema/story/Grandir-au-bahut--c-est-dur-18927411',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. mobj = re.match(self._VALID_URL, url)
  68. video_id = mobj.group('id')
  69. display_id = mobj.group('display_id') or video_id
  70. webpage = self._download_webpage(url, display_id)
  71. youtube_url = self._html_search_regex(
  72. r'<iframe[^>]+src="((?:https?:)?//www\.youtube\.com/embed/[^"]+)"',
  73. webpage, 'YouTube embed URL', default=None)
  74. if youtube_url is not None:
  75. return self.url_result(youtube_url, 'Youtube')
  76. title = self._html_search_regex(
  77. r'<h1>.*?<span>(.+?)</span></h1>',
  78. webpage, 'title', default=None)
  79. if not title:
  80. title = remove_end(re.sub(
  81. r'^20 [Mm]inuten.*? -', '', self._og_search_title(webpage)), ' - News')
  82. if not video_id:
  83. params = self._html_search_regex(
  84. r'<iframe[^>]+src="(?:https?:)?//www\.20min\.ch/videoplayer/videoplayer\.html\?params=(.+?[^"])"',
  85. webpage, '20min embed URL')
  86. video_id = self._search_regex(
  87. r'.*videoId@(\d+)',
  88. params, 'Video Id')
  89. description = self._html_search_meta(
  90. 'description', webpage, 'description')
  91. thumbnail = self._og_search_thumbnail(webpage)
  92. formats = []
  93. format_preferences = [('sd', ''), ('hd', 'h')]
  94. for format_id, url_extension in format_preferences:
  95. format_url = 'http://podcast.20min-tv.ch/podcast/20min/%s%s.mp4' % (video_id, url_extension)
  96. formats.append({
  97. 'format_id': format_id,
  98. 'url': format_url,
  99. })
  100. return {
  101. 'id': video_id,
  102. 'display_id': display_id,
  103. 'title': title,
  104. 'description': description,
  105. 'thumbnail': thumbnail,
  106. 'formats': formats,
  107. }