Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit e74882c

Browse files
committed
Enhance broadcasting features: add environment variables for upload and backup broadcasts; update notification links in Firebase notifications
1 parent f18c4d5 commit e74882c

5 files changed

Lines changed: 48 additions & 11 deletions

File tree

dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ENV PORT=5054
1515
ENV TZ="America/Guatemala"
1616
ENV PYTHONUNBUFFERED=1
1717
ENV MINIMUM_RECORDING_LENGTH="10"
18+
ENV UPLOAD_BROADCAST="true"
19+
ENV BACKUP_BROADCAST="true"
1820
ENV LOG_SERVER_HOST="0.0.0.0"
1921
ENV LOG_SERVER_PORT="5054"
2022
ENV NOTIFICATION_DELAY="2"

filebrowser_uploader.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
load_dotenv()
1010

11+
UPLOAD_BROADCAST: bool = os.getenv("UPLOAD_BROADCAST", "true").lower() == "true"
12+
BACKUP_BROADCAST: bool = os.getenv("BACKUP_BROADCAST", "true").lower() == "true"
13+
1114
# Database settings
1215
db_settings = {
1316
"host": os.getenv("POSTGRES_HOST"),
@@ -138,12 +141,13 @@ async def upload(
138141
except Exception as e:
139142
raise RuntimeError(f"Unexpected error while uploading file: {str(e)}")
140143

141-
pool = await asyncpg.create_pool(**db_settings)
142144
download_url = f"https://broadcasting.hbni.net/play_recording/{quote(file_name)}"
143-
await insert_data_to_db(
144-
pool, file_name, download_url, date, description, length, host, share_hash
145-
)
146-
await pool.close()
145+
if UPLOAD_BROADCAST:
146+
pool = await asyncpg.create_pool(**db_settings)
147+
await insert_data_to_db(
148+
pool, file_name, download_url, date, description, length, host, share_hash
149+
)
150+
await pool.close()
147151

148152

149153
if __name__ == "__main__":

firebase_android_notification.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,38 @@ def _build_common_message(
3939
title: str,
4040
body: str,
4141
topic: str = "news",
42-
link: str = "https://hbniaudio.hbni.net/",
42+
link: str = "https://broadcasting.hbni.net/events",
4343
):
4444
return {
4545
"message": {
4646
"topic": topic,
47-
"notification": {"title": title, "body": body},
48-
"data": {"link": link},
47+
"notification": {
48+
"title": title,
49+
"body": body,
50+
},
51+
"webpush": {
52+
"notification": {
53+
"title": title,
54+
"body": body,
55+
"icon": "/favicon.ico", # optional: your logo icon
56+
},
57+
"fcm_options": {
58+
"link": link,
59+
},
60+
},
61+
"data": {
62+
"link": link,
63+
},
4964
}
5065
}
5166

5267

68+
5369
def _build_override_message(
5470
title: str,
5571
body: str,
5672
topic: str = "news",
57-
link: str = "https://hbniaudio.hbni.net/",
73+
link: str = "https://broadcasting.hbni.net/events",
5874
):
5975
fcm_message = _build_common_message(title=title, body=body, topic=topic, link=link)
6076

@@ -80,7 +96,7 @@ def send_notification(title: str, body: str, link: str):
8096

8197

8298
def send_notification_to_dev(
83-
title: str, body: str, link: str = "https://hbniaudio.hbni.net/"
99+
title: str, body: str, link: str = "https://broadcasting.hbni.net/events"
84100
):
85101
override_message = _build_override_message(
86102
title=title, body=body, topic="developer", link=link

firebase_web_notification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def send_notification_to_topic(title, body, topic="broadcasts"):
1313
body=body,
1414
image="/static/logo.png",
1515
),
16+
data={"link": "https://broadcasting.hbni.net/events"},
1617
topic=topic,
1718
)
1819
response = messaging.send(message)

main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
load_dotenv()
3030

3131
FOLDER_LOCATION: str = os.path.abspath(os.getcwd()).replace("\\", "/")
32+
UPLOAD_BROADCAST: bool = os.getenv("UPLOAD_BROADCAST", "true").lower() == "true"
33+
BACKUP_BROADCAST: bool = os.getenv("BACKUP_BROADCAST", "true").lower() == "true"
34+
3235
db_settings = {
3336
"host": os.getenv("POSTGRES_HOST"),
3437
"port": int(os.getenv("POSTGRES_PORT", 5434)),
@@ -170,7 +173,18 @@ def convert_delta_time(self, duration: timedelta) -> str:
170173
)
171174

172175
def process_file(self):
173-
self.backup_stream(self.recording_file_name)
176+
if self.upload_callback and BACKUP_BROADCAST:
177+
self.backup_stream(self.recording_file_name)
178+
app_log.info(f"Backing up {self.recording_file_name}")
179+
self.upload_callback(
180+
self.recording_file_name.replace(".mp3", ".zip"),
181+
f"{FOLDER_LOCATION}/CURRENTLY_RECORDING/{self.recording_file_name.replace(".mp3", ".zip")}",
182+
self.host,
183+
self.description,
184+
self.starting_time.strftime("%B %d %A %Y %I_%M %p"),
185+
self.audio_file_length,
186+
)
187+
174188
app_log.info(f"Processing {self.recording_file_name}")
175189
remove_silence.remove_silence_everywhere(self.recording_file_path)
176190
self.audio_file_length = audio_file.get_audio_length(self.recording_file_path)

0 commit comments

Comments
 (0)