1 from __future__
import annotations
6 from .common
import InfoExtractor
7 from ..utils
import ExtractorError
, format_field
, int_or_none
, parse_iso8601
8 from ..utils
.traversal
import traverse_obj
12 return functools
.partial(format_field
, template
=url
, default
=None)
15 class TelewebionIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?telewebion\.com/episode/(?P<id>(?:0x[a-fA-F\d]+|\d+))'
18 'url': 'http://www.telewebion.com/episode/0x1b3139c/',
22 'title': 'قرعهکشی لیگ قهرمانان اروپا',
24 'series_id': '0x1b2505c',
26 'channel_id': '0x1b1a761',
27 'channel_url': 'https://telewebion.com/live/tv3',
28 'timestamp': 1425522414,
29 'upload_date': '20150305',
30 'release_timestamp': 1425517020,
31 'release_date': '20150305',
34 'tags': ['ورزشی', 'لیگ اروپا', 'اروپا'],
35 'thumbnail': 'https://static.telewebion.com/episodeImages/YjFhM2MxMDBkMDNiZTU0MjE5YjQ3ZDY0Mjk1ZDE0ZmUwZWU3OTE3OWRmMDAyODNhNzNkNjdmMWMzMWIyM2NmMA/default',
37 'skip_download': 'm3u8',
39 'url': 'https://telewebion.com/episode/162175536',
43 'title': 'کارما یعنی این !',
45 'series_id': '0x29a7426',
47 'channel_id': '0x1b1a719',
48 'channel_url': 'https://telewebion.com/live/tv2',
49 'timestamp': 1699979968,
50 'upload_date': '20231114',
51 'release_timestamp': 1699991638,
52 'release_date': '20231114',
55 'tags': ['کلیپ های منتخب', ' کلیپ طنز ', ' کلیپ سیاست ', 'پاورقی', 'ویژه فلسطین'],
56 'thumbnail': 'https://static.telewebion.com/episodeImages/871e9455-7567-49a5-9648-34c22c197f5f/default',
58 'skip_download': 'm3u8',
61 def _call_graphql_api(
62 self
, operation
, video_id
, query
,
63 variables
: dict[str, tuple[str, str]] |
None = None,
64 note
='Downloading GraphQL JSON metadata',
68 parameters
= ', '.join(f
'${name}: {type_}' for name
, (type_
, _
) in variables
.items())
69 parameters
= f
'({parameters})'
71 result
= self
._download
_json
('https://graph.telewebion.com/graphql', video_id
, note
, data
=json
.dumps({
72 'operationName': operation
,
73 'query': f
'query {operation}{parameters} @cacheControl(maxAge: 60) {{{query}\n}}\n',
74 'variables': {name: value for name, (_, value) in (variables or {}
).items()}
75 }, separators
=(',', ':')).encode(), headers
={
76 'Content-Type': 'application/json',
77 'Accept': 'application/json',
79 if not result
or traverse_obj(result
, 'errors'):
80 message
= ', '.join(traverse_obj(result
, ('errors', ..., 'message', {str}
)))
81 raise ExtractorError(message
or 'Unknown GraphQL API error')
85 def _real_extract(self
, url
):
86 video_id
= self
._match
_id
(url
)
87 if not video_id
.startswith('0x'):
88 video_id
= hex(int(video_id
))
90 episode_data
= self
._call
_graphql
_api
('getEpisodeDetail', video_id
, textwrap
.dedent('''
91 queryEpisode(filter: {EpisodeID: $EpisodeId}, first: 1) {
111 '''), {'EpisodeId': ('[ID!]', video_id)}
)
113 info_dict
= traverse_obj(episode_data
, ('queryEpisode', 0, {
114 'title': ('title', {str}
),
115 'view_count': ('view_count', {int_or_none}
),
116 'duration': ('duration', {int_or_none}
),
117 'tags': ('tags', ..., 'name', {str}
),
118 'release_timestamp': ('started_at', {parse_iso8601}
),
119 'timestamp': ('created_at', {parse_iso8601}
),
120 'series': ('program', 'title', {str}
),
121 'series_id': ('program', 'ProgramID', {str}
),
122 'channel': ('channel', 'name', {str}
),
123 'channel_id': ('channel', 'ChannelID', {str}
),
124 'channel_url': ('channel', 'descriptor', {_fmt_url('https://telewebion.com/live/%s')}
),
125 'thumbnail': ('image', {_fmt_url('https://static.telewebion.com/episodeImages/%s/default')}
),
127 'channel', 'descriptor', {str}
,
128 {_fmt_url(f'https://cdna.telewebion.com/%s/episode/{video_id}
/playlist
.m3u8
')},
129 {functools.partial(self._extract_m3u8_formats, video_id=video_id, ext='mp4', m3u8_id='hls')}),
131 info_dict['id'] = video_id