getnetradio/main.py

87 lines
1.7 KiB
Python
Raw Normal View History

2022-10-06 10:55:32 +00:00
from os import listdir,system as ss
from time import sleep
2022-10-06 17:03:49 +00:00
import subprocess
2022-10-06 10:55:32 +00:00
#Theards
import threading
#Time&Date
from datetime import date
import time
2022-10-06 17:03:49 +00:00
#DEV-MODE#
dev = False
##########
2022-10-06 10:55:32 +00:00
#RADIO STATIONS
2022-10-06 17:03:49 +00:00
#SET TELEGRAM IN upload()
2022-10-06 10:55:32 +00:00
rad = [
"https://nashe1.hostingradio.ru:18000/nashepunks.mp3",
2022-10-06 17:03:49 +00:00
"https://ic7.101.ru:8000/v1_1 -O nrj.mp3",
2022-10-06 11:16:21 +00:00
"https://emgregion.hostingradio.ru:8064/moscow.retrofm.mp3 -O retrofm.mp3"
2022-10-06 10:55:32 +00:00
]
#TIME(IN MINUTES)
2022-10-06 17:03:49 +00:00
tw = 30
if dev == False:
wait = tw*60
else:
wait = tw
2022-10-06 10:55:32 +00:00
#Save location
prefix = "~/ARCHIVE/"
###
2022-10-06 17:03:49 +00:00
#Check bitrate and upload
def tg(i,tim,prefix,group):
ss("rm t")
ss("ffprobe "+i+" 2> t")
bit = int(subprocess.check_output("cat t | grep bitrate | grep Duration | awk -F \" \" '{print $6}'", shell=True))
if bit != 128:
ss("lame --mp3input -b 128 "+i+" tt")
ss("mv tt "+i)
ss("telegram-upload "+i+" --to "+group+" --caption "+tim)
ss("mkdir "+prefix+tim)
ss("mv "+i+" "+prefix+tim+"/")
2022-10-06 10:55:32 +00:00
#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:
2022-10-06 17:03:49 +00:00
#HERE SET YOUR TELEGRAM AND MP3
2022-10-06 10:55:32 +00:00
if i == "nashepunks.mp3":
2022-10-06 17:03:49 +00:00
tg(i,tim,prefix,"https://t.me/getnetradio_nashe0punk")
2022-10-06 10:55:32 +00:00
elif i == "nrj.mp3":
2022-10-06 17:03:49 +00:00
tg(i,tim,prefix,"https://t.me/getnetradio_nrj")
2022-10-06 11:16:21 +00:00
elif i == "retrofm.mp3":
2022-10-06 17:03:49 +00:00
tg(i,tim,prefix,"https://t.me/getnetradio_retrofm")
2022-10-06 10:55:32 +00:00
else:
pass
while True:
#Download function
def rad_down(ch):
ss("wget "+i)
#Run download
for i in rad:
th = threading.Thread(target=rad_down, args=(i,))
th.start()
#Wait
sleep(wait)
#Stop download
ss("killall wget")
#Upload
upload()
2022-10-06 17:03:49 +00:00
if dev == True:
break