From 52833ef89e807ca02b18021b6e0004efe95a0987 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 21 Jun 2022 15:01:23 -0600 Subject: [PATCH] Redirect youtu.be links to the correct instance Farside was previously only looking for links containing "youtube.com" when performing the redirect for full URLs to youtube, which obviously doesn't work for youtu.be shortened links. This updates the matching logic to use a regex element for every key in the services map in order to match against multiple possible domains for each parent service. Fixes #40 --- lib/farside.ex | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/farside.ex b/lib/farside.ex index 97a14bc..21e5076 100644 --- a/lib/farside.ex +++ b/lib/farside.ex @@ -7,15 +7,15 @@ defmodule Farside do # This enables Farside to redirect with links such as: # farside.link/https://www.youtube.com/watch?v=dQw4w9WgXcQ @parent_services %{ - "youtube.com" => ["invidious", "piped"], - "reddit.com" => ["libreddit", "teddit"], - "instagram.com" => ["bibliogram"], - "twitter.com" => ["nitter"], - "wikipedia.org" => ["wikiless"], - "medium.com" => ["scribe"], - "odysee.com" => ["librarian"], - "imgur.com" => ["rimgo"], - "translate.google.com" => ["lingva"] + ~r/youtu(.be|be.com)/ => ["invidious", "piped"], + ~r/reddit.com/ => ["libreddit", "teddit"], + ~r/instagram.com/ => ["bibliogram"], + ~r/twitter.com/ => ["nitter"], + ~r/wikipedia.org/ => ["wikiless"], + ~r/medium.com/ => ["scribe"], + ~r/odysee.com/ => ["librarian"], + ~r/imgur.com/ => ["rimgo"], + ~r/translate.google.com/ => ["lingva"] } def get_services_map do @@ -49,7 +49,7 @@ defmodule Farside do Enum.find_value( @parent_services, fn {k, v} -> - service =~ k && Enum.random(v) + String.match?(service, k) && Enum.random(v) end) true -> service