commit 09670939205593e7a4b13baee641fdb7b196b4a3 Author: filip Date: Sat Feb 13 18:36:45 2021 +0100 first commit diff --git a/make_all.m3u.py b/make_all.m3u.py new file mode 100755 index 0000000..cb6d427 --- /dev/null +++ b/make_all.m3u.py @@ -0,0 +1,6 @@ +import glob +f = open("all.m3u", "w") +for file in glob.iglob("/home/pi/radio_project/sounds/*"): + f.write(file) + f.write("\n") +f.close() diff --git a/make_m3u.py b/make_m3u.py new file mode 100755 index 0000000..fcb93d0 --- /dev/null +++ b/make_m3u.py @@ -0,0 +1,16 @@ +#! python3 +import glob +m3u = input("Filename> ") +m3u = m3u + ".m3u" +f = open(m3u, "w") + +for file in glob.iglob("/home/pi/radio_project/sounds/*"): + print(file + ": Do you want to add this?") + yn = input("y/n> ") + yn = str(yn) + if yn == "y": + f.write(file) + f.write("\n") + if yn == "n": + pass +f.close() diff --git a/pifm b/pifm new file mode 100755 index 0000000..8dbd9cc Binary files /dev/null and b/pifm differ diff --git a/radio.py b/radio.py new file mode 100755 index 0000000..84225bc --- /dev/null +++ b/radio.py @@ -0,0 +1,32 @@ +#William, hvis du redigerer denne: ikke legg til norske symboler det fungerer ikke + +import os, glob + +print("Use python3") +playlist = "/home/pi/radio_project/all.m3u" +playlist = input("Playlist file> ") +station_name = "105FM" +station_id = "BEEF" #hex number 0123456789ABCDEF use uppercase +frequency = "105" #in MHZ float stored as string; do not change var type + +#WARNING! WARNING!: Do not set PS aka: program type to 30 or 31. 30 and 31 are for emergency alert system broadcasts +program_type = "9" #MUST NOT be 30 or 31. See above comment + +def m3u(playlist): + with open(playlist) as f: + lines = f.read().splitlines() + print(lines) + return lines + +while True: + for filename in m3u(playlist): + songname = filename.replace("/home/pi/radio_project/sounds/", "") + songname = songname.replace(".wav", "") + songname = songname.replace(".mp3", "") + cmd_to_execute = "sox \"" + filename + "\" -t wav - | /home/pi/radio_project/pifm --freq " + frequency + " --pi " + station_id + " --audio - --ps " + station_name + " --rt \"" + songname + "\" --pty " + program_type + " --power 0 --wait 0" + print("=================================") + print("Spiller av: ") + print(songname) + print(cmd_to_execute) + print("=================================") + os.system(cmd_to_execute)