quran-audio 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/quran-audio +23 -12
- data/lib/quran/audio/command/pull.rb +18 -9
- data/lib/quran/audio/mp3.rb +2 -2
- data/libexec/quran-audio/pull +5 -2
- data/share/quran-audio/VERSION +1 -1
- data/share/quran-audio/data/recitations.json +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709a79351be5539a80a26a13ac39b41336b6a084cc14e56d476e5cd203090ab6
|
4
|
+
data.tar.gz: 7a0e5403541389a206d28f98bf53756a33ef672ad2bbc7162378efd59080642e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 655fda01723b31bd0d125f886a1b4695d6f16f8ae6bc5b3fac69c12019954c059f1a0fad0987e4d417e689d818400696a11dfa4431002cbcf4d9151f3c41640e
|
7
|
+
data.tar.gz: ede8a0dee97e2c33ddb78314bf4004ab8e785cf6b761cb7b9aea2c1ce03e30d7bbc88b7c0dfc0eeca96c5ac23b013f767b062f415eb3d2ed6608da600fd76554
|
data/bin/quran-audio
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
case ARGV[0]
|
6
|
-
when "pull"
|
7
|
-
Process.spawn File.join(libexec, "pull"), *ARGV[1..]
|
4
|
+
def wait
|
8
5
|
Process.wait
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
rescue Interrupt
|
7
|
+
retry
|
8
|
+
end
|
9
|
+
|
10
|
+
def main(argv)
|
11
|
+
libexec = File.realpath File.join(__dir__, "..", "libexec", "quran-audio")
|
12
|
+
case argv[0]
|
13
|
+
when "pull"
|
14
|
+
Process.spawn File.join(libexec, "pull"), *ARGV[1..]
|
15
|
+
Process.wait
|
16
|
+
when "ls"
|
17
|
+
Process.spawn File.join(libexec, "ls"), *ARGV[1..]
|
18
|
+
Process.wait
|
19
|
+
else
|
20
|
+
warn "Usage: quran-audio [COMMAND] [OPTIONS]\n\n" \
|
21
|
+
"Commands:\n" \
|
22
|
+
" pull Pull MP3 files from everyayah.com\n" \
|
23
|
+
" ls List reciters\n" \
|
24
|
+
end
|
25
|
+
rescue Interrupt
|
26
|
+
wait
|
17
27
|
end
|
28
|
+
main(ARGV)
|
@@ -16,6 +16,14 @@ module Quran::Audio
|
|
16
16
|
|
17
17
|
def run
|
18
18
|
summary(recitations[recitation])
|
19
|
+
start(surahs)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :http
|
25
|
+
|
26
|
+
def start(surahs)
|
19
27
|
surahs.each do |surah|
|
20
28
|
1.upto(sizeof[surah]) do |ayah|
|
21
29
|
mp3 = MP3.new(recitation:, surah:, ayah:, bitrate:)
|
@@ -27,20 +35,16 @@ module Quran::Audio
|
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
|
-
private
|
31
|
-
|
32
|
-
attr_reader :http
|
33
|
-
|
34
38
|
def pull(mp3, delay, interrupt: false)
|
35
39
|
res = http.get(mp3.remote_path)
|
36
40
|
write(mp3, res, interrupt:)
|
37
41
|
sleep(delay)
|
38
42
|
rescue Interrupt
|
39
|
-
line.end.rewind.print("
|
43
|
+
line.end.rewind.print("SIGINT: exiting cleanly, please wait").end
|
40
44
|
pull(mp3, delay, interrupt: true)
|
41
45
|
rescue SocketError, SystemCallError, Net::OpenTimeout => e
|
42
46
|
line.end.rewind.print("#{e.class}: retry")
|
43
|
-
interrupt ?
|
47
|
+
interrupt ? abort! : pull(mp3, delay)
|
44
48
|
end
|
45
49
|
|
46
50
|
def write(mp3, res, interrupt:)
|
@@ -48,9 +52,10 @@ module Quran::Audio
|
|
48
52
|
when Net::HTTPOK
|
49
53
|
mkdir_p File.dirname(mp3.local_path)
|
50
54
|
File.binwrite(mp3.local_path, res.body)
|
51
|
-
|
55
|
+
abort! if interrupt
|
52
56
|
else
|
53
|
-
|
57
|
+
line.end.print("error: unexpected response (#{res.class})")
|
58
|
+
abort!
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
@@ -58,7 +63,7 @@ module Quran::Audio
|
|
58
63
|
line
|
59
64
|
.rewind
|
60
65
|
.print("Recitation".ljust(12), r.name).end
|
61
|
-
.print("Directory".ljust(12), format(r.
|
66
|
+
.print("Directory".ljust(12), format(r.destdir, sharedir: dir.sharedir))
|
62
67
|
.end.end
|
63
68
|
end
|
64
69
|
|
@@ -69,5 +74,9 @@ module Quran::Audio
|
|
69
74
|
def recitations
|
70
75
|
@recitations ||= Ryo.from_json(path: File.join(dir.datadir, "recitations.json"))
|
71
76
|
end
|
77
|
+
|
78
|
+
def abort!
|
79
|
+
throw(:abort, 1)
|
80
|
+
end
|
72
81
|
end
|
73
82
|
end
|
data/lib/quran/audio/mp3.rb
CHANGED
@@ -22,7 +22,7 @@ module Quran::Audio
|
|
22
22
|
# Returns the path to an MP3 file on a remote HTTP server
|
23
23
|
def remote_path
|
24
24
|
filename = [surah.to_s.rjust(3, "0"), ayah.to_s.rjust(3, "0"), ".mp3"].join
|
25
|
-
File.join format(recitation.
|
25
|
+
File.join format(recitation.path, bitrate:), filename
|
26
26
|
end
|
27
27
|
|
28
28
|
##
|
@@ -30,7 +30,7 @@ module Quran::Audio
|
|
30
30
|
# Returns the path to an MP3 file on disk
|
31
31
|
def local_path
|
32
32
|
File.join(
|
33
|
-
format(recitation.
|
33
|
+
format(recitation.destdir, sharedir:),
|
34
34
|
surah.to_s,
|
35
35
|
"#{ayah}.mp3"
|
36
36
|
)
|
data/libexec/quran-audio/pull
CHANGED
data/share/quran-audio/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v0.3.
|
1
|
+
v0.3.3
|
@@ -4,23 +4,23 @@
|
|
4
4
|
"origin": "Kuwait",
|
5
5
|
"available_bitrates": [128, 64],
|
6
6
|
"default_bitrate": 128,
|
7
|
-
"
|
8
|
-
"
|
7
|
+
"path": "/data/Alafasy_%{bitrate}kbps/",
|
8
|
+
"destdir": "%{sharedir}/mp3/alafasy/"
|
9
9
|
},
|
10
10
|
"alajmi": {
|
11
11
|
"name": "Ahmad bin Ali Al-Ajmi",
|
12
12
|
"origin": "Saudi Arabia",
|
13
13
|
"available_bitrates": [128],
|
14
14
|
"default_bitrate": 128,
|
15
|
-
"
|
16
|
-
"
|
15
|
+
"path": "/data/ahmed_ibn_ali_al_ajamy_%{bitrate}kbps/",
|
16
|
+
"destdir": "%{sharedir}/mp3/alajmi/"
|
17
17
|
},
|
18
18
|
"yassin": {
|
19
19
|
"name": "Sahl Yassin",
|
20
20
|
"origin": "Saudi Arabia",
|
21
21
|
"available_bitrates": [128],
|
22
22
|
"default_bitrate": 128,
|
23
|
-
"
|
24
|
-
"
|
23
|
+
"path": "/data/Sahl_Yassin_%{bitrate}kbps/",
|
24
|
+
"destdir": "%{sharedir}/mp3/yassin/"
|
25
25
|
}
|
26
26
|
}
|