mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-22 20:20:09 +09:00
[douyin] Incorporated dirkf's remarks
This commit is contained in:
parent
d3725a6ab2
commit
0ec08cef90
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
|||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
float_or_none,
|
int_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
orderedSet
|
orderedSet
|
||||||
)
|
)
|
||||||
@ -30,9 +30,10 @@ class DouyinVideoIE(InfoExtractor):
|
|||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
iteminfo = self._download_json('https://www.douyin.com/web/api/v2/aweme/iteminfo',
|
iteminfo = self._download_json('https://www.douyin.com/web/api/v2/aweme/iteminfo',
|
||||||
video_id, query={'item_ids': video_id})
|
video_id, query={'item_ids': video_id}) or {}
|
||||||
if iteminfo['status_code']:
|
status_code = iteminfo.get('status_code', 'status_code missing')
|
||||||
raise ExtractorError(iteminfo['status_msg'], video_id=video_id)
|
if status_code:
|
||||||
|
raise ExtractorError('%s (%s)' % (iteminfo.get('status_msg', 'status_msg missing'), status_code), video_id=video_id)
|
||||||
|
|
||||||
item_list = iteminfo.get('item_list')
|
item_list = iteminfo.get('item_list')
|
||||||
if not item_list:
|
if not item_list:
|
||||||
@ -40,20 +41,19 @@ class DouyinVideoIE(InfoExtractor):
|
|||||||
video_id=video_id, expected=True)
|
video_id=video_id, expected=True)
|
||||||
item = item_list[0]
|
item = item_list[0]
|
||||||
|
|
||||||
info_dict = {}
|
return {
|
||||||
info_dict['id'] = video_id
|
'id': video_id,
|
||||||
info_dict['title'] = item['desc']
|
'title': item['desc'],
|
||||||
info_dict['url'] = item['video']['play_addr']['url_list'][0]
|
'url': item['video']['play_addr']['url_list'][0],
|
||||||
info_dict['uploader'] = try_get(item, lambda x: x['author']['nickname'])
|
'uploader': try_get(item, lambda x: x['author']['nickname']),
|
||||||
info_dict['uploader_id'] = try_get(item, lambda x: x['author']['uid'])
|
'uploader_id': try_get(item, lambda x: x['author']['uid']),
|
||||||
info_dict['duration'] = float_or_none(item.get('duration') or try_get(item, lambda x: x['video']['duration'], int), scale=1000)
|
'duration': int_or_none(item.get('duration') or try_get(item, lambda x: x['video']['duration'], int), scale=1000),
|
||||||
info_dict['timestamp'] = float_or_none(item.get('create_time'), invscale=1000)
|
'timestamp': int_or_none(item.get('create_time'), invscale=1000),
|
||||||
info_dict['width'] = try_get(item, lambda x: x['video']['width'])
|
'width': try_get(item, lambda x: x['video']['width']),
|
||||||
info_dict['height'] = try_get(item, lambda x: x['video']['height'])
|
'height': try_get(item, lambda x: x['video']['height']),
|
||||||
info_dict['vbr'] = try_get(item, lambda x: x['video']['bit_rate'])
|
'vbr': try_get(item, lambda x: x['video']['bit_rate']),
|
||||||
info_dict['ext'] = 'mp4'
|
'ext': 'mp4'
|
||||||
|
}
|
||||||
return info_dict
|
|
||||||
|
|
||||||
|
|
||||||
class DouyinUserIE(InfoExtractor):
|
class DouyinUserIE(InfoExtractor):
|
||||||
@ -75,9 +75,10 @@ class DouyinUserIE(InfoExtractor):
|
|||||||
entries = []
|
entries = []
|
||||||
while has_more:
|
while has_more:
|
||||||
post = self._download_json('https://www.douyin.com/web/api/v2/aweme/post',
|
post = self._download_json('https://www.douyin.com/web/api/v2/aweme/post',
|
||||||
sec_uid, query={'sec_uid': sec_uid, 'max_cursor': max_cursor, 'count': 50})
|
sec_uid, query={'sec_uid': sec_uid, 'max_cursor': max_cursor, 'count': 50}) or {}
|
||||||
if post['status_code']:
|
status_code = post.get('status_code', 'status_code missing')
|
||||||
raise ExtractorError(post['status_msg'], video_id=sec_uid)
|
if status_code:
|
||||||
|
raise ExtractorError('%s (%s)' % (post.get('status_msg', 'status_msg missing'), status_code), video_id=sec_uid)
|
||||||
|
|
||||||
aweme_list = post.get('aweme_list')
|
aweme_list = post.get('aweme_list')
|
||||||
if aweme_list is None:
|
if aweme_list is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user