]>
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
): 
  68     _VALID_URL 
= r
'https?://(?:m\.)?tiktok\.com/v/(?P<id>\d+)' 
  70         'url': 'https://m.tiktok.com/v/6606727368545406213.html', 
  71         'md5': 'd584b572e92fcd48888051f238022420', 
  73             'id': '6606727368545406213', 
  76             'description': '#bowsette#mario#cosplay#uk#lgbt#gaming#asian#bowsettecosplay', 
  77             'thumbnail': r
're:^https?://.*~noop.image', 
  78             'uploader': 'Zureeal', 
  79             'timestamp': 1538248586, 
  80             'upload_date': '20180929', 
  86     def _real_extract(self
, url
): 
  87         video_id 
= self
._match
_id
(url
) 
  88         webpage 
= self
._download
_webpage
(url
, video_id
) 
  89         data 
= self
._parse
_json
(self
._search
_regex
( 
  90             r
'\bdata\s*=\s*({.+?})\s*;', webpage
, 'data'), video_id
) 
  91         return self
._extract
_aweme
(data
) 
  94 class TikTokUserIE(TikTokBaseIE
): 
  95     _VALID_URL 
= r
'https?://(?:m\.)?tiktok\.com/h5/share/usr/(?P<id>\d+)' 
  97         'url': 'https://m.tiktok.com/h5/share/usr/188294915489964032.html', 
  99             'id': '188294915489964032', 
 101         'playlist_mincount': 24, 
 104     def _real_extract(self
, url
): 
 105         user_id 
= self
._match
_id
(url
) 
 106         data 
= self
._download
_json
( 
 107             'https://m.tiktok.com/h5/share/usr/list/%s/' % user_id
, user_id
, 
 108             query
={'_signature': '_'}) 
 110         for aweme 
in data
['aweme_list']: 
 112                 entry 
= self
._extract
_aweme
(aweme
) 
 113             except ExtractorError
: 
 115             entry
['extractor_key'] = TikTokIE
.ie_key() 
 116             entries
.append(entry
) 
 117         return self
.playlist_result(entries
, user_id
)