Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions app/controllers/api/v4/chapter_recitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def index
render
end

def rss
@episodes = ::Audio::ChapterAudioFile.episodes

render template: 'api/v4/chapter_recitations/rss', formats: [:xml]
end

protected
def init_presenter
@presenter = ::Audio::RecitationPresenter.new(params)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ApplicationController < ActionController::API
include ActionController::Caching
include QuranUtils::StrongMemoize
include ActionView::Rendering
include ActionController::MimeResponds

before_action :set_cache_headers
before_action :set_default_response_format
Expand Down
6 changes: 6 additions & 0 deletions app/models/audio/chapter_audio_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ class Audio::ChapterAudioFile < ApplicationRecord
belongs_to :audio_recitation, class_name: 'Audio::Recitation'
belongs_to :chapter
has_many :audio_segments, class_name: 'Audio::Segment', foreign_key: 'audio_file_id'

def self.episodes
joins("left join reciters as r on metadata->>'artist' = r.name;")
.select("r.name as reciter_name, audio_url, metadata->>'title' as chapter_name ")

end
end
26 changes: 26 additions & 0 deletions app/views/api/v4/chapter_recitations/rss.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
xml.instruct!
xml.rss :version => "2.0", "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd" do
xml.channel do
xml.title "Quran.com Podcast"
xml.itunes:owner do
xml.tag! "itunes:email", "[email protected]"
end
xml.tag! "itunes:author", "Quran.com"
xml.link "http://localhost:3000/api/v4/rss"
xml.description "Quran.com podcast"
xml.language "en-us"
xml.image do
xml.link "http://localhost:3000/api/v4/rss"
xml.title "Quran.com Podcast"
xml.url "https://raw.githubusercontent.com/quran/quran.com-frontend-next/master/public/logo.png"
end

@episodes.each do |episode|
xml.item do
xml.enclosure :type => "audio/mpeg", :url => episode.audio_url
xml.title episode.chapter_name
xml.description episode.reciter_name
end
end
end
end
3 changes: 3 additions & 0 deletions config/routes/api/v4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
# Footnote
get 'foot_notes/:id', to: 'foot_notes#show'

# Podcast
get 'rss', to: 'chapter_recitations#rss'

# available resources
namespace :resources do
get :translations
Expand Down