Skip to content

Commit 88be42f

Browse files
Merge pull request #60 from manojkarthick/fix/giphy-cdn-cleanup
Simplify Giphy CDN subdomain matching with a slice
2 parents d19052b + 69c91a4 commit 88be42f

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/download.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ static REDGIFS_DOMAIN: &str = "redgifs.com";
4343
static REDGIFS_API_PREFIX: &str = "https://api.redgifs.com/v1/gfycats";
4444

4545
static GIPHY_DOMAIN: &str = "giphy.com";
46-
static GIPHY_MEDIA_SUBDOMAIN: &str = "media.giphy.com";
47-
static GIPHY_MEDIA_SUBDOMAIN_0: &str = "media0.giphy.com";
48-
static GIPHY_MEDIA_SUBDOMAIN_1: &str = "media1.giphy.com";
49-
static GIPHY_MEDIA_SUBDOMAIN_2: &str = "media2.giphy.com";
50-
static GIPHY_MEDIA_SUBDOMAIN_3: &str = "media3.giphy.com";
51-
static GIPHY_MEDIA_SUBDOMAIN_4: &str = "media4.giphy.com";
46+
static GIPHY_MEDIA_SUBDOMAINS: &[&str] = &[
47+
"media.giphy.com",
48+
"media0.giphy.com",
49+
"media1.giphy.com",
50+
"media2.giphy.com",
51+
"media3.giphy.com",
52+
"media4.giphy.com",
53+
];
5254

5355
static YOUTUBE_DOMAIN: &str = "youtube.com";
5456
static YOUTUBE_SHORT_DOMAIN: &str = "youtu.be";
@@ -833,13 +835,7 @@ async fn get_media(data: &PostData) -> Result<Vec<SupportedMedia>, ReddSaverErro
833835
if url.contains(GIPHY_DOMAIN) {
834836
// giphy has multiple CDN networks named {media0, .., media5}
835837
// links can point to the canonical media subdomain or any content domains
836-
if url.contains(GIPHY_MEDIA_SUBDOMAIN)
837-
|| url.contains(GIPHY_MEDIA_SUBDOMAIN_0)
838-
|| url.contains(GIPHY_MEDIA_SUBDOMAIN_1)
839-
|| url.contains(GIPHY_MEDIA_SUBDOMAIN_2)
840-
|| url.contains(GIPHY_MEDIA_SUBDOMAIN_3)
841-
|| url.contains(GIPHY_MEDIA_SUBDOMAIN_4)
842-
{
838+
if GIPHY_MEDIA_SUBDOMAINS.iter().any(|s| url.contains(s)) {
843839
// if we encounter gif, mp4 or gifv - download as is
844840
if url.ends_with(GIF_EXTENSION)
845841
|| url.ends_with(MP4_EXTENSION)
@@ -858,8 +854,8 @@ async fn get_media(data: &PostData) -> Result<Vec<SupportedMedia>, ReddSaverErro
858854
let media_id = path.split("-").last().unwrap();
859855
let supported_media = SupportedMedia {
860856
components: vec![format!(
861-
"https://{}/media/{}.gif",
862-
GIPHY_MEDIA_SUBDOMAIN, media_id
857+
"https://media.giphy.com/media/{}.gif",
858+
media_id
863859
)],
864860
media_type: MediaType::GiphyGif,
865861
};

0 commit comments

Comments
 (0)