[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / ilpost.py
blobda203cf5ff23c3f031b3272265d4633965bbbd75
2 from .common import InfoExtractor
3 from ..utils import (
4 ExtractorError,
5 float_or_none,
6 int_or_none,
7 url_or_none,
8 urlencode_postdata,
10 from ..utils.traversal import traverse_obj
13 class IlPostIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?#]+)'
15 _TESTS = [{
16 'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
17 'md5': '43649f002d85e1c2f319bb478d479c40',
18 'info_dict': {
19 'id': '2972047',
20 'ext': 'mp3',
21 'display_id': '1-avis-akvasas-ka',
22 'title': '1. Avis akvasas ka',
23 'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
24 'timestamp': 1703835014,
25 'upload_date': '20231229',
26 'duration': 2495.0,
27 'availability': 'public',
28 'series_id': '235598',
29 'description': '',
33 def _real_extract(self, url):
34 display_id = self._match_id(url)
35 webpage = self._download_webpage(url, display_id)
37 endpoint_metadata = self._search_json(
38 r'var\s+ilpostpodcast\s*=', webpage, 'metadata', display_id)
39 episode_id = endpoint_metadata['post_id']
40 podcast_id = endpoint_metadata['podcast_id']
41 podcast_metadata = self._download_json(
42 endpoint_metadata['ajax_url'], display_id, data=urlencode_postdata({
43 'action': 'checkpodcast',
44 'cookie': endpoint_metadata['cookie'],
45 'post_id': episode_id,
46 'podcast_id': podcast_id,
47 }))
49 episode = traverse_obj(podcast_metadata, (
50 'data', 'postcastList', lambda _, v: str(v['id']) == episode_id, {dict}), get_all=False)
51 if not episode:
52 raise ExtractorError('Episode could not be extracted')
54 return {
55 'id': episode_id,
56 'display_id': display_id,
57 'series_id': podcast_id,
58 'vcodec': 'none',
59 **traverse_obj(episode, {
60 'title': ('title', {str}),
61 'description': ('description', {str}),
62 'url': ('podcast_raw_url', {url_or_none}),
63 'thumbnail': ('image', {url_or_none}),
64 'timestamp': ('timestamp', {int_or_none}),
65 'duration': ('milliseconds', {float_or_none(scale=1000)}),
66 'availability': ('free', {lambda v: 'public' if v else 'subscriber_only'}),
67 }),