diff --git a/docs/configuration.rst b/docs/configuration.rst index 1ec47196..7fd569e3 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -4389,11 +4389,16 @@ Description extractor.tiktok.audio ---------------------- Type - ``bool`` + * ``bool`` + * ``string`` Default ``true`` Description - Download audio tracks using |ytdl|. + Controls audio download behavior. + + * ``true``: Download audio tracks + * ``"ytdl"``: Download audio tracks using |ytdl| + * ``false``: Ignore audio tracks extractor.tiktok.videos diff --git a/gallery_dl/extractor/tiktok.py b/gallery_dl/extractor/tiktok.py index 203b1acc..30f310d6 100644 --- a/gallery_dl/extractor/tiktok.py +++ b/gallery_dl/extractor/tiktok.py @@ -17,7 +17,7 @@ class TiktokExtractor(Extractor): category = "tiktok" directory_fmt = ("{category}", "{user}") filename_fmt = ( - "{id}{num:?_//>02} {title[b:150]}{img_id:? [/]/}.{extension}") + "{id}{num:?_//>02} {title[b:150]}{img_id|audio_id:? [/]/}.{extension}") archive_fmt = "{id}_{num}_{img_id}" root = "https://www.tiktok.com" cookies_domain = ".tiktok.com" @@ -83,7 +83,11 @@ class TiktokExtractor(Extractor): yield Message.Url, url, post if self.audio and "music" in post: - ytdl_media = "audio" + if self.audio == "ytdl": + ytdl_media = "audio" + else: + url = self._extract_audio(post) + yield Message.Url, url, post elif self.video and "video" in post: ytdl_media = "video" @@ -146,6 +150,25 @@ class TiktokExtractor(Extractor): 'type="application/json">', '') return util.json_loads(data)["__DEFAULT_SCOPE__"] + def _extract_audio(self, post): + audio = post["music"] + url = audio["playUrl"] + text.nameext_from_url(url, post) + post.update({ + "type" : "audio", + "image" : None, + "title" : post["desc"] or "TikTok audio #{}".format(post["id"]), + "duration" : audio.get("duration"), + "num" : 0, + "img_id" : "", + "audio_id" : audio.get("id"), + "width" : 0, + "height" : 0, + }) + if not post["extension"]: + post["extension"] = "mp3" + return url + def _check_status_code(self, detail, url): status = detail.get("statusCode") if not status: