agora.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import functools
  2. import uuid
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. OnDemandPagedList,
  7. int_or_none,
  8. month_by_name,
  9. parse_duration,
  10. try_call,
  11. )
  12. class WyborczaVideoIE(InfoExtractor):
  13. # this id is not an article id, it has to be extracted from the article
  14. _VALID_URL = r'(?:wyborcza:video:|https?://wyborcza\.pl/(?:api-)?video/)(?P<id>\d+)'
  15. IE_NAME = 'wyborcza:video'
  16. _TESTS = [{
  17. 'url': 'wyborcza:video:26207634',
  18. 'info_dict': {
  19. 'id': '26207634',
  20. 'ext': 'mp4',
  21. 'title': '- Polska w 2020 r. jest innym państwem niż w 2015 r. Nie zmieniła się konstytucja, ale jest to już inny ustrój - mówi Adam Bodnar',
  22. 'description': ' ',
  23. 'uploader': 'Dorota Roman',
  24. 'duration': 2474,
  25. 'thumbnail': r're:https://.+\.jpg',
  26. },
  27. }, {
  28. 'url': 'https://wyborcza.pl/video/26207634',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'https://wyborcza.pl/api-video/26207634',
  32. 'only_matching': True,
  33. }]
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. meta = self._download_json(f'https://wyborcza.pl/api-video/{video_id}', video_id)
  37. formats = []
  38. base_url = meta['redirector'].replace('http://', 'https://') + meta['basePath']
  39. for quality in ('standard', 'high'):
  40. if not meta['files'].get(quality):
  41. continue
  42. formats.append({
  43. 'url': base_url + meta['files'][quality],
  44. 'height': int_or_none(
  45. self._search_regex(
  46. r'p(\d+)[a-z]+\.mp4$', meta['files'][quality],
  47. 'mp4 video height', default=None)),
  48. 'format_id': quality,
  49. })
  50. if meta['files'].get('dash'):
  51. formats.extend(self._extract_mpd_formats(base_url + meta['files']['dash'], video_id))
  52. return {
  53. 'id': video_id,
  54. 'formats': formats,
  55. 'title': meta.get('title'),
  56. 'description': meta.get('lead'),
  57. 'uploader': meta.get('signature'),
  58. 'thumbnail': meta.get('imageUrl'),
  59. 'duration': meta.get('duration'),
  60. }
  61. class WyborczaPodcastIE(InfoExtractor):
  62. _VALID_URL = r'''(?x)
  63. https?://(?:www\.)?(?:
  64. wyborcza\.pl/podcast(?:/0,172673\.html)?|
  65. wysokieobcasy\.pl/wysokie-obcasy/0,176631\.html
  66. )(?:\?(?:[^&#]+?&)*podcast=(?P<id>\d+))?
  67. '''
  68. _TESTS = [{
  69. 'url': 'https://wyborcza.pl/podcast/0,172673.html?podcast=100720#S.main_topic-K.C-B.6-L.1.podcast',
  70. 'info_dict': {
  71. 'id': '100720',
  72. 'ext': 'mp3',
  73. 'title': 'Cyfrodziewczyny. Kim były pionierki polskiej informatyki ',
  74. 'uploader': 'Michał Nogaś ',
  75. 'upload_date': '20210117',
  76. 'description': 'md5:49f0a06ffc4c1931210d3ab1416a651d',
  77. 'duration': 3684.0,
  78. 'thumbnail': r're:https://.+\.jpg',
  79. },
  80. }, {
  81. 'url': 'https://www.wysokieobcasy.pl/wysokie-obcasy/0,176631.html?podcast=100673',
  82. 'info_dict': {
  83. 'id': '100673',
  84. 'ext': 'mp3',
  85. 'title': 'Czym jest ubóstwo menstruacyjne i dlaczego dotyczy każdej i każdego z nas?',
  86. 'uploader': 'Agnieszka Urazińska ',
  87. 'upload_date': '20210115',
  88. 'description': 'md5:c161dc035f8dbb60077011fc41274899',
  89. 'duration': 1803.0,
  90. 'thumbnail': r're:https://.+\.jpg',
  91. },
  92. }, {
  93. 'url': 'https://wyborcza.pl/podcast',
  94. 'info_dict': {
  95. 'id': '334',
  96. 'title': 'Gościnnie: Wyborcza, 8:10',
  97. 'series': 'Gościnnie: Wyborcza, 8:10',
  98. },
  99. 'playlist_mincount': 370,
  100. }, {
  101. 'url': 'https://www.wysokieobcasy.pl/wysokie-obcasy/0,176631.html',
  102. 'info_dict': {
  103. 'id': '395',
  104. 'title': 'Gościnnie: Wysokie Obcasy',
  105. 'series': 'Gościnnie: Wysokie Obcasy',
  106. },
  107. 'playlist_mincount': 12,
  108. }]
  109. def _real_extract(self, url):
  110. podcast_id = self._match_id(url)
  111. if not podcast_id: # playlist
  112. podcast_id = '395' if 'wysokieobcasy.pl/' in url else '334'
  113. return self.url_result(TokFMAuditionIE._create_url(podcast_id), TokFMAuditionIE, podcast_id)
  114. meta = self._download_json('https://wyborcza.pl/api/podcast', podcast_id,
  115. query={'guid': podcast_id, 'type': 'wo' if 'wysokieobcasy.pl/' in url else None})
  116. day, month, year = self._search_regex(r'^(\d\d?) (\w+) (\d{4})$', meta.get('publishedDate'),
  117. 'upload date', group=(1, 2, 3), default=(None, None, None))
  118. return {
  119. 'id': podcast_id,
  120. 'url': meta['url'],
  121. 'title': meta.get('title'),
  122. 'description': meta.get('description'),
  123. 'thumbnail': meta.get('imageUrl'),
  124. 'duration': parse_duration(meta.get('duration')),
  125. 'uploader': meta.get('author'),
  126. 'upload_date': try_call(lambda: f'{year}{month_by_name(month, lang="pl"):0>2}{day:0>2}'),
  127. }
  128. class TokFMPodcastIE(InfoExtractor):
  129. _VALID_URL = r'(?:https?://audycje\.tokfm\.pl/podcast/|tokfm:podcast:)(?P<id>\d+),?'
  130. IE_NAME = 'tokfm:podcast'
  131. _TESTS = [{
  132. 'url': 'https://audycje.tokfm.pl/podcast/91275,-Systemowy-rasizm-Czy-zamieszki-w-USA-po-morderstwie-w-Minneapolis-doprowadza-do-zmian-w-sluzbach-panstwowych',
  133. 'info_dict': {
  134. 'id': '91275',
  135. 'ext': 'aac',
  136. 'title': 'md5:a9b15488009065556900169fb8061cce',
  137. 'episode': 'md5:a9b15488009065556900169fb8061cce',
  138. 'series': 'Analizy',
  139. },
  140. }]
  141. def _real_extract(self, url):
  142. media_id = self._match_id(url)
  143. # in case it breaks see this but it returns a lot of useless data
  144. # https://api.podcast.radioagora.pl/api4/getPodcasts?podcast_id=100091&with_guests=true&with_leaders_for_mobile=true
  145. metadata = self._download_json(
  146. f'https://audycje.tokfm.pl/getp/3{media_id}', media_id, 'Downloading podcast metadata')
  147. if not metadata:
  148. raise ExtractorError('No such podcast', expected=True)
  149. metadata = metadata[0]
  150. formats = []
  151. for ext in ('aac', 'mp3'):
  152. url_data = self._download_json(
  153. f'https://api.podcast.radioagora.pl/api4/getSongUrl?podcast_id={media_id}&device_id={uuid.uuid4()}&ppre=false&audio={ext}',
  154. media_id, f'Downloading podcast {ext} URL')
  155. # prevents inserting the mp3 (default) multiple times
  156. if 'link_ssl' in url_data and f'.{ext}' in url_data['link_ssl']:
  157. formats.append({
  158. 'url': url_data['link_ssl'],
  159. 'ext': ext,
  160. 'vcodec': 'none',
  161. 'acodec': ext,
  162. })
  163. return {
  164. 'id': media_id,
  165. 'formats': formats,
  166. 'title': metadata.get('podcast_name'),
  167. 'series': metadata.get('series_name'),
  168. 'episode': metadata.get('podcast_name'),
  169. }
  170. class TokFMAuditionIE(InfoExtractor):
  171. _VALID_URL = r'(?:https?://audycje\.tokfm\.pl/audycja/|tokfm:audition:)(?P<id>\d+),?'
  172. IE_NAME = 'tokfm:audition'
  173. _TESTS = [{
  174. 'url': 'https://audycje.tokfm.pl/audycja/218,Analizy',
  175. 'info_dict': {
  176. 'id': '218',
  177. 'title': 'Analizy',
  178. 'series': 'Analizy',
  179. },
  180. 'playlist_count': 1635,
  181. }]
  182. _PAGE_SIZE = 30
  183. _HEADERS = {
  184. 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Redmi 3S Build/PQ3A.190801.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.101 Mobile Safari/537.36',
  185. }
  186. @staticmethod
  187. def _create_url(video_id):
  188. return f'https://audycje.tokfm.pl/audycja/{video_id}'
  189. def _real_extract(self, url):
  190. audition_id = self._match_id(url)
  191. data = self._download_json(
  192. f'https://api.podcast.radioagora.pl/api4/getSeries?series_id={audition_id}',
  193. audition_id, 'Downloading audition metadata', headers=self._HEADERS)
  194. if not data:
  195. raise ExtractorError('No such audition', expected=True)
  196. data = data[0]
  197. entries = OnDemandPagedList(functools.partial(
  198. self._fetch_page, audition_id, data), self._PAGE_SIZE)
  199. return {
  200. '_type': 'playlist',
  201. 'id': audition_id,
  202. 'title': data.get('series_name'),
  203. 'series': data.get('series_name'),
  204. 'entries': entries,
  205. }
  206. def _fetch_page(self, audition_id, data, page):
  207. for retry in self.RetryManager():
  208. podcast_page = self._download_json(
  209. f'https://api.podcast.radioagora.pl/api4/getPodcasts?series_id={audition_id}&limit=30&offset={page}&with_guests=true&with_leaders_for_mobile=true',
  210. audition_id, f'Downloading podcast list page {page + 1}', headers=self._HEADERS)
  211. if not podcast_page:
  212. retry.error = ExtractorError('Agora returned empty page', expected=True)
  213. for podcast in podcast_page:
  214. yield {
  215. '_type': 'url_transparent',
  216. 'url': podcast['podcast_sharing_url'],
  217. 'ie_key': TokFMPodcastIE.ie_key(),
  218. 'title': podcast.get('podcast_name'),
  219. 'episode': podcast.get('podcast_name'),
  220. 'description': podcast.get('podcast_description'),
  221. 'timestamp': int_or_none(podcast.get('podcast_timestamp')),
  222. 'series': data.get('series_name'),
  223. }