Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podcasts guid, set by uuidv5, add to rss #1104

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Podcast < ApplicationRecord
FEED_GETTERS = FEED_ATTRS.map { |s| [s, "#{s}_was".to_sym, "#{s}_changed?".to_sym] }.flatten
FEED_SETTERS = FEED_ATTRS.map { |s| "#{s}=".to_sym }

# https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#guid
PODCAST_NAMESPACE = "ead4c236-bf58-58c6-a2c6-a6b28d128cb6".freeze

include TextSanitizer
include AdvisoryLocks
include EmbedPlayerHelper
Expand Down Expand Up @@ -57,8 +60,18 @@ def self.by_prx_series(series)
Podcast.find_by(prx_uri: series_uri)
end

def set_guid!
update!(guid: guid) if set_guid
end

def set_guid
return unless public_url.present? && guid.blank?
self.guid = Digest::UUID.uuid_v5(PODCAST_NAMESPACE, public_url)
end

def set_defaults
self.explicit ||= "false"
set_guid
end

def default_feed
Expand Down
4 changes: 4 additions & 0 deletions app/views/podcasts/show.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.podcast :funding, "Support the Show!", "url" => @podcast.donation_url
end

if @podcast.guid.present?
xml.podcast :guid, @podcast.guid
end

@episodes.each_with_index do |ep, index|
xml.item do
xml.guid(ep.item_guid, isPermaLink: !!ep.is_perma_link)
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240928150204_add_guid_to_podcasts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddGuidToPodcasts < ActiveRecord::Migration[7.2]
def change
add_column :podcasts, :guid, :string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to just generate these for all existing Podcasts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and we could do that at the console at any time, I just didn't force it in this PR

add_index :podcasts, :guid
end
end
9 changes: 5 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/models/podcast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
assert podcast.default_feed.private? == false
assert podcast.default_feed.slug.nil?
assert podcast.default_feed.file_name == Feed::DEFAULT_FILE_NAME
assert podcast.public_feed.present?
assert podcast.public_feed == podcast.default_feed
end

it "can set a guid on create or update" do
assert podcast.public_url == "http://feeds.feedburner.com/thornmorris"
assert podcast.guid == "95ebfb22-0002-5f78-a7aa-5acb5ac7daa9"
podcast.update_column(:guid, nil)
assert !podcast.guid.present?
podcast.set_guid
assert podcast.guid == "95ebfb22-0002-5f78-a7aa-5acb5ac7daa9"
podcast.update_column(:guid, nil)
podcast.set_guid!
assert podcast.guid == "95ebfb22-0002-5f78-a7aa-5acb5ac7daa9"
end

it "is episodic or serial" do
Expand Down
Loading