You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
6.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from .kaltura import KalturaIE
  5. from ..utils import (
  6. get_element_by_id,
  7. strip_or_none,
  8. urljoin,
  9. )
  10. class AZMedienBaseIE(InfoExtractor):
  11. def _kaltura_video(self, partner_id, entry_id):
  12. return self.url_result(
  13. 'kaltura:%s:%s' % (partner_id, entry_id), ie=KalturaIE.ie_key(),
  14. video_id=entry_id)
  15. class AZMedienIE(AZMedienBaseIE):
  16. IE_DESC = 'AZ Medien videos'
  17. _VALID_URL = r'''(?x)
  18. https?://
  19. (?:www\.)?
  20. (?:
  21. telezueri\.ch|
  22. telebaern\.tv|
  23. telem1\.ch
  24. )/
  25. [0-9]+-show-[^/\#]+
  26. (?:
  27. /[0-9]+-episode-[^/\#]+
  28. (?:
  29. /[0-9]+-segment-(?:[^/\#]+\#)?|
  30. \#
  31. )|
  32. \#
  33. )
  34. (?P<id>[^\#]+)
  35. '''
  36. _TESTS = [{
  37. # URL with 'segment'
  38. 'url': 'http://www.telezueri.ch/62-show-zuerinews/13772-episode-sonntag-18-dezember-2016/32419-segment-massenabweisungen-beim-hiltl-club-wegen-pelzboom',
  39. 'info_dict': {
  40. 'id': '1_2444peh4',
  41. 'ext': 'mov',
  42. 'title': 'Massenabweisungen beim Hiltl Club wegen Pelzboom',
  43. 'description': 'md5:9ea9dd1b159ad65b36ddcf7f0d7c76a8',
  44. 'uploader_id': 'TeleZ?ri',
  45. 'upload_date': '20161218',
  46. 'timestamp': 1482084490,
  47. },
  48. 'params': {
  49. 'skip_download': True,
  50. },
  51. }, {
  52. # URL with 'segment' and fragment:
  53. 'url': 'http://www.telebaern.tv/118-show-news/14240-episode-dienstag-17-januar-2017/33666-segment-achtung-gefahr#zu-wenig-pflegerinnen-und-pfleger',
  54. 'only_matching': True
  55. }, {
  56. # URL with 'episode' and fragment:
  57. 'url': 'http://www.telem1.ch/47-show-sonntalk/13986-episode-soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz#soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz',
  58. 'only_matching': True
  59. }, {
  60. # URL with 'show' and fragment:
  61. 'url': 'http://www.telezueri.ch/66-show-sonntalk#burka-plakate-trump-putin-china-besuch',
  62. 'only_matching': True
  63. }]
  64. def _real_extract(self, url):
  65. video_id = self._match_id(url)
  66. webpage = self._download_webpage(url, video_id)
  67. partner_id = self._search_regex(
  68. r'<script[^>]+src=["\'](?:https?:)?//(?:[^/]+\.)?kaltura\.com(?:/[^/]+)*/(?:p|partner_id)/([0-9]+)',
  69. webpage, 'kaltura partner id')
  70. entry_id = self._html_search_regex(
  71. r'<a[^>]+data-id=(["\'])(?P<id>(?:(?!\1).)+)\1[^>]+data-slug=["\']%s'
  72. % re.escape(video_id), webpage, 'kaltura entry id', group='id')
  73. return self._kaltura_video(partner_id, entry_id)
  74. class AZMedienPlaylistIE(AZMedienBaseIE):
  75. IE_DESC = 'AZ Medien playlists'
  76. _VALID_URL = r'''(?x)
  77. https?://
  78. (?:www\.)?
  79. (?:
  80. telezueri\.ch|
  81. telebaern\.tv|
  82. telem1\.ch
  83. )/
  84. (?P<id>[0-9]+-
  85. (?:
  86. show|
  87. topic|
  88. themen
  89. )-[^/\#]+
  90. (?:
  91. /[0-9]+-episode-[^/\#]+
  92. )?
  93. )$
  94. '''
  95. _TESTS = [{
  96. # URL with 'episode'
  97. 'url': 'http://www.telebaern.tv/118-show-news/13735-episode-donnerstag-15-dezember-2016',
  98. 'info_dict': {
  99. 'id': '118-show-news/13735-episode-donnerstag-15-dezember-2016',
  100. 'title': 'News - Donnerstag, 15. Dezember 2016',
  101. },
  102. 'playlist_count': 9,
  103. }, {
  104. # URL with 'themen'
  105. 'url': 'http://www.telem1.ch/258-themen-tele-m1-classics',
  106. 'info_dict': {
  107. 'id': '258-themen-tele-m1-classics',
  108. 'title': 'Tele M1 Classics',
  109. },
  110. 'playlist_mincount': 15,
  111. }, {
  112. # URL with 'topic', contains nested playlists
  113. 'url': 'http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen',
  114. 'only_matching': True,
  115. }, {
  116. # URL with 'show' only
  117. 'url': 'http://www.telezueri.ch/86-show-talktaeglich',
  118. 'only_matching': True
  119. }]
  120. def _real_extract(self, url):
  121. show_id = self._match_id(url)
  122. webpage = self._download_webpage(url, show_id)
  123. entries = []
  124. partner_id = self._search_regex(
  125. r'src=["\'](?:https?:)?//(?:[^/]+\.)kaltura\.com/(?:[^/]+/)*(?:p|partner_id)/(\d+)',
  126. webpage, 'kaltura partner id', default=None)
  127. if partner_id:
  128. entries = [
  129. self._kaltura_video(partner_id, m.group('id'))
  130. for m in re.finditer(
  131. r'data-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage)]
  132. if not entries:
  133. entries = [
  134. self.url_result(m.group('url'), ie=AZMedienIE.ie_key())
  135. for m in re.finditer(
  136. r'<a[^>]+data-real=(["\'])(?P<url>http.+?)\1', webpage)]
  137. if not entries:
  138. entries = [
  139. # May contain nested playlists (e.g. [1]) thus no explicit
  140. # ie_key
  141. # 1. http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen)
  142. self.url_result(urljoin(url, m.group('url')))
  143. for m in re.finditer(
  144. r'<a[^>]+name=[^>]+href=(["\'])(?P<url>/.+?)\1', webpage)]
  145. title = self._search_regex(
  146. r'episodeShareTitle\s*=\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
  147. webpage, 'title',
  148. default=strip_or_none(get_element_by_id(
  149. 'video-title', webpage)), group='title')
  150. return self.playlist_result(entries, show_id, title)