Skip to content

Commit

Permalink
Merge pull request #1104 from PRX/feat/podcasts_guid
Browse files Browse the repository at this point in the history
Add podcasts guid, set by uuidv5, add to rss
  • Loading branch information
kookster authored Oct 9, 2024
2 parents d39a96c + 1058b43 commit 4badbd7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
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
add_index :podcasts, :guid
end
end
5 changes: 3 additions & 2 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

0 comments on commit 4badbd7

Please sign in to comment.