From 0cbed930c8f5b14500557b689c754b9ad0c0436a Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Tue, 30 Nov 2021 17:11:07 +0100 Subject: [PATCH] [trovo] Fix extractor (#1818) Closes #1782 Authored by: nyuszika7h --- yt_dlp/extractor/trovo.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/yt_dlp/extractor/trovo.py b/yt_dlp/extractor/trovo.py index a0f0cc31c..9d49840a5 100644 --- a/yt_dlp/extractor/trovo.py +++ b/yt_dlp/extractor/trovo.py @@ -17,6 +17,11 @@ class TrovoBaseIE(InfoExtractor): _VALID_URL_BASE = r'https?://(?:www\.)?trovo\.live/' _HEADERS = {'Origin': 'https://trovo.live'} + def _call_api(self, video_id, query=None, data=None): + return self._download_json( + 'https://gql.trovo.live/', video_id, query=query, data=data, + headers={'Accept': 'application/json'}) + def _extract_streamer_info(self, data): streamer_info = data.get('streamerInfo') or {} username = streamer_info.get('userName') @@ -32,9 +37,8 @@ class TrovoIE(TrovoBaseIE): def _real_extract(self, url): username = self._match_id(url) - live_info = self._download_json( - 'https://gql.trovo.live/', username, query={ - 'query': '''{ + live_info = self._call_api(username, query={ + 'query': '''{ getLiveInfo(params: {userName: "%s"}) { isLive programInfo { @@ -53,7 +57,7 @@ class TrovoIE(TrovoBaseIE): } } }''' % username, - })['data']['getLiveInfo'] + })['data']['getLiveInfo'] if live_info.get('isLive') == 0: raise ExtractorError('%s is offline' % username, expected=True) program_info = live_info['programInfo'] @@ -111,15 +115,14 @@ class TrovoVodIE(TrovoBaseIE): def _real_extract(self, url): vid = self._match_id(url) - resp = self._download_json( - 'https://gql.trovo.live/', vid, data=json.dumps([{ - 'query': '''{ + resp = self._call_api(vid, data=json.dumps([{ + 'query': '''{ batchGetVodDetailInfo(params: {vids: ["%s"]}) { VodDetailInfos } }''' % vid, - }, { - 'query': '''{ + }, { + 'query': '''{ getCommentList(params: {appInfo: {postID: "%s"}, pageSize: 1000000000, preview: {}}) { commentList { author { @@ -133,9 +136,7 @@ class TrovoVodIE(TrovoBaseIE): } } }''' % vid, - }]).encode(), headers={ - 'Content-Type': 'application/json', - }) + }]).encode()) vod_detail_info = resp[0]['data']['batchGetVodDetailInfo']['VodDetailInfos'][vid] vod_info = vod_detail_info['vodInfo'] title = vod_info['title'] @@ -215,7 +216,7 @@ class TrovoChannelBaseIE(InfoExtractor): def _real_extract(self, url): id = self._match_id(url) - uid = str(self._download_json('https://gql.trovo.live/', id, query={ + uid = str(self._call_api(id, query={ 'query': '{getLiveInfo(params:{userName:"%s"}){streamerInfo{uid}}}' % id })['data']['getLiveInfo']['streamerInfo']['uid']) return self.playlist_result(self._entries(uid), playlist_id=uid) @@ -237,7 +238,7 @@ class TrovoChannelVodIE(TrovoChannelBaseIE): _TYPE = 'video' def _get_vod_json(self, page, uid): - return self._download_json('https://gql.trovo.live/', uid, query={ + return self._call_api(uid, query={ 'query': self._QUERY % (page, uid) })['data']['getChannelLtvVideoInfos'] @@ -258,6 +259,6 @@ class TrovoChannelClipIE(TrovoChannelBaseIE): _TYPE = 'clip' def _get_vod_json(self, page, uid): - return self._download_json('https://gql.trovo.live/', uid, query={ + return self._call_api(uid, query={ 'query': self._QUERY % (page, uid) })['data']['getChannelClipVideoInfos']