From 879d5b229cf745f95111603b6039c0b52a5d5475 Mon Sep 17 00:00:00 2001 From: Andrew Kuklewicz Date: Tue, 26 Nov 2024 15:43:11 -0500 Subject: [PATCH 1/2] Add class to remove chartable prefix --- lib/remove_chartable.rb | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/remove_chartable.rb diff --git a/lib/remove_chartable.rb b/lib/remove_chartable.rb new file mode 100644 index 000000000..699abf7b4 --- /dev/null +++ b/lib/remove_chartable.rb @@ -0,0 +1,73 @@ +# RemoveChartable.new.fix_feeds +class RemoveChartable + PRX_SWAP_FM_FEEDS = [424, 398, 4192, 181, 258, 268, 3334, 308, 4885, 279, 5051, 44, 144] + + SWAP_FM_PREFIX = "tracking.swap.fm/track/sblTq32fyWAjsHzze2LG/" + + DEBUG = true + + def fix_feeds + chartable_feeds.each do |feed| + puts "\npodcast: #{feed.podcast.id}: #{feed.podcast.title}, feed: #{feed.id}" + new_prefix = remove_chartable(feed.enclosure_prefix) + + if PRX_SWAP_FM_FEEDS.include?(feed.id) + new_prefix = add_swap_fm(new_prefix) + end + + puts "fix_feeds:\n\t'#{feed.enclosure_prefix}'\n\t'#{new_prefix}'\n" + + if (new_prefix != feed.enclosure_prefix) && !DEBUG + feed.update(enclosure_prefix: new_prefix) + feed.podcast.publish! + end + end + puts "done!" + end + + def chartable_feeds + Feed.where("enclosure_prefix like '%chrt.fm%' or enclosure_prefix like '%chtbl.com%'") + end + + def add_swap_fm(prefix) + if prefix.include?(SWAP_FM_PREFIX) + puts "add_swap_fm: swap.fm prefix already present" + return + end + + fixed = (prefix || "").gsub(/https:\//, "") + fixed = if fixed.blank? + "https://#{SWAP_FM_PREFIX}" + else + "#{fixed}/#{SWAP_FM_PREFIX}" + end + fixed = fixed.squeeze("/") + + # get rid of any leading slashes + fixed = fixed.sub(/^\/+/, "") + + fixed = (fixed.blank? || fixed == "/") ? nil : "https://#{fixed}" + puts "add_swap_fm: #{prefix} -> #{fixed}" + fixed + end + + def remove_chartable(prefix) + # remove https:/ anywhere in the prefix (we'll put it back!) + fixed = (prefix || "").gsub(/https:\//, "") + + # remove the chartable prefix + fixed = fixed.gsub(/(chrt\.fm|chtbl\.com)\/track\/\w+/, "") + + # remove any duplicate slashes left over + fixed = fixed.squeeze("/") + + # get rid of any leading slashes + fixed = fixed.sub(/^\/+/, "") + + # if all that is left is a single slash, this is nil + # otherwise, add back that protocol + fixed = (fixed.blank? || fixed == "/") ? nil : "https://#{fixed}" + puts "remove_chartable: #{prefix} -> #{fixed}" + fixed + end +end From 4d3ef6ac25a42805dd0e3e904193df8cf69e3774 Mon Sep 17 00:00:00 2001 From: Andrew Kuklewicz Date: Tue, 26 Nov 2024 16:22:53 -0500 Subject: [PATCH 2/2] Return the prefix, unchanged --- lib/remove_chartable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/remove_chartable.rb b/lib/remove_chartable.rb index 699abf7b4..95c953c65 100644 --- a/lib/remove_chartable.rb +++ b/lib/remove_chartable.rb @@ -32,7 +32,7 @@ def chartable_feeds def add_swap_fm(prefix) if prefix.include?(SWAP_FM_PREFIX) puts "add_swap_fm: swap.fm prefix already present" - return + return prefix end fixed = (prefix || "").gsub(/https:\//, "")