You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
getnetradio/main.py

78 lines
1.3 KiB

from os import listdir,system as ss
from time import sleep
#Theards
import threading
#Time&Date
from datetime import date
import time
#Config
import config
#Check bitrate and convert audio
from pydub import AudioSegment
from pydub.utils import mediainfo
#Import config
tw = int(config.time)
prefix = config.prefix
rad = config.radio
dev = bool(config.dev)
###
if dev == False:
wait = tw*60
else:
wait = tw
#Check bitrate and upload
def tg(i,tim,group):
bit = int(mediainfo(i)['bit_rate'])/1000
if bit > 128:
sound = AudioSegment.from_file(i)
sound.export("tt.mp3", format="mp3", bitrate="128k")
ss("mv tt.mp3 "+i)
ss("telegram-upload "+i+" --to "+group+" --caption "+tim)
ss("mkdir "+prefix+tim)
ss("mv "+i+" "+prefix+tim+"/")
#Upload in telegram
def upload():
today = date.today()
files = listdir()
#Set date&time
tim = today.strftime("%d.%m.%Y_"+time.strftime("%H:%M", time.localtime()))
for i in files:
if rad.get(i) == None:
pass
else:
print("SUCCESS")
tg(i,tim,rad[i][1])
#Download function
def rad_down(ch):
ss("wget "+ch)
while True:
#Run download
for i in rad:
th = threading.Thread(target=rad_down, args=(rad[i][0],))
th.start()
#Wait
sleep(wait)
#Stop download
ss("killall wget")
#Upload
upload()
if dev == True:
break