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.

252 lines
9.2 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. clean_html,
  8. determine_ext,
  9. ExtractorError,
  10. get_element_by_attribute,
  11. orderedSet,
  12. )
  13. class TVPIE(InfoExtractor):
  14. IE_NAME = 'tvp'
  15. IE_DESC = 'Telewizja Polska'
  16. _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:video/(?:[^,\s]*,)*|(?:(?!\d+/)[^/]+/)*)(?P<id>\d+)'
  17. _TESTS = [{
  18. 'url': 'https://vod.tvp.pl/video/czas-honoru,i-seria-odc-13,194536',
  19. 'md5': 'a21eb0aa862f25414430f15fdfb9e76c',
  20. 'info_dict': {
  21. 'id': '194536',
  22. 'ext': 'mp4',
  23. 'title': 'Czas honoru, odc. 13 – Władek',
  24. 'description': 'md5:437f48b93558370b031740546b696e24',
  25. },
  26. }, {
  27. 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
  28. 'md5': 'b0005b542e5b4de643a9690326ab1257',
  29. 'info_dict': {
  30. 'id': '17916176',
  31. 'ext': 'mp4',
  32. 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  33. 'description': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  34. },
  35. }, {
  36. # page id is not the same as video id(#7799)
  37. 'url': 'https://wiadomosci.tvp.pl/33908820/28092017-1930',
  38. 'md5': '84cd3c8aec4840046e5ab712416b73d0',
  39. 'info_dict': {
  40. 'id': '33908820',
  41. 'ext': 'mp4',
  42. 'title': 'Wiadomości, 28.09.2017, 19:30',
  43. 'description': 'Wydanie główne codziennego serwisu informacyjnego.'
  44. },
  45. 'skip': 'HTTP Error 404: Not Found',
  46. }, {
  47. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
  63. 'only_matching': True,
  64. }]
  65. def _real_extract(self, url):
  66. page_id = self._match_id(url)
  67. webpage = self._download_webpage(url, page_id)
  68. video_id = self._search_regex([
  69. r'<iframe[^>]+src="[^"]*?object_id=(\d+)',
  70. r"object_id\s*:\s*'(\d+)'",
  71. r'data-video-id="(\d+)"'], webpage, 'video id', default=page_id)
  72. return {
  73. '_type': 'url_transparent',
  74. 'url': 'tvp:' + video_id,
  75. 'description': self._og_search_description(
  76. webpage, default=None) or self._html_search_meta(
  77. 'description', webpage, default=None),
  78. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  79. 'ie_key': 'TVPEmbed',
  80. }
  81. class TVPEmbedIE(InfoExtractor):
  82. IE_NAME = 'tvp:embed'
  83. IE_DESC = 'Telewizja Polska'
  84. _VALID_URL = r'(?:tvp:|https?://[^/]+\.tvp\.(?:pl|info)/sess/tvplayer\.php\?.*?object_id=)(?P<id>\d+)'
  85. _TESTS = [{
  86. 'url': 'tvp:194536',
  87. 'md5': 'a21eb0aa862f25414430f15fdfb9e76c',
  88. 'info_dict': {
  89. 'id': '194536',
  90. 'ext': 'mp4',
  91. 'title': 'Czas honoru, odc. 13 – Władek',
  92. },
  93. }, {
  94. # not available
  95. 'url': 'http://www.tvp.pl/sess/tvplayer.php?object_id=22670268',
  96. 'md5': '8c9cd59d16edabf39331f93bf8a766c7',
  97. 'info_dict': {
  98. 'id': '22670268',
  99. 'ext': 'mp4',
  100. 'title': 'Panorama, 07.12.2015, 15:40',
  101. },
  102. 'skip': 'Transmisja została zakończona lub materiał niedostępny',
  103. }, {
  104. 'url': 'tvp:22670268',
  105. 'only_matching': True,
  106. }]
  107. def _real_extract(self, url):
  108. video_id = self._match_id(url)
  109. webpage = self._download_webpage(
  110. 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
  111. error = self._html_search_regex(
  112. r'(?s)<p[^>]+\bclass=["\']notAvailable__text["\'][^>]*>(.+?)</p>',
  113. webpage, 'error', default=None) or clean_html(
  114. get_element_by_attribute('class', 'msg error', webpage))
  115. if error:
  116. raise ExtractorError('%s said: %s' % (
  117. self.IE_NAME, clean_html(error)), expected=True)
  118. title = self._search_regex(
  119. r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
  120. webpage, 'title', group='title')
  121. series_title = self._search_regex(
  122. r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
  123. webpage, 'series', group='series', default=None)
  124. if series_title:
  125. title = '%s, %s' % (series_title, title)
  126. thumbnail = self._search_regex(
  127. r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
  128. video_url = self._search_regex(
  129. r'0:{src:([\'"])(?P<url>.*?)\1', webpage,
  130. 'formats', group='url', default=None)
  131. if not video_url or 'material_niedostepny.mp4' in video_url:
  132. video_url = self._download_json(
  133. 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
  134. video_id)['video_url']
  135. formats = []
  136. video_url_base = self._search_regex(
  137. r'(https?://.+?/video)(?:\.(?:ism|f4m|m3u8)|-\d+\.mp4)',
  138. video_url, 'video base url', default=None)
  139. if video_url_base:
  140. # TODO: <Group> found instead of <AdaptationSet> in MPD manifest.
  141. # It's not mentioned in MPEG-DASH standard. Figure that out.
  142. # formats.extend(self._extract_mpd_formats(
  143. # video_url_base + '.ism/video.mpd',
  144. # video_id, mpd_id='dash', fatal=False))
  145. formats.extend(self._extract_ism_formats(
  146. video_url_base + '.ism/Manifest',
  147. video_id, 'mss', fatal=False))
  148. formats.extend(self._extract_f4m_formats(
  149. video_url_base + '.ism/video.f4m',
  150. video_id, f4m_id='hds', fatal=False))
  151. m3u8_formats = self._extract_m3u8_formats(
  152. video_url_base + '.ism/video.m3u8', video_id,
  153. 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
  154. self._sort_formats(m3u8_formats)
  155. m3u8_formats = list(filter(
  156. lambda f: f.get('vcodec') != 'none', m3u8_formats))
  157. formats.extend(m3u8_formats)
  158. for i, m3u8_format in enumerate(m3u8_formats, 2):
  159. http_url = '%s-%d.mp4' % (video_url_base, i)
  160. if self._is_valid_url(http_url, video_id):
  161. f = m3u8_format.copy()
  162. f.update({
  163. 'url': http_url,
  164. 'format_id': f['format_id'].replace('hls', 'http'),
  165. 'protocol': 'http',
  166. })
  167. formats.append(f)
  168. else:
  169. formats = [{
  170. 'format_id': 'direct',
  171. 'url': video_url,
  172. 'ext': determine_ext(video_url, 'mp4'),
  173. }]
  174. self._sort_formats(formats)
  175. return {
  176. 'id': video_id,
  177. 'title': title,
  178. 'thumbnail': thumbnail,
  179. 'formats': formats,
  180. }
  181. class TVPWebsiteIE(InfoExtractor):
  182. IE_NAME = 'tvp:series'
  183. _VALID_URL = r'https?://vod\.tvp\.pl/website/(?P<display_id>[^,]+),(?P<id>\d+)'
  184. _TESTS = [{
  185. # series
  186. 'url': 'https://vod.tvp.pl/website/lzy-cennet,38678312/video',
  187. 'info_dict': {
  188. 'id': '38678312',
  189. },
  190. 'playlist_count': 115,
  191. }, {
  192. # film
  193. 'url': 'https://vod.tvp.pl/website/gloria,35139666',
  194. 'info_dict': {
  195. 'id': '36637049',
  196. 'ext': 'mp4',
  197. 'title': 'Gloria, Gloria',
  198. },
  199. 'params': {
  200. 'skip_download': True,
  201. },
  202. 'add_ie': ['TVPEmbed'],
  203. }, {
  204. 'url': 'https://vod.tvp.pl/website/lzy-cennet,38678312',
  205. 'only_matching': True,
  206. }]
  207. def _entries(self, display_id, playlist_id):
  208. url = 'https://vod.tvp.pl/website/%s,%s/video' % (display_id, playlist_id)
  209. for page_num in itertools.count(1):
  210. page = self._download_webpage(
  211. url, display_id, 'Downloading page %d' % page_num,
  212. query={'page': page_num})
  213. video_ids = orderedSet(re.findall(
  214. r'<a[^>]+\bhref=["\']/video/%s,[^,]+,(\d+)' % display_id,
  215. page))
  216. if not video_ids:
  217. break
  218. for video_id in video_ids:
  219. yield self.url_result(
  220. 'tvp:%s' % video_id, ie=TVPEmbedIE.ie_key(),
  221. video_id=video_id)
  222. def _real_extract(self, url):
  223. mobj = re.match(self._VALID_URL, url)
  224. display_id, playlist_id = mobj.group('display_id', 'id')
  225. return self.playlist_result(
  226. self._entries(display_id, playlist_id), playlist_id)