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.

179 lines
6.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. clean_html,
  8. get_element_by_attribute,
  9. ExtractorError,
  10. )
  11. class TVPIE(InfoExtractor):
  12. IE_NAME = 'tvp'
  13. IE_DESC = 'Telewizja Polska'
  14. _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)'
  15. _TESTS = [{
  16. 'url': 'http://vod.tvp.pl/194536/i-seria-odc-13',
  17. 'md5': '8aa518c15e5cc32dfe8db400dc921fbb',
  18. 'info_dict': {
  19. 'id': '194536',
  20. 'ext': 'mp4',
  21. 'title': 'Czas honoru, I seria – odc. 13',
  22. },
  23. }, {
  24. 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
  25. 'md5': 'b0005b542e5b4de643a9690326ab1257',
  26. 'info_dict': {
  27. 'id': '17916176',
  28. 'ext': 'mp4',
  29. 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  30. },
  31. }, {
  32. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
  42. 'only_matching': True,
  43. }, {
  44. 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
  48. 'only_matching': True,
  49. }]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. webpage = self._download_webpage(
  53. 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
  54. error_massage = get_element_by_attribute('class', 'msg error', webpage)
  55. if error_massage:
  56. raise ExtractorError('%s said: %s' % (
  57. self.IE_NAME, clean_html(error_massage)), expected=True)
  58. title = self._search_regex(
  59. r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
  60. webpage, 'title', group='title')
  61. series_title = self._search_regex(
  62. r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
  63. webpage, 'series', group='series', default=None)
  64. if series_title:
  65. title = '%s, %s' % (series_title, title)
  66. thumbnail = self._search_regex(
  67. r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
  68. video_url = self._search_regex(
  69. r'0:{src:([\'"])(?P<url>.*?)\1', webpage,
  70. 'formats', group='url', default=None)
  71. if not video_url or 'material_niedostepny.mp4' in video_url:
  72. video_url = self._download_json(
  73. 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
  74. video_id)['video_url']
  75. formats = []
  76. video_url_base = self._search_regex(
  77. r'(https?://.+?/video)(?:\.(?:ism|f4m|m3u8)|-\d+\.mp4)',
  78. video_url, 'video base url', default=None)
  79. if video_url_base:
  80. # TODO: <Group> found instead of <AdaptationSet> in MPD manifest.
  81. # It's not mentioned in MPEG-DASH standard. Figure that out.
  82. # formats.extend(self._extract_mpd_formats(
  83. # video_url_base + '.ism/video.mpd',
  84. # video_id, mpd_id='dash', fatal=False))
  85. formats.extend(self._extract_f4m_formats(
  86. video_url_base + '.ism/video.f4m',
  87. video_id, f4m_id='hds', fatal=False))
  88. m3u8_formats = self._extract_m3u8_formats(
  89. video_url_base + '.ism/video.m3u8', video_id,
  90. 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
  91. self._sort_formats(m3u8_formats)
  92. m3u8_formats = list(filter(
  93. lambda f: f.get('vcodec') != 'none' and f.get('resolution') != 'multiple',
  94. m3u8_formats))
  95. formats.extend(m3u8_formats)
  96. for i, m3u8_format in enumerate(m3u8_formats, 2):
  97. http_url = '%s-%d.mp4' % (video_url_base, i)
  98. if self._is_valid_url(http_url, video_id):
  99. f = m3u8_format.copy()
  100. f.update({
  101. 'url': http_url,
  102. 'format_id': f['format_id'].replace('hls', 'http'),
  103. 'protocol': 'http',
  104. })
  105. formats.append(f)
  106. else:
  107. formats = [{
  108. 'format_id': 'direct',
  109. 'url': video_url,
  110. 'ext': determine_ext(video_url, 'mp4'),
  111. }]
  112. self._sort_formats(formats)
  113. return {
  114. 'id': video_id,
  115. 'title': title,
  116. 'thumbnail': thumbnail,
  117. 'formats': formats,
  118. }
  119. class TVPSeriesIE(InfoExtractor):
  120. IE_NAME = 'tvp:series'
  121. _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
  122. _TESTS = [{
  123. 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
  124. 'info_dict': {
  125. 'title': 'Ogniem i mieczem',
  126. 'id': '4278026',
  127. },
  128. 'playlist_count': 4,
  129. }, {
  130. 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
  131. 'info_dict': {
  132. 'title': 'Boso przez świat',
  133. 'id': '9329207',
  134. },
  135. 'playlist_count': 86,
  136. }]
  137. def _real_extract(self, url):
  138. display_id = self._match_id(url)
  139. webpage = self._download_webpage(url, display_id, tries=5)
  140. title = self._html_search_regex(
  141. r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
  142. playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
  143. playlist = self._download_webpage(
  144. 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
  145. 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
  146. note='Downloading playlist')
  147. videos_paths = re.findall(
  148. '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
  149. entries = [
  150. self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key())
  151. for v_path in videos_paths]
  152. return {
  153. '_type': 'playlist',
  154. 'id': playlist_id,
  155. 'display_id': display_id,
  156. 'title': title,
  157. 'entries': entries,
  158. }