Browse Source

twitter check before error output

Drn 2 năm trước cách đây
mục cha
commit
f1809faac5
2 tập tin đã thay đổi với 25 bổ sung21 xóa
  1. 21 20
      downloads.go
  2. 4 1
      main.go

+ 21 - 20
downloads.go

@@ -231,29 +231,30 @@ func getDownloadLinks(inputURL string, m *discordgo.Message) map[string]string {
 	- Facebook Videos: Previously supported but they split mp4 into separate audio and video streams
 	*/
 
-	inputURL = strings.ReplaceAll(inputURL, "mobile.twitter", "twitter")
-	inputURL = strings.ReplaceAll(inputURL, "fxtwitter.com", "twitter.com")
-	inputURL = strings.ReplaceAll(inputURL, "c.vxtwitter.com", "twitter.com")
-	inputURL = strings.ReplaceAll(inputURL, "vxtwitter.com", "twitter.com")
-
-	if regexUrlTwitter.MatchString(inputURL) {
-		links, err := getTwitterUrls(inputURL)
-		if err != nil {
-			if !strings.Contains(err.Error(), "suspended") {
-				log.Println(lg("Download", "", color.RedString, "Twitter Media fetch failed for %s -- %s", inputURL, err))
+	if twitterConnected {
+		inputURL = strings.ReplaceAll(inputURL, "mobile.twitter", "twitter")
+		inputURL = strings.ReplaceAll(inputURL, "fxtwitter.com", "twitter.com")
+		inputURL = strings.ReplaceAll(inputURL, "c.vxtwitter.com", "twitter.com")
+		inputURL = strings.ReplaceAll(inputURL, "vxtwitter.com", "twitter.com")
+		if regexUrlTwitter.MatchString(inputURL) {
+			links, err := getTwitterUrls(inputURL)
+			if err != nil {
+				if !strings.Contains(err.Error(), "suspended") {
+					log.Println(lg("Download", "", color.RedString, "Twitter Media fetch failed for %s -- %s", inputURL, err))
+				}
+			} else if len(links) > 0 {
+				return trimDownloadedLinks(links, m)
 			}
-		} else if len(links) > 0 {
-			return trimDownloadedLinks(links, m)
 		}
-	}
-	if regexUrlTwitterStatus.MatchString(inputURL) {
-		links, err := getTwitterStatusUrls(inputURL, m)
-		if err != nil {
-			if !strings.Contains(err.Error(), "suspended") && !strings.Contains(err.Error(), "No status found") {
-				log.Println(lg("Download", "", color.RedString, "Twitter Status fetch failed for %s -- %s", inputURL, err))
+		if regexUrlTwitterStatus.MatchString(inputURL) {
+			links, err := getTwitterStatusUrls(inputURL, m)
+			if err != nil {
+				if !strings.Contains(err.Error(), "suspended") && !strings.Contains(err.Error(), "No status found") {
+					log.Println(lg("Download", "", color.RedString, "Twitter Status fetch failed for %s -- %s", inputURL, err))
+				}
+			} else if len(links) > 0 {
+				return trimDownloadedLinks(links, m)
 			}
-		} else if len(links) > 0 {
-			return trimDownloadedLinks(links, m)
 		}
 	}
 

+ 4 - 1
main.go

@@ -43,6 +43,9 @@ import (
 * Support Mediafire? (folder; direct singles)
 * Support Lightshot?
 * Support Gyazo?
+* Support TikTok -- Tried, once the connection is closed the cdn URL is rendered invalid
+* Support Facebook Photos -- Tried, it doesn't preload image data, it's loaded in after. Would have to keep connection open, find alternative way to grab, or use api.
+* Support Facebook Videos -- Previously supported but they split mp4 into separate audio and video streams
 
 * Add setting for filename max length, shorten if over given length, default to sys max
 
@@ -70,7 +73,7 @@ var (
 	myDB *db.DB
 
 	// APIs
-	twitterConnected bool
+	twitterConnected bool = false
 
 	// Gen
 	loop                 chan os.Signal