Skip to content
Prev Previous commit
Next Next commit
Segments and Surah info apis
  • Loading branch information
mmahalwy committed Dec 22, 2016
commit 72392e01c61b10ef29b72a894999f74aaa6207ac
22 changes: 11 additions & 11 deletions app/models/audio/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#
# Table name: audio.file
#
# file_id :integer not null, primary key
# recitation_id :integer not null
# ayah_key :text not null
# format :text not null
# duration :float
# mime_type :text not null
# is_enabled :boolean default(TRUE), not null
# url :text
# segments :text
# encrypted_segments :text
# file_id :integer not null, primary key
# recitation_id :integer not null
# ayah_key :text not null
# format :text not null
# duration :float
# mime_type :text not null
# is_enabled :boolean default(TRUE), not null
# url :text
# segments :text is an Array
# segments_stats :json
#

class Audio::File < ActiveRecord::Base
Expand All @@ -31,6 +31,6 @@ def as_json(options = {})
ayah = ayah_key.split(':')[1]


super(only: [:duration, :url, :encrypted_segments])
super(only: [:duration, :url, :segments])
end
end
2 changes: 1 addition & 1 deletion app/models/quran/ayah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def self.as_json_with_resources(ayahs, options = {})
if audio_option = options[:audio]
audio =
Audio::File
.where(ayah_key: keys, recitation_id: audio_option, is_enabled: true)
.where(ayah_key: keys, recitation_id: audio_option, is_enabled: true, format: 'mp3')
.order(:ayah_key)
.group_by(&:ayah_key)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/quran/surah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Quran::Surah < ActiveRecord::Base

def get_surah_info_for_language(language_code)
language = Locale::Language.find_by_language_code(language_code) || Locale::Language.find('en')
surah_infos.where(language: language)

surah_infos.find_by(language: language)
end

def name
Expand Down
2 changes: 1 addition & 1 deletion db
Submodule db updated from 5dbfe0 to 8dbe99
33 changes: 33 additions & 0 deletions lib/tasks/segments.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# May need this if @cpfair changes the files.
# files = [
# { recitation_id: 1, filename: 'Abdul_Basit_Mujawwad_128kbps.json' },
# { recitation_id: 2, filename: 'Abdul_Basit_Murattal_64kbps.json' },
# { recitation_id: 3, filename: 'Abdurrahmaan_As-Sudais_192kbps.json' },
# { recitation_id: 4, filename: 'Abu_Bakr_Ash-Shaatree_128kbps.json' },
# { recitation_id: 5, filename: 'Hani_Rifai_192kbps.json' },
# { recitation_id: 7, filename: 'Husary_Muallim_128kbps.json' },
# { recitation_id: 8, filename: 'Alafasy_128kbps.json' },
# { recitation_id: 9, filename: 'Minshawy_Mujawwad_192kbps.json' },
# { recitation_id: 10, filename: 'Minshawy_Murattal_128kbps.json' },
# { recitation_id: 11, filename: 'Saood_ash-Shuraym_128kbps.json' },
# { recitation_id: 12, filename: 'Mohammad_al_Tablaway_128kbps.json' },
# { recitation_id: 13, filename: 'Husary_64kbps.json' },
# ]
#
#
# Parallel.each(files, in_processes: 4, progress: 'Importing segments') do |file|
# begin
# puts file[:filename]
# json = Oj.load_file("../quran-align-data/#{file[:filename]}")
# audio_files = Audio::File.where(recitation_id: file[:recitation_id], segments: nil)
#
# json.each do |ayah_json|
# record = audio_files.find_by(ayah_key: "#{ayah_json['surah']}:#{ayah_json['ayah']}")
# record.update(segments: ayah_json["segments"], segments_stats: ayah_json["stats"])
# end
#
# rescue Exception => e
# puts e.message
# puts e.backtrace.inspect
# end
# end