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.

142 lines
4.9 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. class TVPIE(InfoExtractor):
  6. IE_NAME = 'tvp'
  7. IE_DESC = 'Telewizja Polska'
  8. _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)'
  9. _TESTS = [{
  10. 'url': 'http://vod.tvp.pl/194536/i-seria-odc-13',
  11. 'md5': '8aa518c15e5cc32dfe8db400dc921fbb',
  12. 'info_dict': {
  13. 'id': '194536',
  14. 'ext': 'mp4',
  15. 'title': 'Czas honoru, I seria – odc. 13',
  16. },
  17. }, {
  18. 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
  19. 'md5': 'c3b15ed1af288131115ff17a17c19dda',
  20. 'info_dict': {
  21. 'id': '17916176',
  22. 'ext': 'mp4',
  23. 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
  24. },
  25. }, {
  26. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. webpage = self._download_webpage(
  47. 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
  48. title = self._search_regex(
  49. r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
  50. webpage, 'title', group='title')
  51. series_title = self._search_regex(
  52. r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
  53. webpage, 'series', group='series', default=None)
  54. if series_title:
  55. title = '%s, %s' % (series_title, title)
  56. thumbnail = self._search_regex(
  57. r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
  58. video_url = self._search_regex(
  59. r'0:{src:([\'"])(?P<url>.*?)\1', webpage, 'formats', group='url', default=None)
  60. if not video_url:
  61. video_url = self._download_json(
  62. 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
  63. video_id)['video_url']
  64. ext = video_url.rsplit('.', 1)[-1]
  65. if ext != 'ism/manifest':
  66. if '/' in ext:
  67. ext = 'mp4'
  68. formats = [{
  69. 'format_id': 'direct',
  70. 'url': video_url,
  71. 'ext': ext,
  72. }]
  73. else:
  74. m3u8_url = re.sub('([^/]*)\.ism/manifest', r'\1.ism/\1.m3u8', video_url)
  75. formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
  76. self._sort_formats(formats)
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'thumbnail': thumbnail,
  81. 'formats': formats,
  82. }
  83. class TVPSeriesIE(InfoExtractor):
  84. IE_NAME = 'tvp:series'
  85. _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
  86. _TESTS = [{
  87. 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
  88. 'info_dict': {
  89. 'title': 'Ogniem i mieczem',
  90. 'id': '4278026',
  91. },
  92. 'playlist_count': 4,
  93. }, {
  94. 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
  95. 'info_dict': {
  96. 'title': 'Boso przez świat',
  97. 'id': '9329207',
  98. },
  99. 'playlist_count': 86,
  100. }]
  101. def _real_extract(self, url):
  102. display_id = self._match_id(url)
  103. webpage = self._download_webpage(url, display_id, tries=5)
  104. title = self._html_search_regex(
  105. r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
  106. playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
  107. playlist = self._download_webpage(
  108. 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
  109. 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
  110. note='Downloading playlist')
  111. videos_paths = re.findall(
  112. '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
  113. entries = [
  114. self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key())
  115. for v_path in videos_paths]
  116. return {
  117. '_type': 'playlist',
  118. 'id': playlist_id,
  119. 'display_id': display_id,
  120. 'title': title,
  121. 'entries': entries,
  122. }