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.

99 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import (
  10. int_or_none,
  11. strip_or_none,
  12. unified_timestamp,
  13. )
  14. class PolskieRadioIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?polskieradio\.pl/\d+/\d+/Artykul/(?P<id>[0-9]+)'
  16. _TESTS = [{
  17. 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943,Prof-Andrzej-Nowak-o-historii-nie-da-sie-myslec-beznamietnie',
  18. 'info_dict': {
  19. 'id': '1587943',
  20. 'title': 'Prof. Andrzej Nowak: o historii nie da się myśleć beznamiętnie',
  21. 'description': 'md5:12f954edbf3120c5e7075e17bf9fc5c5',
  22. },
  23. 'playlist': [{
  24. 'md5': '2984ee6ce9046d91fc233bc1a864a09a',
  25. 'info_dict': {
  26. 'id': '1540576',
  27. 'ext': 'mp3',
  28. 'title': 'md5:d4623290d4ac983bf924061c75c23a0d',
  29. 'timestamp': 1456594200,
  30. 'upload_date': '20160227',
  31. 'duration': 2364,
  32. 'thumbnail': 're:^https?://static\.prsa\.pl/images/.*\.jpg$'
  33. },
  34. }],
  35. }, {
  36. 'url': 'http://www.polskieradio.pl/265/5217/Artykul/1635803,Euro-2016-nie-ma-miejsca-na-blad-Polacy-graja-ze-Szwajcaria-o-cwiercfinal',
  37. 'info_dict': {
  38. 'id': '1635803',
  39. 'title': 'Euro 2016: nie ma miejsca na błąd. Polacy grają ze Szwajcarią o ćwierćfinał',
  40. 'description': 'md5:01cb7d0cad58664095d72b51a1ebada2',
  41. },
  42. 'playlist_mincount': 12,
  43. }, {
  44. 'url': 'http://polskieradio.pl/9/305/Artykul/1632955,Bardzo-popularne-slowo-remis',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943',
  48. 'only_matching': True,
  49. }, {
  50. # with mp4 video
  51. 'url': 'http://www.polskieradio.pl/9/299/Artykul/1634903,Brexit-Leszek-Miller-swiat-sie-nie-zawali-Europa-bedzie-trwac-dalej',
  52. 'only_matching': True,
  53. }]
  54. def _real_extract(self, url):
  55. playlist_id = self._match_id(url)
  56. webpage = self._download_webpage(url, playlist_id)
  57. content = self._search_regex(
  58. r'(?s)<div[^>]+class="audio atarticle"[^>]*>(.+?)<script>',
  59. webpage, 'content')
  60. timestamp = unified_timestamp(self._html_search_regex(
  61. r'(?s)<span[^>]+id="datetime2"[^>]*>(.+?)</span>',
  62. webpage, 'timestamp', fatal=False))
  63. thumbnail_url = self._og_search_thumbnail(webpage)
  64. entries = []
  65. media_urls = set()
  66. for data_media in re.findall(r'<[^>]+data-media=({[^>]+})', content):
  67. media = self._parse_json(data_media, playlist_id, fatal=False)
  68. if not media.get('file') or not media.get('desc'):
  69. continue
  70. media_url = self._proto_relative_url(media['file'], 'http:')
  71. if media_url in media_urls:
  72. continue
  73. media_urls.add(media_url)
  74. entries.append({
  75. 'id': compat_str(media['id']),
  76. 'url': media_url,
  77. 'title': compat_urllib_parse_unquote(media['desc']),
  78. 'duration': int_or_none(media.get('length')),
  79. 'vcodec': 'none' if media.get('provider') == 'audio' else None,
  80. 'timestamp': timestamp,
  81. 'thumbnail': thumbnail_url
  82. })
  83. title = self._og_search_title(webpage).strip()
  84. description = strip_or_none(self._og_search_description(webpage))
  85. return self.playlist_result(entries, playlist_id, title, description)