This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignores linked Discord Emojis, refactoring
- Loading branch information
Showing
5 changed files
with
257 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// isDiscordEmoji matches https://cdn.discordapp.com/emojis/503141595860959243.gif, and similar URLs/filenames | ||
func isDiscordEmoji(link string) bool { | ||
// always match discord emoji URLs, eg https://cdn.discordapp.com/emojis/340989430460317707.png | ||
if strings.HasPrefix(link, discordEmojiBaseUrl) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
func getDownloadLinks(inputURL string, channelID string, interactive bool) map[string]string { | ||
if RegexpUrlTwitter.MatchString(inputURL) { | ||
links, err := getTwitterUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("twitter URL failed,", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlTwitterStatus.MatchString(inputURL) { | ||
links, err := getTwitterStatusUrls(inputURL, channelID) | ||
if err != nil { | ||
fmt.Println("twitter status URL failed,", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlTistory.MatchString(inputURL) { | ||
links, err := getTistoryUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("tistory URL failed,", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlGfycat.MatchString(inputURL) { | ||
links, err := getGfycatUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("gfycat URL failed,", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlInstagram.MatchString(inputURL) { | ||
links, err := getInstagramUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("instagram URL failed,", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlImgurSingle.MatchString(inputURL) { | ||
links, err := getImgurSingleUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("imgur single URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlImgurAlbum.MatchString(inputURL) { | ||
links, err := getImgurAlbumUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("imgur album URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlGoogleDrive.MatchString(inputURL) { | ||
links, err := getGoogleDriveUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("google drive album URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlFlickrPhoto.MatchString(inputURL) { | ||
links, err := getFlickrPhotoUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("flickr photo URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlFlickrAlbum.MatchString(inputURL) { | ||
links, err := getFlickrAlbumUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("flickr album URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlFlickrAlbumShort.MatchString(inputURL) { | ||
links, err := getFlickrAlbumShortUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("flickr album short URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if RegexpUrlStreamable.MatchString(inputURL) { | ||
links, err := getStreamableUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("streamable URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
if DownloadTistorySites { | ||
if RegexpUrlPossibleTistorySite.MatchString(inputURL) { | ||
links, err := getPossibleTistorySiteUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("checking for tistory site failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} | ||
} | ||
if RegexpUrlGoogleDriveFolder.MatchString(inputURL) { | ||
if interactive { | ||
links, err := getGoogleDriveFolderUrls(inputURL) | ||
if err != nil { | ||
fmt.Println("google drive folder URL failed, ", inputURL, ",", err) | ||
} else if len(links) > 0 { | ||
return skipDuplicateLinks(links, channelID, interactive) | ||
} | ||
} else { | ||
fmt.Println("google drive folder only accepted in interactive channels") | ||
} | ||
} | ||
|
||
if !interactive && isDiscordEmoji(inputURL) { | ||
fmt.Printf("skipped %s as it is a Discord emoji\n", inputURL) | ||
return nil | ||
} | ||
|
||
// try without queries | ||
parsedURL, err := url.Parse(inputURL) | ||
if err == nil { | ||
parsedURL.RawQuery = "" | ||
inputURLWithoutQueries := parsedURL.String() | ||
if inputURLWithoutQueries != inputURL { | ||
return getDownloadLinks(inputURLWithoutQueries, channelID, interactive) | ||
} | ||
} | ||
|
||
return map[string]string{inputURL: ""} | ||
} |
Oops, something went wrong.