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.

213 lines
7.6 KiB

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