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

Truncate description for shows with Apple feeds #1092

Merged
merged 14 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 17 additions & 0 deletions app/helpers/podcasts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ module PodcastsHelper

RSS_LANGUAGE_CODES = %w[af sq eu be bg ca zh-cn zh-tw hr cs da nl nl-be nl-nl en en-au en-bz en-ca en-ie en-jm en-nz en-ph en-za en-tt en-gb en-us en-zw et fo fi fr fr-be fr-ca fr-fr fr-lu fr-mc fr-ch gl gd de de-at de-de de-li de-lu de-ch el haw hu is in ga it it-it it-ch ja ko mk no pl pt pt-br pt-pt ro ro-mo ro-ro ru ru-mo ru-ru sr sk sl es es-ar es-bo es-cl es-co es-cr es-do es-ec es-sv es-gt es-hn es-mx es-ni es-pa es-py es-pe es-pr es-es es-uy es-ve sv sv-fi sv-se tr uk]

def feed_description(feed, podcast)
desc = feed.description.present? ? feed.description : podcast.description
desc ||= ""
if podcast.has_apple_config?
desc = desc.truncate_bytes(4000, omission: "")
kookster marked this conversation as resolved.
Show resolved Hide resolved
end
desc
end

def episode_description(episode)
desc = episode.description_with_default
if episode.podcast.has_apple_config?
desc = episode.description.truncate_bytes(4000, omission: "")
kookster marked this conversation as resolved.
Show resolved Hide resolved
end
desc
end
svevang marked this conversation as resolved.
Show resolved Hide resolved

def full_contact(type, item)
name = item.try("#{type}_name")
email = item.try("#{type}_email")
Expand Down
6 changes: 6 additions & 0 deletions app/models/apple/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Config < ApplicationRecord

accepts_nested_attributes_for :key

after_create :publish_feeds

def self.find_or_build_apple_feed(podcast)
existing_feed = Feeds::AppleSubscription.find_by_podcast_id(podcast.id)
existing_feed.present? ? existing_feed : Feeds::AppleSubscription.new(podcast_id: podcast.id)
Expand Down Expand Up @@ -65,6 +67,10 @@ def self.setup_delegated_delivery(podcast, key: nil, apple_config: nil, apple_sh
mark_as_delivered!(pub)
end

def publish_feeds
podcast&.publish!
end
kookster marked this conversation as resolved.
Show resolved Hide resolved

def not_default_feed
if feed&.default?
errors.add(:feed, "cannot use default feed")
Expand Down
3 changes: 2 additions & 1 deletion app/models/apple/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def create_episode_bridge_params

def episode_create_parameters
explicit = feeder_episode.explicit.present? && feeder_episode.explicit == "true"
desc = feeder_episode.description_with_default.truncate_bytes(4000, omission: "")

{
data:
Expand All @@ -290,7 +291,7 @@ def episode_create_parameters
guid: guid,
title: feeder_episode.title,
originalReleaseDate: feeder_episode.published_at.utc.iso8601,
description: feeder_episode.description_with_default,
description: desc,
websiteUrl: feeder_episode.url,
explicit: explicit,
episodeNumber: feeder_episode.episode_number,
Expand Down
4 changes: 4 additions & 0 deletions app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def apple_config
end
end

def has_apple_config?
apple_config.present?
end

def reload(options = nil)
remove_instance_variable(:@apple_config) if defined?(@apple_config)
super
Expand Down
8 changes: 2 additions & 6 deletions app/views/podcasts/show.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.copyright @podcast.copyright unless @podcast.copyright.blank?
xml.webMaster @podcast.web_master unless @podcast.web_master.blank?

if @feed.description.present?
xml.description { xml.cdata!(@feed.description) }
elsif @podcast.description.present?
xml.description { xml.cdata!(@podcast.description) }
end
xml.description { xml.cdata!(feed_description(@feed, @podcast)) }

xml.managingEditor @podcast.managing_editor unless @podcast.managing_editor.blank?

Expand Down Expand Up @@ -112,7 +108,7 @@ xml.rss "xmlns:atom" => "http://www.w3.org/2005/Atom",
xml.title(ep.title)
xml.pubDate ep.published_at.utc.rfc2822
xml.link ep.url || ep.enclosure_url(@feed)
xml.description { xml.cdata!(ep.description_with_default) }
xml.description { xml.cdata!(episode_description(ep)) }
# TODO: may not reflect the content_type/file_size of replaced media
xml.enclosure(url: ep.enclosure_url(@feed), type: ep.media_content_type(@feed), length: ep.media_file_size) if ep.media?

Expand Down
Loading