From 93da918554558ccf801c560301e9fab2e06b66b2 Mon Sep 17 00:00:00 2001 From: Irid3 Date: Sun, 21 Jul 2024 18:08:26 +0700 Subject: [PATCH] fix tiktok title --- extractors/tiktok/tiktok.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/extractors/tiktok/tiktok.go b/extractors/tiktok/tiktok.go index 496bab450..6576a3900 100644 --- a/extractors/tiktok/tiktok.go +++ b/extractors/tiktok/tiktok.go @@ -43,14 +43,28 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor titleMatcherRegExp := regexp.MustCompile(`]*>([^<]+)`) + titleMatcherRegExpOpt := regexp.MustCompile(`"desc":"([^"]*)"`) + titleMatcher := titleMatcherRegExp.FindStringSubmatch(html) + titleMatcherOpt := titleMatcherRegExpOpt.FindStringSubmatch(html) + if len(titleMatcher) == 0 { return nil, errors.WithStack(extractors.ErrURLParseFailed) } title := titleMatcher[1] + if title == "TikTok - Make Your Day" { + if len(titleMatcherOpt[1]) > 64 { + cutoff := titleMatcherOpt[1][:64] + lastSpace := strings.LastIndex(cutoff, " ") + title = titleMatcherOpt[1][:lastSpace] + } else { + title = titleMatcherOpt[1] + } + } + titleArr := strings.Split(title, "|") if len(titleArr) == 1 {