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.

95 lines
3.4 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. },
  33. }],
  34. }, {
  35. 'url': 'http://www.polskieradio.pl/265/5217/Artykul/1635803,Euro-2016-nie-ma-miejsca-na-blad-Polacy-graja-ze-Szwajcaria-o-cwiercfinal',
  36. 'info_dict': {
  37. 'id': '1635803',
  38. 'title': 'Euro 2016: nie ma miejsca na błąd. Polacy grają ze Szwajcarią o ćwierćfinał',
  39. 'description': 'md5:01cb7d0cad58664095d72b51a1ebada2',
  40. },
  41. 'playlist_mincount': 12,
  42. }, {
  43. 'url': 'http://polskieradio.pl/9/305/Artykul/1632955,Bardzo-popularne-slowo-remis',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943',
  47. 'only_matching': True,
  48. }, {
  49. # with mp4 video
  50. 'url': 'http://www.polskieradio.pl/9/299/Artykul/1634903,Brexit-Leszek-Miller-swiat-sie-nie-zawali-Europa-bedzie-trwac-dalej',
  51. 'only_matching': True,
  52. }]
  53. def _real_extract(self, url):
  54. playlist_id = self._match_id(url)
  55. webpage = self._download_webpage(url, playlist_id)
  56. content = self._search_regex(
  57. r'(?s)<div[^>]+class="audio atarticle"[^>]*>(.+?)<script>',
  58. webpage, 'content')
  59. timestamp = unified_timestamp(self._html_search_regex(
  60. r'(?s)<span[^>]+id="datetime2"[^>]*>(.+?)</span>',
  61. webpage, 'timestamp', fatal=False))
  62. entries = []
  63. media_urls = set()
  64. for data_media in re.findall(r'<[^>]+data-media=({[^>]+})', content):
  65. media = self._parse_json(data_media, playlist_id, fatal=False)
  66. if not media.get('file') or not media.get('desc'):
  67. continue
  68. media_url = self._proto_relative_url(media['file'], 'http:')
  69. if media_url in media_urls:
  70. continue
  71. media_urls.add(media_url)
  72. entries.append({
  73. 'id': compat_str(media['id']),
  74. 'url': media_url,
  75. 'title': compat_urllib_parse_unquote(media['desc']),
  76. 'duration': int_or_none(media.get('length')),
  77. 'vcodec': 'none' if media.get('provider') == 'audio' else None,
  78. 'timestamp': timestamp,
  79. })
  80. title = self._og_search_title(webpage).strip()
  81. description = strip_or_none(self._og_search_description(webpage))
  82. return self.playlist_result(entries, playlist_id, title, description)