Skip to content

Commit

Permalink
Plain text login
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
mmpx12 committed Apr 30, 2024
1 parent ee8cf8b commit 9f3f73f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Usage:
(default large)
-U, --update Download missing tweet only
-L, --login Log in to your account
-P, --login-plaintext Plain text Login (needed for NSFW tweets)
-o, --output DIR Output directory
-f, --file-format FORMAT Formatted name for the downloaded file
-p, --proxy PROXY Use proxy (proto://ip:port)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module twmd

go 1.22.0
go 1.22.2

require (
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e
github.com/imperatrona/twitter-scraper v0.0.0-20240321062442-6a0f92e31498
github.com/imperatrona/twitter-scraper v0.0.0-20240425221339-715658ada4d9
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
Expand All @@ -13,8 +13,8 @@ require (

require (
github.com/AlexEidt/Vidio v1.5.1 // indirect
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d // indirect
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.19.0 // indirect
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
github.com/AlexEidt/Vidio v1.5.1 h1:tovwvtgQagUz1vifiL9OeWkg1fP/XUzFazFKh7tFtaE=
github.com/AlexEidt/Vidio v1.5.1/go.mod h1:djhIMnWMqPrC3X6nB6ymGX6uWWlgw+VayYGKE1bNwmI=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d h1:2xp1BQbqcDDaikHnASWpVZRjibOxu7y9LhAv04whugI=
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU=
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/imperatrona/twitter-scraper v0.0.0-20240321062442-6a0f92e31498 h1:RXuNC5UJRKa+JZTocOtAKbDBW26yRi+mIcl1hod1nso=
github.com/imperatrona/twitter-scraper v0.0.0-20240321062442-6a0f92e31498/go.mod h1:+Z1pca7Faf2tzpHVRnRcratFxy/PuDKj2iaygdgZRLM=
github.com/imperatrona/twitter-scraper v0.0.0-20240425221339-715658ada4d9 h1:X/TQaFNGVNQXn33JnpQLBwQ+2Nd2P6x8EUEqMUI+xU4=
github.com/imperatrona/twitter-scraper v0.0.0-20240425221339-715658ada4d9/go.mod h1:+Z1pca7Faf2tzpHVRnRcratFxy/PuDKj2iaygdgZRLM=
github.com/mmpx12/optionparser v1.1.0 h1:CgfC8WBDxkHOlg9myndDMezNiyXeMzVRDLWDRIjdlf8=
github.com/mmpx12/optionparser v1.1.0/go.mod h1:1Ub9+E2fDinPCmAU2lCuJcXE8x0HCmkurDv+lcXgRd8=
github.com/n0madic/twitter-scraper v0.0.0-20231104223941-296710769dd8 h1:yToM7p7HL/WwEESkupFV3Nf7a8d80CHaKRoFNstGA2U=
Expand All @@ -33,9 +32,8 @@ 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 Down
29 changes: 18 additions & 11 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.1"
version = "1.13.2"
scraper *twitterscraper.Scraper
client *http.Client
size = "orig"
Expand Down Expand Up @@ -210,16 +210,22 @@ func photoSingle(tweet *twitterscraper.Tweet, output string) {
}
}

func askPass(twofa bool) {
func askPass(loginp, twofa bool) {
for {
var username string
var pass string
fmt.Printf("username: ")
fmt.Scanln(&username)
fmt.Printf("password: ")
pass, _ := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
if loginp {
fmt.Scanln(&pass)
} else {
password, _ := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
pass = string(password)
}
if !twofa {
scraper.Login(username, string(pass))
scraper.Login(username, pass)
} else {
var code string
fmt.Printf("two-factor: ")
Expand All @@ -240,17 +246,17 @@ func askPass(twofa bool) {
}
}

func Login(twofa bool) {
func Login(loginp, twofa bool) {
if _, err := os.Stat("twmd_cookies.json"); errors.Is(err, fs.ErrNotExist) {
askPass(twofa)
askPass(loginp, twofa)
} else {
f, _ := os.Open("twmd_cookies.json")
var cookies []*http.Cookie
json.NewDecoder(f).Decode(&cookies)
scraper.SetCookies(cookies)
}
if !scraper.IsLoggedIn() {
askPass(twofa)
askPass(loginp, twofa)
} else {
fmt.Println("Logged in")
}
Expand Down Expand Up @@ -404,7 +410,7 @@ func getFormat(tweet interface{}) string {

func main() {
var nbr, single, output string
var retweet, all, printversion, nologo, login, twofa bool
var retweet, all, printversion, nologo, login, loginp, twofa bool
op := optionparser.NewOptionParser()
op.Banner = "twmd: Apiless twitter media downloader\n\nUsage:"
op.On("-u", "--user USERNAME", "User you want to download", &usr)
Expand All @@ -421,6 +427,7 @@ func main() {
op.On("-o", "--output DIR", "Output directory", &output)
op.On("-f", "--file-format FORMAT", "Formatted name for the downloaded file, {DATE} {USERNAME} {NAME} {TITLE} {ID}", &format)
op.On("-L", "--login", "Login (needed for NSFW tweets)", &login)
op.On("-P", "--login-plaintext", "Plain text login (needed for NSFW tweets)", &loginp)
op.On("-2", "--2fa", "Use 2fa", &twofa)
op.On("-p", "--proxy PROXY", "Use proxy (proto://ip:port)", &proxy)
op.On("-V", "--version", "Print version and exit", &printversion)
Expand Down Expand Up @@ -490,8 +497,8 @@ func main() {
scraper = twitterscraper.New()
scraper.WithReplies(true)
scraper.SetProxy(proxy)
if login {
Login(twofa)
if login || loginp {
Login(loginp, twofa)
}

if single != "" {
Expand Down

0 comments on commit 9f3f73f

Please sign in to comment.