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.

180 lines
6.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_str,
  8. compat_urllib_parse_unquote,
  9. compat_urlparse
  10. )
  11. from ..utils import (
  12. extract_attributes,
  13. int_or_none,
  14. strip_or_none,
  15. unified_timestamp,
  16. )
  17. class PolskieRadioIE(InfoExtractor):
  18. _VALID_URL = r'https?://(?:www\.)?polskieradio\.pl/\d+/\d+/Artykul/(?P<id>[0-9]+)'
  19. _TESTS = [{
  20. 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943,Prof-Andrzej-Nowak-o-historii-nie-da-sie-myslec-beznamietnie',
  21. 'info_dict': {
  22. 'id': '1587943',
  23. 'title': 'Prof. Andrzej Nowak: o historii nie da się myśleć beznamiętnie',
  24. 'description': 'md5:12f954edbf3120c5e7075e17bf9fc5c5',
  25. },
  26. 'playlist': [{
  27. 'md5': '2984ee6ce9046d91fc233bc1a864a09a',
  28. 'info_dict': {
  29. 'id': '1540576',
  30. 'ext': 'mp3',
  31. 'title': 'md5:d4623290d4ac983bf924061c75c23a0d',
  32. 'timestamp': 1456594200,
  33. 'upload_date': '20160227',
  34. 'duration': 2364,
  35. 'thumbnail': r're:^https?://static\.prsa\.pl/images/.*\.jpg$'
  36. },
  37. }],
  38. }, {
  39. 'url': 'http://www.polskieradio.pl/265/5217/Artykul/1635803,Euro-2016-nie-ma-miejsca-na-blad-Polacy-graja-ze-Szwajcaria-o-cwiercfinal',
  40. 'info_dict': {
  41. 'id': '1635803',
  42. 'title': 'Euro 2016: nie ma miejsca na błąd. Polacy grają ze Szwajcarią o ćwierćfinał',
  43. 'description': 'md5:01cb7d0cad58664095d72b51a1ebada2',
  44. },
  45. 'playlist_mincount': 12,
  46. }, {
  47. 'url': 'http://polskieradio.pl/9/305/Artykul/1632955,Bardzo-popularne-slowo-remis',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943',
  51. 'only_matching': True,
  52. }, {
  53. # with mp4 video
  54. 'url': 'http://www.polskieradio.pl/9/299/Artykul/1634903,Brexit-Leszek-Miller-swiat-sie-nie-zawali-Europa-bedzie-trwac-dalej',
  55. 'only_matching': True,
  56. }]
  57. def _real_extract(self, url):
  58. playlist_id = self._match_id(url)
  59. webpage = self._download_webpage(url, playlist_id)
  60. content = self._search_regex(
  61. r'(?s)<div[^>]+class="audio atarticle"[^>]*>(.+?)<script>',
  62. webpage, 'content')
  63. timestamp = unified_timestamp(self._html_search_regex(
  64. r'(?s)<span[^>]+id="datetime2"[^>]*>(.+?)</span>',
  65. webpage, 'timestamp', fatal=False))
  66. thumbnail_url = self._og_search_thumbnail(webpage)
  67. entries = []
  68. media_urls = set()
  69. for data_media in re.findall(r'<[^>]+data-media=({[^>]+})', content):
  70. media = self._parse_json(data_media, playlist_id, fatal=False)
  71. if not media.get('file') or not media.get('desc'):
  72. continue
  73. media_url = self._proto_relative_url(media['file'], 'http:')
  74. if media_url in media_urls:
  75. continue
  76. media_urls.add(media_url)
  77. entries.append({
  78. 'id': compat_str(media['id']),
  79. 'url': media_url,
  80. 'title': compat_urllib_parse_unquote(media['desc']),
  81. 'duration': int_or_none(media.get('length')),
  82. 'vcodec': 'none' if media.get('provider') == 'audio' else None,
  83. 'timestamp': timestamp,
  84. 'thumbnail': thumbnail_url
  85. })
  86. title = self._og_search_title(webpage).strip()
  87. description = strip_or_none(self._og_search_description(webpage))
  88. return self.playlist_result(entries, playlist_id, title, description)
  89. class PolskieRadioCategoryIE(InfoExtractor):
  90. _VALID_URL = r'https?://(?:www\.)?polskieradio\.pl/\d+(?:,[^/]+)?/(?P<id>\d+)'
  91. _TESTS = [{
  92. 'url': 'http://www.polskieradio.pl/7/5102,HISTORIA-ZYWA',
  93. 'info_dict': {
  94. 'id': '5102',
  95. 'title': 'HISTORIA ŻYWA',
  96. },
  97. 'playlist_mincount': 38,
  98. }, {
  99. 'url': 'http://www.polskieradio.pl/7/4807',
  100. 'info_dict': {
  101. 'id': '4807',
  102. 'title': 'Vademecum 1050. rocznicy Chrztu Polski'
  103. },
  104. 'playlist_mincount': 5
  105. }, {
  106. 'url': 'http://www.polskieradio.pl/7/129,Sygnaly-dnia?ref=source',
  107. 'only_matching': True
  108. }, {
  109. 'url': 'http://www.polskieradio.pl/37,RedakcjaKatolicka/4143,Kierunek-Krakow',
  110. 'info_dict': {
  111. 'id': '4143',
  112. 'title': 'Kierunek Kraków',
  113. },
  114. 'playlist_mincount': 61
  115. }, {
  116. 'url': 'http://www.polskieradio.pl/10,czworka/214,muzyka',
  117. 'info_dict': {
  118. 'id': '214',
  119. 'title': 'Muzyka',
  120. },
  121. 'playlist_mincount': 61
  122. }, {
  123. 'url': 'http://www.polskieradio.pl/7,Jedynka/5102,HISTORIA-ZYWA',
  124. 'only_matching': True,
  125. }, {
  126. 'url': 'http://www.polskieradio.pl/8,Dwojka/196,Publicystyka',
  127. 'only_matching': True,
  128. }]
  129. @classmethod
  130. def suitable(cls, url):
  131. return False if PolskieRadioIE.suitable(url) else super(PolskieRadioCategoryIE, cls).suitable(url)
  132. def _entries(self, url, page, category_id):
  133. content = page
  134. for page_num in itertools.count(2):
  135. for a_entry, entry_id in re.findall(
  136. r'(?s)<article[^>]+>.*?(<a[^>]+href=["\']/\d+/\d+/Artykul/(\d+)[^>]+>).*?</article>',
  137. content):
  138. entry = extract_attributes(a_entry)
  139. href = entry.get('href')
  140. if not href:
  141. continue
  142. yield self.url_result(
  143. compat_urlparse.urljoin(url, href), PolskieRadioIE.ie_key(),
  144. entry_id, entry.get('title'))
  145. mobj = re.search(
  146. r'<div[^>]+class=["\']next["\'][^>]*>\s*<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1',
  147. content)
  148. if not mobj:
  149. break
  150. next_url = compat_urlparse.urljoin(url, mobj.group('url'))
  151. content = self._download_webpage(
  152. next_url, category_id, 'Downloading page %s' % page_num)
  153. def _real_extract(self, url):
  154. category_id = self._match_id(url)
  155. webpage = self._download_webpage(url, category_id)
  156. title = self._html_search_regex(
  157. r'<title>([^<]+) - [^<]+ - [^<]+</title>',
  158. webpage, 'title', fatal=False)
  159. return self.playlist_result(
  160. self._entries(url, webpage, category_id),
  161. category_id, title)