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.

227 lines
8.4 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. 'description': 'md5:76649d2014f65c99477be17f23a4dead',
  23. },
  24. }, {
  25. 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
  26. 'md5': 'b0005b542e5b4de643a9690326ab1257',
  27. 'info_dict': {
  28. 'id': '17916176',
  29. 'ext': 'mp4',
  30. 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  31. 'description': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  32. },
  33. }, {
  34. # page id is not the same as video id(#7799)
  35. 'url': 'http://vod.tvp.pl/22704887/08122015-1500',
  36. 'md5': 'cf6a4705dfd1489aef8deb168d6ba742',
  37. 'info_dict': {
  38. 'id': '22680786',
  39. 'ext': 'mp4',
  40. 'title': 'Wiadomości, 08.12.2015, 15:00',
  41. },
  42. }, {
  43. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
  56. 'only_matching': True,
  57. }, {
  58. 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
  59. 'only_matching': True,
  60. }]
  61. def _real_extract(self, url):
  62. page_id = self._match_id(url)
  63. webpage = self._download_webpage(url, page_id)
  64. video_id = self._search_regex([
  65. r'<iframe[^>]+src="[^"]*?object_id=(\d+)',
  66. r"object_id\s*:\s*'(\d+)'",
  67. r'data-video-id="(\d+)"'], webpage, 'video id', default=page_id)
  68. return {
  69. '_type': 'url_transparent',
  70. 'url': 'tvp:' + video_id,
  71. 'description': self._og_search_description(webpage, default=None),
  72. 'thumbnail': self._og_search_thumbnail(webpage),
  73. 'ie_key': 'TVPEmbed',
  74. }
  75. class TVPEmbedIE(InfoExtractor):
  76. IE_NAME = 'tvp:embed'
  77. IE_DESC = 'Telewizja Polska'
  78. _VALID_URL = r'(?:tvp:|https?://[^/]+\.tvp\.(?:pl|info)/sess/tvplayer\.php\?.*?object_id=)(?P<id>\d+)'
  79. _TESTS = [{
  80. 'url': 'http://www.tvp.pl/sess/tvplayer.php?object_id=22670268',
  81. 'md5': '8c9cd59d16edabf39331f93bf8a766c7',
  82. 'info_dict': {
  83. 'id': '22670268',
  84. 'ext': 'mp4',
  85. 'title': 'Panorama, 07.12.2015, 15:40',
  86. },
  87. }, {
  88. 'url': 'tvp:22670268',
  89. 'only_matching': True,
  90. }]
  91. def _real_extract(self, url):
  92. video_id = self._match_id(url)
  93. webpage = self._download_webpage(
  94. 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
  95. error_massage = get_element_by_attribute('class', 'msg error', webpage)
  96. if error_massage:
  97. raise ExtractorError('%s said: %s' % (
  98. self.IE_NAME, clean_html(error_massage)), expected=True)
  99. title = self._search_regex(
  100. r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
  101. webpage, 'title', group='title')
  102. series_title = self._search_regex(
  103. r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
  104. webpage, 'series', group='series', default=None)
  105. if series_title:
  106. title = '%s, %s' % (series_title, title)
  107. thumbnail = self._search_regex(
  108. r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
  109. video_url = self._search_regex(
  110. r'0:{src:([\'"])(?P<url>.*?)\1', webpage,
  111. 'formats', group='url', default=None)
  112. if not video_url or 'material_niedostepny.mp4' in video_url:
  113. video_url = self._download_json(
  114. 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
  115. video_id)['video_url']
  116. formats = []
  117. video_url_base = self._search_regex(
  118. r'(https?://.+?/video)(?:\.(?:ism|f4m|m3u8)|-\d+\.mp4)',
  119. video_url, 'video base url', default=None)
  120. if video_url_base:
  121. # TODO: <Group> found instead of <AdaptationSet> in MPD manifest.
  122. # It's not mentioned in MPEG-DASH standard. Figure that out.
  123. # formats.extend(self._extract_mpd_formats(
  124. # video_url_base + '.ism/video.mpd',
  125. # video_id, mpd_id='dash', fatal=False))
  126. formats.extend(self._extract_ism_formats(
  127. video_url_base + '.ism/Manifest',
  128. video_id, 'mss', fatal=False))
  129. formats.extend(self._extract_f4m_formats(
  130. video_url_base + '.ism/video.f4m',
  131. video_id, f4m_id='hds', fatal=False))
  132. m3u8_formats = self._extract_m3u8_formats(
  133. video_url_base + '.ism/video.m3u8', video_id,
  134. 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
  135. self._sort_formats(m3u8_formats)
  136. m3u8_formats = list(filter(
  137. lambda f: f.get('vcodec') != 'none' and f.get('resolution') != 'multiple',
  138. m3u8_formats))
  139. formats.extend(m3u8_formats)
  140. for i, m3u8_format in enumerate(m3u8_formats, 2):
  141. http_url = '%s-%d.mp4' % (video_url_base, i)
  142. if self._is_valid_url(http_url, video_id):
  143. f = m3u8_format.copy()
  144. f.update({
  145. 'url': http_url,
  146. 'format_id': f['format_id'].replace('hls', 'http'),
  147. 'protocol': 'http',
  148. })
  149. formats.append(f)
  150. else:
  151. formats = [{
  152. 'format_id': 'direct',
  153. 'url': video_url,
  154. 'ext': determine_ext(video_url, 'mp4'),
  155. }]
  156. self._sort_formats(formats)
  157. return {
  158. 'id': video_id,
  159. 'title': title,
  160. 'thumbnail': thumbnail,
  161. 'formats': formats,
  162. }
  163. class TVPSeriesIE(InfoExtractor):
  164. IE_NAME = 'tvp:series'
  165. _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
  166. _TESTS = [{
  167. 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
  168. 'info_dict': {
  169. 'title': 'Ogniem i mieczem',
  170. 'id': '4278026',
  171. },
  172. 'playlist_count': 4,
  173. }, {
  174. 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
  175. 'info_dict': {
  176. 'title': 'Boso przez świat',
  177. 'id': '9329207',
  178. },
  179. 'playlist_count': 86,
  180. }]
  181. def _real_extract(self, url):
  182. display_id = self._match_id(url)
  183. webpage = self._download_webpage(url, display_id, tries=5)
  184. title = self._html_search_regex(
  185. r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
  186. playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
  187. playlist = self._download_webpage(
  188. 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
  189. 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
  190. note='Downloading playlist')
  191. videos_paths = re.findall(
  192. '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
  193. entries = [
  194. self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key())
  195. for v_path in videos_paths]
  196. return {
  197. '_type': 'playlist',
  198. 'id': playlist_id,
  199. 'display_id': display_id,
  200. 'title': title,
  201. 'entries': entries,
  202. }