Skip to content

Commit

Permalink
TikTok: Only download avatar when extracting user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualYT31 committed Dec 24, 2024
1 parent 8aec090 commit a6238e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions gallery_dl/extractor/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ class TiktokExtractor(Extractor):
def urls(self):
return [self.url]

def avatar(self):
return False

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 = False
downloaded_avatar = not self.avatar()
for tiktok_url in self.urls():
# If we can recognise that this is a /photo/ link, preemptively
# replace it with /video/ to prevent a needless second request.
Expand Down Expand Up @@ -97,12 +100,13 @@ def items(self):
yield Message.Directory, {"user": user}
if not downloaded_avatar:
avatar = post_info["author"]["avatarLarger"]
name_and_ext = text.nameext_from_url(avatar)
yield Message.Url, avatar, {
"title" : "@" + user,
"id" : post_info["author"]["id"],
"index" : "",
"img_id" : "",
"extension" : text.ext_from_url(avatar)
"img_id" : name_and_ext["filename"].split("~")[0],
"extension" : name_and_ext["extension"]
}
downloaded_avatar = True
if "imagePost" in post_info:
Expand Down Expand Up @@ -183,3 +187,6 @@ def urls(self):
info = ydl.extract_info(self.url, download=False)
# This should include video and photo posts in /video/ URL form.
return [video["webpage_url"] for video in info["entries"]]

def avatar(self):
return True
8 changes: 4 additions & 4 deletions test/results/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,31 @@
"#comment" : "Video post",
"#category" : ("", "tiktok", "post"),
"#class" : tiktok.TiktokPostExtractor,
"#pattern" : PATTERN_WITH_AUDIO,
"#urls" : "ytdl:https://www.tiktok.com/@memezar/video/7449708266168274208",
"#options" : {"videos": True}
},
{
"#url" : "https://www.tiktok.com/@memezar/photo/7449708266168274208",
"#comment" : "Video post as a /photo/ link",
"#category" : ("", "tiktok", "post"),
"#class" : tiktok.TiktokPostExtractor,
"#pattern" : PATTERN_WITH_AUDIO,
"#urls" : "ytdl:https://www.tiktok.com/@memezar/video/7449708266168274208",
"#options" : {"videos": True}
},
{
"#url" : "https://vm.tiktok.com/ZGdht7cjp/",
"#comment" : "Video post as a VM link",
"#category" : ("", "tiktok", "vmpost"),
"#class" : tiktok.TiktokVmpostExtractor,
"#pattern" : PATTERN_WITH_AUDIO,
"#urls" : "ytdl:https://vm.tiktok.com/ZGdht7cjp/",
"#options" : {"videos": True}
},
{
"#url" : "https://www.tiktok.com/@memezar/video/7449708266168274208",
"#comment" : "Skipping video post",
"#category" : ("", "tiktok", "post"),
"#class" : tiktok.TiktokPostExtractor,
"#pattern" : PATTERN,
"#urls" : [],
"#options" : {"videos": False}
},
{
Expand Down

0 comments on commit a6238e5

Please sign in to comment.