mirror of https://github.com/blackjack4494/yt-dlc
[viki:channel] Switch to API
This commit is contained in:
parent
ac20d95f97
commit
bc56355ec6
|
@ -4,6 +4,7 @@ import re
|
||||||
import time
|
import time
|
||||||
import hmac
|
import hmac
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import itertools
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
|
@ -227,7 +228,7 @@ class VikiIE(VikiBaseIE):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class VikiChannelIE(InfoExtractor):
|
class VikiChannelIE(VikiBaseIE):
|
||||||
IE_NAME = 'viki:channel'
|
IE_NAME = 'viki:channel'
|
||||||
_VALID_URL = r'https?://(?:www\.)?viki\.com/tv/(?P<id>[0-9]+c)'
|
_VALID_URL = r'https?://(?:www\.)?viki\.com/tv/(?P<id>[0-9]+c)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
|
@ -247,16 +248,15 @@ class VikiChannelIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
'playlist_count': 127,
|
'playlist_count': 127,
|
||||||
}]
|
}]
|
||||||
_API_BASE = 'http://api.viki.io/v4/containers'
|
|
||||||
_APP = '100000a'
|
|
||||||
_PER_PAGE = 25
|
_PER_PAGE = 25
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
channel_id = self._match_id(url)
|
channel_id = self._match_id(url)
|
||||||
|
|
||||||
channel = self._download_json(
|
channel = self._call_api(
|
||||||
'%s/%s.json?app=%s' % (self._API_BASE, channel_id, self._APP),
|
'containers/%s.json' % channel_id, channel_id,
|
||||||
channel_id, 'Downloading channel JSON')
|
'Downloading channel JSON')
|
||||||
|
|
||||||
titles = channel['titles']
|
titles = channel['titles']
|
||||||
title = titles.get('en') or titles[titles.keys()[0]]
|
title = titles.get('en') or titles[titles.keys()[0]]
|
||||||
|
@ -266,16 +266,16 @@ class VikiChannelIE(InfoExtractor):
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for video_type in ('episodes', 'clips'):
|
for video_type in ('episodes', 'clips'):
|
||||||
page_url = '%s/%s/%s.json?app=%s&per_page=%d&sort=number&direction=asc&with_paging=true&page=1' % (self._API_BASE, channel_id, video_type, self._APP, self._PER_PAGE)
|
for page_num in itertools.count(1):
|
||||||
while page_url:
|
page = self._call_api(
|
||||||
page = self._download_json(
|
'containers/%s/%s.json?per_page=%d&sort=number&direction=asc&with_paging=true&page=%d'
|
||||||
page_url, channel_id,
|
% (channel_id, video_type, self._PER_PAGE, page_num), channel_id,
|
||||||
'Downloading %s JSON page #%s'
|
'Downloading %s JSON page #%d' % (video_type, page_num))
|
||||||
% (video_type, re.search(r'[?&]page=([0-9]+)', page_url).group(1)))
|
|
||||||
for video in page['response']:
|
for video in page['response']:
|
||||||
video_id = video['id']
|
video_id = video['id']
|
||||||
entries.append(self.url_result(
|
entries.append(self.url_result(
|
||||||
'http://www.viki.com/videos/%s' % video_id, 'Viki', video_id))
|
'http://www.viki.com/videos/%s' % video_id, 'Viki'))
|
||||||
page_url = page['pagination']['next']
|
if not page['pagination']['next']:
|
||||||
|
break
|
||||||
|
|
||||||
return self.playlist_result(entries, channel_id, title, description)
|
return self.playlist_result(entries, channel_id, title, description)
|
||||||
|
|
Loading…
Reference in New Issue