forked from under0tech/conversation-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grabber.py
25 lines (20 loc) · 819 Bytes
/
grabber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import time
import requests
def grabber_go(
max_time, prefix,
broadcastify_url,
output_folder,
stop_command):
while not stop_command.is_set():
start_time = time.time()
response = requests.get(broadcastify_url, stream=True)
with open(f'{output_folder}/{prefix}_{start_time}.mp3', 'wb') as f:
try:
for block in response.iter_content(512):
f.write(block)
if (time.time() - start_time) > max_time or stop_command.is_set():
break
except Exception as e:
print(f"An error occurred: {e}")
stopped_time = time.strftime("%H:%M:%S, %Y, %d %B", time.localtime())
print(f'thread \033[93mGrabber\033[0m, DONE at {stopped_time}.')