Skip to content

Commit

Permalink
Merge pull request #53 from KazuProg/fix-download-video
Browse files Browse the repository at this point in the history
Fix can't download video close #51
  • Loading branch information
mmpx12 authored May 16, 2024
2 parents 7de5459 + a9b3601 commit 9f32fef
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions twmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
vidz bool
imgs bool
urlOnly bool
version = "1.13.2"
version = "1.13.3"
scraper *twitterscraper.Scraper
client *http.Client
size = "orig"
Expand Down Expand Up @@ -103,34 +103,25 @@ func download(wg *sync.WaitGroup, tweet interface{}, url string, filetype string
fmt.Println("Downloaded " + name)
}

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")
continue
} 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 @@ -169,14 +160,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 9f32fef

Please sign in to comment.