[tiktok] add 'audio' option (#7060)
This commit is contained in:
@@ -4316,6 +4316,16 @@ Description
|
||||
and click ``Create Token``.
|
||||
|
||||
|
||||
extractor.tiktok.audio
|
||||
----------------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
``true``
|
||||
Description
|
||||
Download audio tracks using |ytdl|.
|
||||
|
||||
|
||||
extractor.tiktok.videos
|
||||
-----------------------
|
||||
Type
|
||||
|
||||
@@ -595,6 +595,7 @@
|
||||
},
|
||||
"tiktok":
|
||||
{
|
||||
"audio" : true,
|
||||
"videos": true,
|
||||
|
||||
"user": {
|
||||
|
||||
@@ -22,11 +22,14 @@ class TiktokExtractor(Extractor):
|
||||
root = "https://www.tiktok.com"
|
||||
cookies_domain = ".tiktok.com"
|
||||
|
||||
def _init(self):
|
||||
self.audio = self.config("audio", True)
|
||||
self.videos = self.config("videos", True)
|
||||
|
||||
def avatar(self):
|
||||
return ""
|
||||
|
||||
def items(self):
|
||||
videos = self.config("videos", True)
|
||||
# We assume that all of the URLs served by urls() come from the same
|
||||
# author.
|
||||
downloaded_avatar = not self.avatar()
|
||||
@@ -50,8 +53,6 @@ class TiktokExtractor(Extractor):
|
||||
post["user"] = user = author["uniqueId"]
|
||||
post["date"] = text.parse_timestamp(post["createTime"])
|
||||
original_title = title = post["desc"]
|
||||
if not title:
|
||||
title = "TikTok photo #{}".format(post["id"])
|
||||
|
||||
if not downloaded_avatar:
|
||||
avatar_url = author["avatarLarger"]
|
||||
@@ -62,7 +63,11 @@ class TiktokExtractor(Extractor):
|
||||
downloaded_avatar = True
|
||||
|
||||
yield Message.Directory, post
|
||||
ytdl_media = False
|
||||
|
||||
if "imagePost" in post:
|
||||
if not original_title:
|
||||
title = "TikTok photo #{}".format(post["id"])
|
||||
img_list = post["imagePost"]["images"]
|
||||
for i, img in enumerate(img_list, 1):
|
||||
url = img["imageURL"]["urlList"][0]
|
||||
@@ -78,19 +83,23 @@ class TiktokExtractor(Extractor):
|
||||
})
|
||||
yield Message.Url, url, post
|
||||
|
||||
elif videos:
|
||||
if not original_title:
|
||||
title = "TikTok video #{}".format(post["id"])
|
||||
if self.audio and "music" in post:
|
||||
ytdl_media = "audio"
|
||||
|
||||
elif self.video and "video" in post:
|
||||
ytdl_media = "video"
|
||||
|
||||
else:
|
||||
self.log.info("%s: Skipping post", tiktok_url)
|
||||
|
||||
if videos:
|
||||
if ytdl_media:
|
||||
if not original_title:
|
||||
title = "TikTok {} #{}".format(ytdl_media, post["id"])
|
||||
post.update({
|
||||
"type" : "video",
|
||||
"type" : ytdl_media,
|
||||
"image" : None,
|
||||
"filename" : "",
|
||||
"extension" : "mp4",
|
||||
"extension" : "mp3" if ytdl_media == "audio" else "mp4",
|
||||
"title" : title,
|
||||
"num" : 0,
|
||||
"img_id" : "",
|
||||
|
||||
@@ -124,8 +124,19 @@ __tests__ = (
|
||||
"#comment" : "www.tiktokv.com link: many photos with audio",
|
||||
"#category" : ("", "tiktok", "post"),
|
||||
"#class" : tiktok.TiktokPostExtractor,
|
||||
"#options" : {"audio": True},
|
||||
"#pattern" : PATTERN_WITH_AUDIO,
|
||||
"#options" : {"videos": True},
|
||||
"#count" : 17,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://www.tiktokv.com/share/video/7240568259186019630",
|
||||
"#comment" : "www.tiktokv.com link: many photos with audio disabled",
|
||||
"#category" : ("", "tiktok", "post"),
|
||||
"#class" : tiktok.TiktokPostExtractor,
|
||||
"#options" : {"audio": False},
|
||||
"#pattern" : PATTERN,
|
||||
"#count" : 16,
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user