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