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