6161 "tarhim.mp3" : "Tarhim 1" ,
6262}
6363
64+ # Pad naar de sounds map (www/sounds/ in de repo = /config/www/sounds/ op HA)
65+ _SOUNDS_DIR = "/config/www/sounds"
6466
6567
68+ def _format_sound_label (filename : str ) -> str :
69+ """Convert filename to readable label.
70+ 01-adhan.mp3 -> Adhan 01
71+ 01-adhan-fajr.mp3 -> Adhan Fajr 01
72+ 01-jingle.mp3 -> Jingle 01
73+ 01-tarhim.mp3 -> Tarhim 01
74+ """
75+ import re
76+ name = filename .replace ('.mp3' , '' )
77+ parts = re .split (r'[-_]' , name )
78+ numbers = [p for p in parts if p .isdigit ()]
79+ words = [p .capitalize () for p in parts if not p .isdigit ()]
80+ num = numbers [- 1 ] if numbers else ""
81+ if words and num :
82+ return f"{ ' ' .join (words )} { num } "
83+ return name .replace ('-' , ' ' ).replace ('_' , ' ' ).title ()
6684
67- def get_tarhim_sounds ():
85+
86+ def get_tarhim_sounds () -> dict :
6887 """Scan sounds folder for tarhim MP3s."""
6988 import os
70- sounds_path = os .path .join (os .path .dirname (__file__ ), "sounds" )
71- sounds = {}
89+ result = {}
7290 try :
73- with os .scandir (sounds_path ) as entries :
91+ with os .scandir (_SOUNDS_DIR ) as entries :
7492 for entry in sorted (entries , key = lambda e : e .name ):
7593 if entry .name .endswith (".mp3" ) and "tarhim" in entry .name .lower ():
76- label = entry .name .replace (".mp3" , "" ).replace ("-" , " " ).title ()
77- sounds [entry .name ] = label
94+ result [entry .name ] = _format_sound_label (entry .name )
7895 except Exception :
7996 pass
80- return sounds if sounds else {"01-tarhim.mp3" : "Tarhim 1 " }
97+ return result if result else {"01-tarhim.mp3" : "Tarhim 01 " }
8198
8299
83- def get_fajr_sounds ():
100+ def get_fajr_sounds () -> dict :
84101 """Scan sounds folder for fajr MP3s."""
85102 import os
86- sounds_path = os .path .join (os .path .dirname (__file__ ), "sounds" )
87- sounds = {}
103+ result = {}
88104 try :
89- for f in sorted (os .listdir (sounds_path )):
105+ for f in sorted (os .listdir (_SOUNDS_DIR )):
90106 if f .endswith (".mp3" ) and "fajr" in f .lower ():
91- label = f .replace (".mp3" , "" ).replace ("-" , " " ).title ()
92- sounds [f ] = label
107+ result [f ] = _format_sound_label (f )
93108 except Exception :
94109 pass
95- return sounds if sounds else {"01-01- adhan-fajr.mp3" : "Adhan Fajr 1 " }
110+ return result if result else {"01-adhan-fajr.mp3" : "Adhan Fajr 01 " }
96111
97112
98- def get_day_sounds ():
113+ def get_day_sounds () -> dict :
99114 """Scan sounds folder for day adhan MP3s."""
100115 import os
101- sounds_dir = "/config/www/nida/sounds"
102116 result = {}
103117 try :
104- for f in sorted (os .listdir (sounds_dir )):
105- if (f .endswith ('.mp3' ) and 'adhan' in f .lower ()
118+ for f in sorted (os .listdir (_SOUNDS_DIR )):
119+ if (f .endswith ('.mp3' )
120+ and 'adhan' in f .lower ()
106121 and 'fajr' not in f .lower ()
107122 and 'tarhim' not in f .lower ()
108123 and 'jingle' not in f .lower ()
@@ -112,6 +127,33 @@ def get_day_sounds():
112127 pass
113128 return result if result else {"01-adhan.mp3" : "Adhan 01" }
114129
130+
131+ def get_suhoor_sounds () -> dict :
132+ """Scan sounds folder for suhoor MP3s."""
133+ import os
134+ result = {}
135+ try :
136+ for f in sorted (os .listdir (_SOUNDS_DIR )):
137+ if f .endswith ('.mp3' ) and 'suhoor' in f .lower ():
138+ result [f ] = _format_sound_label (f )
139+ except Exception :
140+ pass
141+ return result if result else {"01-suhoor.mp3" : "Suhoor 01" }
142+
143+
144+ def get_jingle_sounds () -> dict :
145+ """Scan sounds folder for jingle MP3s."""
146+ import os
147+ result = {}
148+ try :
149+ for f in sorted (os .listdir (_SOUNDS_DIR )):
150+ if f .endswith ('.mp3' ) and 'jingle' in f .lower ():
151+ result [f ] = _format_sound_label (f )
152+ except Exception :
153+ pass
154+ return result
155+
156+
115157# Pre-adhan reminders
116158CONF_REMINDER_1_ENABLED = "reminder_1_enabled"
117159CONF_REMINDER_1_MINUTES = "reminder_1_minutes"
@@ -149,49 +191,4 @@ def get_day_sounds():
149191 "id" : "[prayer] akan tiba dalam [minutes] menit" ,
150192 "ur" : "[minutes] منٹ میں [prayer] کا وقت ہوگا" ,
151193 "fa" : "تا [minutes] دقیقه دیگر وقت نماز [prayer] است" ,
152- }
153-
154- def _format_sound_label (filename : str ) -> str :
155- """Convert filename to readable label.
156- 01-adhan.mp3 -> Adhan 01
157- 01-adhan-fajr.mp3 -> Adhan Fajr 01
158- 01-jingle.mp3 -> Jingle 01
159- 01-tarhim.mp3 -> Tarhim 01
160- """
161- import re
162- name = filename .replace ('.mp3' , '' )
163- parts = re .split (r'[-_]' , name )
164- numbers = [p for p in parts if p .isdigit ()]
165- words = [p .capitalize () for p in parts if not p .isdigit ()]
166- # Gebruik laatste getal als versienummer
167- num = numbers [- 1 ] if numbers else ""
168- if words and num :
169- return f"{ ' ' .join (words )} { num } "
170- return name .replace ('-' , ' ' ).replace ('_' , ' ' ).title ()
171-
172- def get_suhoor_sounds () -> dict :
173- """Get all suhoor MP3 files."""
174- import os
175- sounds_dir = "/config/www/nida/sounds"
176- result = {}
177- try :
178- for f in sorted (os .listdir (sounds_dir )):
179- if f .endswith ('.mp3' ) and 'suhoor' in f .lower ():
180- result [f ] = _format_sound_label (f )
181- except Exception :
182- pass
183- return result if result else {"01-suhoor.mp3" : "Suhoor 01" }
184-
185- def get_jingle_sounds () -> dict :
186- """Get all jingle MP3 files."""
187- import os
188- sounds_dir = "/config/www/nida/sounds"
189- result = {}
190- try :
191- for f in sorted (os .listdir (sounds_dir )):
192- if f .endswith ('.mp3' ) and 'jingle' in f .lower ():
193- result [f ] = _format_sound_label (f )
194- except Exception :
195- pass
196- return result
197-
194+ }
0 commit comments