Skip to content

Commit

Permalink
fix tiktok title
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifulI57 committed Jul 21, 2024
1 parent 0883b0f commit 93da918
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extractors/tiktok/tiktok.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,28 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor

titleMatcherRegExp := regexp.MustCompile(`<title[^>]*>([^<]+)</title>`)

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 {
Expand Down

0 comments on commit 93da918

Please sign in to comment.