Skip to content

Commit

Permalink
Merge pull request #47 from KazuProg/fix-formatted-filename
Browse files Browse the repository at this point in the history
Fix incorrect output filename
  • Loading branch information
mmpx12 authored Apr 6, 2024
2 parents 1f0e3eb + e49549e commit d88cee6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ require (
github.com/mmpx12/optionparser v1.1.0
github.com/n0madic/twitter-scraper v0.0.0-20231104223941-296710769dd8
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627
golang.org/x/term v0.18.0
golang.org/x/term v0.19.0
)

require (
github.com/AlexEidt/Vidio v1.5.1 // indirect
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d // indirect
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
)
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -47,16 +48,18 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
60 changes: 27 additions & 33 deletions twmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ import (
"sync"
"time"

"unicode/utf8"

twitterscraper "github.com/imperatrona/twitter-scraper"
"github.com/mmpx12/optionparser"
"golang.org/x/term"
"unicode/utf8"
)

var (
usr string
format string
formatName string
proxy string
update bool
onlyrtw bool
vidz bool
imgs bool
urlOnly bool
version = "1.13.0"
scraper *twitterscraper.Scraper
client *http.Client
size = "orig"
usr string
format string
proxy string
update bool
onlyrtw bool
vidz bool
imgs bool
urlOnly bool
version = "1.13.1"
scraper *twitterscraper.Scraper
client *http.Client
size = "orig"
)

func download(wg *sync.WaitGroup, url string, filetype string, output string, dwn_type string) {
func download(wg *sync.WaitGroup, tweet interface{}, url string, filetype string, output string, dwn_type string) {
defer wg.Done()
segments := strings.Split(url, "/")
name := segments[len(segments)-1]
Expand All @@ -49,7 +49,7 @@ func download(wg *sync.WaitGroup, url string, filetype string, output string, dw
name = segments[len(segments)-2]
}
if format != "" {
name = formatName + "_" + name
name = getFormat(tweet) + "_" + name
}
if urlOnly {
fmt.Println(url)
Expand Down Expand Up @@ -120,7 +120,7 @@ func videoUser(wait *sync.WaitGroup, tweet *twitterscraper.TweetResult, output s
if rt || onlyrtw {
v := vidUrl(j)
wg.Add(1)
go download(&wg, v, "video", output, "user")
go download(&wg, tweet, v, "video", output, "user")
} else {
continue
}
Expand All @@ -129,7 +129,7 @@ func videoUser(wait *sync.WaitGroup, tweet *twitterscraper.TweetResult, output s
}
v := vidUrl(j)
wg.Add(1)
go download(&wg, v, "video", output, "user")
go download(&wg, tweet, v, "video", output, "user")
}
wg.Wait()
}
Expand All @@ -154,7 +154,7 @@ func photoUser(wait *sync.WaitGroup, tweet *twitterscraper.TweetResult, output s
url = i.URL
}
wg.Add(1)
go download(&wg, url, "img", output, "user")
go download(&wg, tweet, url, "img", output, "user")
}
}
wg.Wait()
Expand All @@ -172,10 +172,10 @@ func videoSingle(tweet *twitterscraper.Tweet, output string) {
v := vidUrl(j)
if usr != "" {
wg.Add(1)
go download(&wg, v, "rtvideo", output, "user")
go download(&wg, tweet, v, "rtvideo", output, "user")
} else {
wg.Add(1)
go download(&wg, v, "tweet", output, "tweet")
go download(&wg, tweet, v, "tweet", output, "tweet")
}
}
wg.Wait()
Expand All @@ -199,10 +199,10 @@ func photoSingle(tweet *twitterscraper.Tweet, output string) {
}
if usr != "" {
wg.Add(1)
go download(&wg, url, "rtimg", output, "user")
go download(&wg, tweet, url, "rtimg", output, "user")
} else {
wg.Add(1)
go download(&wg, url, "tweet", output, "tweet")
go download(&wg, tweet, url, "tweet", output, "tweet")
}
}
}
Expand Down Expand Up @@ -266,9 +266,6 @@ func singleTweet(output string, id string) {
fmt.Println("Error retrieve tweet")
return
}
if format != "" {
getFormat(tweet)
}
if usr != "" {
if vidz {
videoSingle(tweet, output)
Expand All @@ -282,7 +279,7 @@ func singleTweet(output string, id string) {
}
}

func getFormat(tweet interface{}) {
func getFormat(tweet interface{}) string {
var formatNew string
var tweetResult *twitterscraper.TweetResult
var tweetObj *twitterscraper.Tweet
Expand All @@ -294,7 +291,7 @@ func getFormat(tweet interface{}) {
tweetObj = t
default:
fmt.Println("Invalid tweet type")
return
return ""
}

formatParts := strings.Split(format, " ")
Expand All @@ -304,7 +301,7 @@ func getFormat(tweet interface{}) {
regex, err := regexp.Compile(pattern)
if err != nil {
fmt.Println("Error compiling regular expression:", err)
return
return ""
}

processText := func(text string, remainingChars int) string {
Expand Down Expand Up @@ -401,7 +398,7 @@ func getFormat(tweet interface{}) {
}
}

formatName = formatNew
return formatNew

}

Expand Down Expand Up @@ -527,9 +524,6 @@ func main() {
fmt.Println(tweet.Error)
os.Exit(1)
}
if format != "" {
getFormat(tweet)
}
if vidz {
wg.Add(1)
go videoUser(&wg, tweet, output, retweet)
Expand Down

0 comments on commit d88cee6

Please sign in to comment.