]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tiktok.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
15 class TikTokBaseIE(InfoExtractor
):
16 def _extract_aweme(self
, data
):
18 description
= str_or_none(try_get(data
, lambda x
: x
['desc']))
19 width
= int_or_none(try_get(data
, lambda x
: video
['width']))
20 height
= int_or_none(try_get(data
, lambda x
: video
['height']))
25 'play_addr_lowbr', 'play_addr', 'play_addr_h264',
27 for format
in try_get(
28 video
, lambda x
: x
[format_id
]['url_list'], list) or []:
29 format_url
= url_or_none(format
)
32 if format_url
in format_urls
:
34 format_urls
.add(format_url
)
41 self
._sort
_formats
(formats
)
43 thumbnail
= url_or_none(try_get(
44 video
, lambda x
: x
['cover']['url_list'][0], compat_str
))
45 uploader
= try_get(data
, lambda x
: x
['author']['nickname'], compat_str
)
46 timestamp
= int_or_none(data
.get('create_time'))
47 comment_count
= int_or_none(data
.get('comment_count')) or int_or_none(
48 try_get(data
, lambda x
: x
['statistics']['comment_count']))
49 repost_count
= int_or_none(try_get(
50 data
, lambda x
: x
['statistics']['share_count']))
52 aweme_id
= data
['aweme_id']
56 'title': uploader
or aweme_id
,
57 'description': description
,
58 'thumbnail': thumbnail
,
60 'timestamp': timestamp
,
61 'comment_count': comment_count
,
62 'repost_count': repost_count
,
67 class TikTokIE(TikTokBaseIE
):
71 (?:m\.)?tiktok\.com/v|
72 (?:www\.)?tiktok\.com/share/video
77 'url': 'https://m.tiktok.com/v/6606727368545406213.html',
78 'md5': 'd584b572e92fcd48888051f238022420',
80 'id': '6606727368545406213',
83 'description': '#bowsette#mario#cosplay#uk#lgbt#gaming#asian#bowsettecosplay',
84 'thumbnail': r
're:^https?://.*~noop.image',
85 'uploader': 'Zureeal',
86 'timestamp': 1538248586,
87 'upload_date': '20180929',
92 'url': 'https://www.tiktok.com/share/video/6606727368545406213',
93 'only_matching': True,
96 def _real_extract(self
, url
):
97 video_id
= self
._match
_id
(url
)
98 webpage
= self
._download
_webpage
(
99 'https://m.tiktok.com/v/%s.html' % video_id
, video_id
)
100 data
= self
._parse
_json
(self
._search
_regex
(
101 r
'\bdata\s*=\s*({.+?})\s*;', webpage
, 'data'), video_id
)
102 return self
._extract
_aweme
(data
)
105 class TikTokUserIE(TikTokBaseIE
):
106 _VALID_URL
= r
'''(?x)
109 (?:m\.)?tiktok\.com/h5/share/usr|
110 (?:www\.)?tiktok\.com/share/user
115 'url': 'https://m.tiktok.com/h5/share/usr/188294915489964032.html',
117 'id': '188294915489964032',
119 'playlist_mincount': 24,
121 'url': 'https://www.tiktok.com/share/user/188294915489964032',
122 'only_matching': True,
125 def _real_extract(self
, url
):
126 user_id
= self
._match
_id
(url
)
127 data
= self
._download
_json
(
128 'https://m.tiktok.com/h5/share/usr/list/%s/' % user_id
, user_id
,
129 query
={'_signature': '_'})
131 for aweme
in data
['aweme_list']:
133 entry
= self
._extract
_aweme
(aweme
)
134 except ExtractorError
:
136 entry
['extractor_key'] = TikTokIE
.ie_key()
137 entries
.append(entry
)
138 return self
.playlist_result(entries
, user_id
)