diff --git a/docs/configuration.rst b/docs/configuration.rst index 6334a624..a700b713 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 85f9a0ba..c1e861a3 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -595,6 +595,7 @@ }, "tiktok": { + "audio" : true, "videos": true, "user": { diff --git a/gallery_dl/extractor/tiktok.py b/gallery_dl/extractor/tiktok.py index e50dd351..d7534d62 100644 --- a/gallery_dl/extractor/tiktok.py +++ b/gallery_dl/extractor/tiktok.py @@ -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" : "", diff --git a/test/results/tiktok.py b/test/results/tiktok.py index 4f2c7438..9cd73a92 100644 --- a/test/results/tiktok.py +++ b/test/results/tiktok.py @@ -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, }, {