download video
This commit is contained in:
parent
06b483099c
commit
3165ef58a5
@ -1,4 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
import os.path
|
||||||
|
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
|
||||||
|
|
||||||
@ -26,6 +28,15 @@ class TikTokTestYoutubeDl(unittest.TestCase):
|
|||||||
self.assertEquals(info['ext'], 'mp.4')
|
self.assertEquals(info['ext'], 'mp.4')
|
||||||
self.assertGreater(len(info['embed_code']),0)
|
self.assertGreater(len(info['embed_code']),0)
|
||||||
|
|
||||||
|
def test_download_video(self):
|
||||||
|
url = 'https://www.tiktok.com/@ballislife/video/6783617809113943301'
|
||||||
|
params = {}
|
||||||
|
ydl = youtube_dl.YoutubeDL(params)
|
||||||
|
info = ydl.extract_info(url, download=True)
|
||||||
|
self.assertTrue(os.path.exists("Imagine lebron freaking out over something you did! #foryou #ballislife #lebron #nba-6783617809113943301.mp.4"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -4,63 +4,31 @@ from bs4 import BeautifulSoup
|
|||||||
import json
|
import json
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
compat_str,
|
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
)
|
||||||
str_or_none,
|
|
||||||
try_get,
|
|
||||||
url_or_none)
|
|
||||||
|
|
||||||
|
|
||||||
class TikTokBaseIE(InfoExtractor):
|
class TikTokBaseIE(InfoExtractor):
|
||||||
def _extract_aweme(self, data):
|
def _extract_aweme(self, data):
|
||||||
video = data['video']
|
video = data['props']['pageProps']['metaParams']
|
||||||
description = str_or_none(try_get(data, lambda x: x['desc']))
|
description = video['description']
|
||||||
width = int_or_none(try_get(data, lambda x: video['width']))
|
video_meta=data['props']['pageProps']['videoData']['itemInfos']['video']
|
||||||
height = int_or_none(try_get(data, lambda x: video['height']))
|
width = video_meta['videoMeta']['width']
|
||||||
|
height = video_meta['videoMeta']['height']
|
||||||
|
format_urls=video_meta['urls']
|
||||||
|
|
||||||
format_urls = set()
|
|
||||||
formats = []
|
formats = []
|
||||||
for format_id in (
|
for format in format_urls:
|
||||||
'play_addr_lowbr', 'play_addr', 'play_addr_h264',
|
formats.append({
|
||||||
'download_addr'):
|
'url': format,
|
||||||
for format in try_get(
|
'ext': 'mp4',
|
||||||
video, lambda x: x[format_id]['url_list'], list) or []:
|
'height': height,
|
||||||
format_url = url_or_none(format)
|
'width': width,
|
||||||
if not format_url:
|
})
|
||||||
continue
|
|
||||||
if format_url in format_urls:
|
|
||||||
continue
|
|
||||||
format_urls.add(format_url)
|
|
||||||
formats.append({
|
|
||||||
'url': format_url,
|
|
||||||
'ext': 'mp4',
|
|
||||||
'height': height,
|
|
||||||
'width': width,
|
|
||||||
})
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
thumbnail = url_or_none(try_get(
|
|
||||||
video, lambda x: x['cover']['url_list'][0], compat_str))
|
|
||||||
uploader = try_get(data, lambda x: x['author']['nickname'], compat_str)
|
|
||||||
timestamp = int_or_none(data.get('create_time'))
|
|
||||||
comment_count = int_or_none(data.get('comment_count')) or int_or_none(
|
|
||||||
try_get(data, lambda x: x['statistics']['comment_count']))
|
|
||||||
repost_count = int_or_none(try_get(
|
|
||||||
data, lambda x: x['statistics']['share_count']))
|
|
||||||
|
|
||||||
aweme_id = data['aweme_id']
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': aweme_id,
|
|
||||||
'title': uploader or aweme_id,
|
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'formats': formats
|
||||||
'uploader': uploader,
|
|
||||||
'timestamp': timestamp,
|
|
||||||
'comment_count': comment_count,
|
|
||||||
'repost_count': repost_count,
|
|
||||||
'formats': formats,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -115,14 +83,16 @@ class TikTokIE(TikTokBaseIE):
|
|||||||
comments_count = item_info['commentCount']
|
comments_count = item_info['commentCount']
|
||||||
likes_count = item_info['diggCount']
|
likes_count = item_info['diggCount']
|
||||||
|
|
||||||
|
entry=self._extract_aweme(data_dict)
|
||||||
|
|
||||||
return self.info_dict(video_id, str(url), json_api['title'],
|
return self.info_dict(video_id, str(url), json_api['title'],
|
||||||
json_api['author_name'], timestamp, json_api['thumbnail_url'],
|
json_api['author_name'], timestamp, json_api['thumbnail_url'],
|
||||||
views, provider_id, False, 'not_live', likes_count, shares, '', comments_count, duration, json_api['html'])
|
views, provider_id, False, 'not_live', likes_count, shares, '', comments_count, duration, json_api['html'], entry['formats'])
|
||||||
|
|
||||||
def info_dict(self, video_id, url, video_title,
|
def info_dict(self, video_id, url, video_title,
|
||||||
uploader, timestamp, thumbnail,
|
uploader, timestamp, thumbnail,
|
||||||
view_count, uploader_id, is_live, live_status
|
view_count, uploader_id, is_live, live_status
|
||||||
, likes_count, shares_count, subtitles, comment_count, duration, embed_code):
|
, likes_count, shares_count, subtitles, comment_count, duration, embed_code, format):
|
||||||
info_dict = {
|
info_dict = {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': url,
|
'url': url,
|
||||||
@ -140,7 +110,8 @@ class TikTokIE(TikTokBaseIE):
|
|||||||
'comment_count': comment_count,
|
'comment_count': comment_count,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'ext':'mp.4',
|
'ext':'mp.4',
|
||||||
'embed_code': embed_code
|
'embed_code': embed_code,
|
||||||
|
'format': format
|
||||||
}
|
}
|
||||||
return info_dict
|
return info_dict
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user