diff --git a/config.py b/config.py index c0d924e84e19437754805b6a8f40e30e09a4011b..4540550779724692c78c1ea33a5edec12841088f 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,11 @@ debug = True filesExtension = ".wav" blankPauseDuration = 0 -musicMinIntroDelay = 10 -musicMaxIntroDelay = 20 +musicMinIntroDelay = 5 +musicMaxIntroDelay = 15 introFolder = "intro" +adsProbability = 0.25 +newsProbability = 0.25 # Regex idPattern = "((id)|(ID))_([0-9]){2}" @@ -14,7 +16,8 @@ musicPatten = "^(?:(?!(" + idPattern + "|" + monoSoloPattern + "|" + generalPatt musicIntro = "REPLACEMEWITHMSUICTITLE_([0-9]){2}" # Radio specific -musicPatterns = ["ID, GENERAL, (MUSIC, INTRO)", "ID, (MUSIC, INTRO)", "GENERAL, (MUSIC, INTRO)", - "ID, GENERAL, (MUSIC, INTRO)"] +musicPatterns = ["ID, GENERAL, MUSIC", "ID, MUSIC", "GENERAL, MUSIC", + "ID, GENERAL, MUSIC"] -adsAndNewsPatterns = ["AD, AD, NEWS", "NEWS", "MONO_SOLO, AD", "AD, MONO_SOLO", "MONO_SOLO, NEWS", "NEWS, MONO_SOLO"] +adsAndNewsPatterns = ["AD, AD, NEWS", "AD, AD", "NEWS", "MONO_SOLO, AD", "AD, MONO_SOLO", "MONO_SOLO, NEWS", + "NEWS, MONO_SOLO"] diff --git a/defs.py b/defs.py index 6fcb44109c12cd0416b24b1601a66af477e7a453..6d6f2e4c3cf64d05f09ab4f7a493bb5071bd0183 100644 --- a/defs.py +++ b/defs.py @@ -1,4 +1,5 @@ import os +import random import re import time import vlc @@ -50,3 +51,52 @@ def getMusicIntroFiles(filesPath, musicName): audioFiles.append(filesPath + "/" + file) return audioFiles + + +def playSoundWithDelayedSecondSound(firstSound, secondSound): + delay = random.randint(config.musicMinIntroDelay, config.musicMaxIntroDelay) + + if config.debug: + print("Playing: " + firstSound + " and " + secondSound + " with a delay of " + str(delay) + " seconds") + + instances = [vlc.Instance(), vlc.Instance()] + players = [instances[0].media_player_new(), instances[1].media_player_new()] + + # We set the first sound + players[0].set_media(instances[0].media_new(firstSound)) + + # We set the second sound + players[1].set_media(instances[1].media_new(secondSound)) + + # We will play the first sound + players[0].play() + + # We wait + time.sleep(delay) + + # We will play the second sound + players[1].play() + + # We lower the volume of the first sound + # players[0].audio_set_volume(50) + # players[1].audio_set_volume(100) + + # We will wait for the second sound to finish + Ended = 6 + current_state = players[1].get_state() + while current_state != Ended: + current_state = players[1].get_state() + + if config.debug: + print("Done playing Intro: " + secondSound) + + # We will now raise the volume of the first sound + players[0].audio_set_volume(100) + + # We will wait for the first sound to finish + current_state = players[0].get_state() + while current_state != Ended: + current_state = players[0].get_state() + + if config.debug: + print("Done playing Music: " + firstSound) diff --git a/radio-adverts/mono_tv_ad_rehab_01/0x0077D12B.wav b/radio-adverts/mono_tv_ad_rehab_01/0x0077D12B.wav deleted file mode 100644 index d8ff9a871b3f6cbf3820a9be3efcb41926907c87..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_ad_rehab_01/0x0077D12B.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_ad_tourism_01/0x0F62EB2D.wav b/radio-adverts/mono_tv_ad_tourism_01/0x0F62EB2D.wav deleted file mode 100644 index ce9c227e07432674772c00f5c61b6eff8731129a..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_ad_tourism_01/0x0F62EB2D.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_ad_whiz_01/0x07040695.wav b/radio-adverts/mono_tv_ad_whiz_01/0x07040695.wav deleted file mode 100644 index 1fc56a8f243a614e2f780a90b3db35cc85db26f5..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_ad_whiz_01/0x07040695.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_bright_mrhd_01/0x19568703.wav b/radio-adverts/mono_tv_bright_mrhd_01/0x19568703.wav deleted file mode 100644 index c2359557b0b60b6c3ed988abc7a9191f9f969933..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_bright_mrhd_01/0x19568703.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_bright_prb_01/0x1D8E02C2.wav b/radio-adverts/mono_tv_bright_prb_01/0x1D8E02C2.wav deleted file mode 100644 index fc8f2f12836b685c2dd6ae0c6fa8f02eef4550eb..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_bright_prb_01/0x1D8E02C2.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_bright_rsr_01/0x14A68640.wav b/radio-adverts/mono_tv_bright_rsr_01/0x14A68640.wav deleted file mode 100644 index 99bf79cd07828dd57103f59c19b87ea7247025c0..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_bright_rsr_01/0x14A68640.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_mrhd_01/0x15DF8F7E.wav b/radio-adverts/mono_tv_mrhd_01/0x15DF8F7E.wav deleted file mode 100644 index cffeefcf9b4f23f90f0346017a63a9adaaa1ce6f..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_mrhd_01/0x15DF8F7E.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_prb_01/0x07740AF4.wav b/radio-adverts/mono_tv_prb_01/0x07740AF4.wav deleted file mode 100644 index 86206d6ad69db7e546b6bdaf309df2b1045c26f4..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_prb_01/0x07740AF4.wav and /dev/null differ diff --git a/radio-adverts/mono_tv_rsr_01/0x126ACDBD.wav b/radio-adverts/mono_tv_rsr_01/0x126ACDBD.wav deleted file mode 100644 index 9618aad94ceea0bd8a03df527643361d51f7ccc1..0000000000000000000000000000000000000000 Binary files a/radio-adverts/mono_tv_rsr_01/0x126ACDBD.wav and /dev/null differ diff --git a/radio.py b/radio.py index 30bdef475d4b28de866b63c66595194cc7032c29..48bb33d1cb1f3a2f0ef09903bd5303639271e2fd 100644 --- a/radio.py +++ b/radio.py @@ -3,41 +3,86 @@ import random import config import defs + class Radio: - filesPath = "" + radioPath = "" + adsPath = "" + newsPath = "" radioName = "" ids = [] monoSolos = [] generals = [] musics = [] + ads = [] + news = [] def __init__(self, radioName): - self.filesPath = os.getcwd() + "/" + radioName + self.radioPath = os.getcwd() + "/" + radioName + self.adsPath = os.getcwd() + "/radio-adverts" + self.newsPath = os.getcwd() + "/radio-news" self.radioName = radioName if radioName == "non-stop-pop": - print("Playing: Non Stop Pop") - self.ids = defs.getFilesByRegex(self.filesPath, config.idPattern) - self.monoSolos = defs.getFilesByRegex(self.filesPath, config.monoSoloPattern) - self.generals = defs.getFilesByRegex(self.filesPath, config.generalPattern) - self.musics = defs.getFilesByRegex(self.filesPath, config.musicPatten) + self.ids = defs.getFilesByRegex(self.radioPath, config.idPattern) + self.monoSolos = defs.getFilesByRegex(self.radioPath, config.monoSoloPattern) + self.generals = defs.getFilesByRegex(self.radioPath, config.generalPattern) + self.musics = defs.getFilesByRegex(self.radioPath, config.musicPatten) + self.ads = defs.getFilesByRegex(self.adsPath, ".*") + self.news = defs.getFilesByRegex(self.newsPath, ".*") - def play(self): + def startRadio(self): while True: - defs.playSound(random.choice(self.ids)) - defs.playSound(random.choice(self.generals)) - music = random.choice(self.musics) + # Check if we will play an ad or news + if random.random() < config.adsProbability: + if config.debug: + print("Playing ads and news") + self.playAdAndNews() + + if config.debug: + print("Playing music") + self.playMusic() + + def playMusic(self): + music = random.choice(self.musics) + musicName = music.split("/")[-1].split(".")[0] + + # We choose random pattern + pattern = random.choice(config.musicPatterns).split(", ") + + if config.debug: + print("Pattern: " + str(pattern)) + + # We will now play the pattern + for item in pattern: + if item == "ID": + defs.playSound(random.choice(self.ids)) + elif item == "GENERAL": + defs.playSound(random.choice(self.generals)) + elif item == "MONO_SOLO": + defs.playSound(random.choice(self.monoSolos)) + elif item == "MUSIC": + defs.playSoundWithDelayedSecondSound(music, + random.choice(defs.getMusicIntroFiles(self.radioPath, musicName))) + + def playAdAndNews(self): + # We choose random pattern + pattern = random.choice(config.adsAndNewsPatterns).split(", ") + + if config.debug: + print("Pattern: " + str(pattern)) - # Get all after last / and before last . - musicName = music.split("/")[-1].split(".")[0] - print("Playing: " + musicName) - defs.playSound(random.choice(defs.getMusicIntroFiles(self.filesPath, musicName))) - defs.playSound(music) - defs.playSound(random.choice(self.monoSolos)) + # We will now play the pattern + for item in pattern: + if item == "AD": + defs.playSound(random.choice(self.ads)) + elif item == "NEWS": + defs.playSound(random.choice(self.news)) + elif item == "MONO_SOLO": + defs.playSound(random.choice(self.monoSolos)) radiosStations = ["non-stop-pop"] chosenRadio = random.choice(radiosStations) radio = Radio(chosenRadio) -radio.play() \ No newline at end of file +radio.startRadio()