Browse Source

add setting output directory

master
mark 2 years ago
parent
commit
5faa087de9
1 changed files with 10 additions and 6 deletions
  1. +10
    -6
      main.go

+ 10
- 6
main.go View File

@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/signal"
"path"
"strings"
"syscall"

@@ -53,7 +54,7 @@ func getBestBitrate(variants []twitter.VideoVariant) (int, string) {
return bestBitrate, bestURL
}

func downloadFromTweet(c *twitter.Client, t *twitter.Tweet, burn bool) error {
func downloadFromTweet(c *twitter.Client, t *twitter.Tweet, outDir string, burn bool) error {
log.Printf("Checking for media in tweet %v", t.IDStr)
if t.ExtendedEntities == nil {
return nil
@@ -83,8 +84,9 @@ func downloadFromTweet(c *twitter.Client, t *twitter.Tweet, burn bool) error {
qMarkSplit := strings.Split(filename, "?")
filename = qMarkSplit[0]
}
filepath := path.Join(outDir, filename)

err := downloadFile(url, filename)
err := downloadFile(url, filepath)

if err != nil {
return err
@@ -129,10 +131,10 @@ func yeetTweet(c *twitter.Client, t *twitter.Tweet) error {
return nil
}

func setupDemux(c *twitter.Client, burn bool) twitter.SwitchDemux {
func setupDemux(c *twitter.Client, outDir string, burn bool) twitter.SwitchDemux {
demux := twitter.NewSwitchDemux()
demux.Tweet = func(tweet *twitter.Tweet) {
downloadFromTweet(c, tweet, burn)
downloadFromTweet(c, tweet, outDir, burn)
}

return demux
@@ -160,13 +162,15 @@ func main() {
AppName: "tmw",
}

var consumerKey, consumerSecret, token, tokenSecret *string
var consumerKey, consumerSecret, token, tokenSecret, outDir *string
var burn *bool

consumerKey = optionset.String("consumerkey", "", "Twitter application Consumer Key")
consumerSecret = optionset.String("consumersecret", "", "Twitter application Consumer Secret")
token = optionset.String("token", "", "Twitter application Access Token")
tokenSecret = optionset.String("tokensecret", "", "Twitter application Access Token Secret")
outDir = optionset.String("outdir", "", "Output directory to download files to")

burn = optionset.Bool("burn", true, "Whether to delete the tweet after downloading media.")

err := optionset.ParseEnv()
@@ -189,7 +193,7 @@ func main() {
user, _, _ := client.Accounts.VerifyCredentials(verifyParams)
log.Printf("Logged in as %v.\n", user.Name)

demux := setupDemux(client, *burn)
demux := setupDemux(client, *outDir, *burn)

log.Println("Starting stream...")



Loading…
Cancel
Save