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