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.

139 lines
4.7 KiB

10 years ago
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.pl'
  7. _VALID_URL = r'https?://(?:vod|www)\.tvp\.pl/.*/(?P<id>\d+)$'
  8. _TESTS = [{
  9. 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem/wideo/odc-2/4278035',
  10. 'md5': 'cdd98303338b8a7f7abab5cd14092bf2',
  11. 'info_dict': {
  12. 'id': '4278035',
  13. 'ext': 'wmv',
  14. 'title': 'Ogniem i mieczem, odc. 2',
  15. },
  16. }, {
  17. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/czas-honoru/sezon-1-1-13/i-seria-odc-13/194536',
  18. 'md5': '8aa518c15e5cc32dfe8db400dc921fbb',
  19. 'info_dict': {
  20. 'id': '194536',
  21. 'ext': 'mp4',
  22. 'title': 'Czas honoru, I seria – odc. 13',
  23. },
  24. }, {
  25. 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
  26. 'md5': 'c3b15ed1af288131115ff17a17c19dda',
  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. },
  32. }, {
  33. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  34. 'md5': 'c3b15ed1af288131115ff17a17c19dda',
  35. 'info_dict': {
  36. 'id': '17834272',
  37. 'ext': 'mp4',
  38. 'title': 'Na sygnale, odc. 39',
  39. },
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(
  44. 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
  45. title = self._search_regex(
  46. r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
  47. webpage, 'title', group='title')
  48. series_title = self._search_regex(
  49. r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
  50. webpage, 'series', group='series', default=None)
  51. if series_title:
  52. title = '%s, %s' % (series_title, title)
  53. thumbnail = self._search_regex(
  54. r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
  55. video_url = self._search_regex(
  56. r'0:{src:([\'"])(?P<url>.*?)\1', webpage, 'formats', group='url', default=None)
  57. if not video_url:
  58. video_url = self._download_json(
  59. 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
  60. video_id)['video_url']
  61. ext = video_url.rsplit('.', 1)[-1]
  62. if ext != 'ism/manifest':
  63. if '/' in ext:
  64. ext = 'mp4'
  65. formats = [{
  66. 'format_id': 'direct',
  67. 'url': video_url,
  68. 'ext': ext,
  69. }]
  70. else:
  71. m3u8_url = re.sub('([^/]*)\.ism/manifest', r'\1.ism/\1.m3u8', video_url)
  72. formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
  73. self._sort_formats(formats)
  74. return {
  75. 'id': video_id,
  76. 'title': title,
  77. 'thumbnail': thumbnail,
  78. 'formats': formats,
  79. }
  80. class TvpSeriesIE(InfoExtractor):
  81. IE_NAME = 'tvp.pl:Series'
  82. _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
  83. _TESTS = [{
  84. 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
  85. 'info_dict': {
  86. 'title': 'Ogniem i mieczem',
  87. 'id': '4278026',
  88. },
  89. 'playlist_count': 4,
  90. }, {
  91. 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
  92. 'info_dict': {
  93. 'title': 'Boso przez świat',
  94. 'id': '9329207',
  95. },
  96. 'playlist_count': 86,
  97. }]
  98. def _real_extract(self, url):
  99. display_id = self._match_id(url)
  100. webpage = self._download_webpage(url, display_id, tries=5)
  101. title = self._html_search_regex(
  102. r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
  103. playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
  104. playlist = self._download_webpage(
  105. 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
  106. 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
  107. note='Downloading playlist')
  108. videos_paths = re.findall(
  109. '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
  110. entries = [
  111. self.url_result('http://vod.tvp.pl%s' % v_path, ie=TvpIE.ie_key())
  112. for v_path in videos_paths]
  113. return {
  114. '_type': 'playlist',
  115. 'id': playlist_id,
  116. 'display_id': display_id,
  117. 'title': title,
  118. 'entries': entries,
  119. }