text stringlengths 1 93.6k |
|---|
stream_player.audio_set_volume(volume)
|
adblock_player.audio_set_volume(volume)
|
stream_player.play()
|
# Big print statement
|
if station_name.startswith("http"):
|
print(
|
colors.GREEN + "\nYou are listening to: " + colors.ENDC +
|
colors.BOLD + station_name + colors.ENDC)
|
else:
|
print(
|
colors.GREEN + "\nYou are listening to: " + colors.ENDC +
|
colors.BOLD + station_name + colors.ENDC +
|
colors.GREEN + " at " + colors.ENDC +
|
colors.UNDERLINE + station_url + colors.ENDC)
|
print(colors.YELLOW + "-> Playback started! Ctrl+C to pause!" + colors.ENDC, end="")
|
# Length of the print above
|
oldTitle = " "*37
|
# States: 1 = playing, 2 = paused, 3 = blocking
|
state = 1
|
while True:
|
try:
|
if state == 1 or state == 3:
|
# Get the song title from VLC
|
stream_media.parse()
|
newTitle = stream_media.get_meta(12)
|
if not newTitle:
|
newTitle = ""
|
# If the title changed, process
|
if newTitle != oldTitle and newTitle != "":
|
if state == 3:
|
state = 1
|
adblock_player.stop()
|
stream_player.audio_set_volume(volume)
|
# Search if any of our blocked phrases are in the new title
|
for toCheck in config["Blocked Titles"]:
|
if toCheck.lower() in newTitle.lower():
|
state = 3
|
if state == 3:
|
# Sad fact: We cant .stop() the stream player,
|
# because it would stop us from getting new song titles.
|
# Instead, we have to silence it using .audio_set_volume(0).
|
# This may create additional overhead, but I am not aware of
|
# any better method to do this.
|
stream_player.audio_set_volume(0)
|
adblock_player.play()
|
print(
|
"\r" + " "*(13 + len(oldTitle))+ "\r" + # Clear the line
|
colors.YELLOW + "-> Blocked a title!" + colors.ENDC, end="")
|
oldTitle = newTitle
|
continue
|
print(
|
"\r" + " "*(13 + len(oldTitle))+ "\r" + # Clear the line
|
colors.GREEN + "Now playing: " + colors.ENDC +
|
colors.BOLD + newTitle + colors.ENDC, end="")
|
oldTitle = newTitle
|
time.sleep(1.5)
|
# A single Ctrl+C pauses the playback
|
except KeyboardInterrupt:
|
try:
|
# If we are playing or blocking, we are now paused.
|
# If we already are paused, we are now playing.
|
if state == 1:
|
stream_player.pause()
|
state = 2
|
elif state == 2:
|
state = 1
|
elif state == 3:
|
adblock_player.pause()
|
state = 2
|
# The pause handling
|
if state == 2:
|
print(
|
"\r" + " "*(13 + len(oldTitle)) + "\r" + # Clear the line
|
colors.YELLOW + "-> Press Ctrl+C again to exit!" + colors.ENDC, end="")
|
# Here we wait for a second signal to end the program...
|
time.sleep(2)
|
# ...and apparently no signal was received. This means we are just paused.
|
print(
|
"\r" + " "*30 + "\r" +
|
colors.YELLOW + "-> Playback paused! Ctrl+C to unpause!" + colors.ENDC, end="")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.