Skip to content

Commit

Permalink
Fix can't download video close #51
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuProg committed May 3, 2024
1 parent f68243e commit 26edd31
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions twmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,24 @@ func download(wg *sync.WaitGroup, tweet interface{}, url string, filetype string
}
}

func vidUrl(video string) string {
vid := strings.Split(string(video), " ")
v := vid[len(vid)-1]
v = strings.TrimSuffix(v, "}")
vid = strings.Split(v, "?")
return vid[0]
}

func videoUser(wait *sync.WaitGroup, tweet *twitterscraper.TweetResult, output string, rt bool) {
defer wait.Done()
wg := sync.WaitGroup{}
if len(tweet.Videos) > 0 {
for _, i := range tweet.Videos {
j := fmt.Sprintf("%s", i)
url := strings.Split(i.URL, "?")[0]
if tweet.IsRetweet {
if rt || onlyrtw {
v := vidUrl(j)
wg.Add(1)
go download(&wg, tweet, v, "video", output, "user")
go download(&wg, tweet, url, "video", output, "user")
} else {
continue
}
} else if onlyrtw {
continue
}
v := vidUrl(j)
wg.Add(1)
go download(&wg, tweet, v, "video", output, "user")
go download(&wg, tweet, url, "video", output, "user")
}
wg.Wait()
}
Expand Down Expand Up @@ -224,14 +214,13 @@ func videoSingle(tweet *twitterscraper.Tweet, output string) {
if len(tweet.Videos) > 0 {
wg := sync.WaitGroup{}
for _, i := range tweet.Videos {
j := fmt.Sprintf("%s", i)
v := vidUrl(j)
url := strings.Split(i.URL, "?")[0]
if usr != "" {
wg.Add(1)
go download(&wg, tweet, v, "rtvideo", output, "user")
go download(&wg, tweet, url, "rtvideo", output, "user")
} else {
wg.Add(1)
go download(&wg, tweet, v, "tweet", output, "tweet")
go download(&wg, tweet, url, "tweet", output, "tweet")
}
}
wg.Wait()
Expand Down

0 comments on commit 26edd31

Please sign in to comment.