From 2445bd1e838311744c4fb230130b2b092012c60a Mon Sep 17 00:00:00 2001 From: zuckerberg <5-zuckerberg@users.noreply.git.neet.dev> Date: Mon, 7 Jun 2021 18:49:52 -0400 Subject: [PATCH] don't switch to null src --- radio.py | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/radio.py b/radio.py index 5dc17d8..843b1c5 100644 --- a/radio.py +++ b/radio.py @@ -1,7 +1,6 @@ import downloader import uploader import transcoder -import nullsrc from time import sleep from flask import Flask, request from queue import Queue @@ -14,53 +13,36 @@ class Radio(object): self.transcoder = None self.uploader = uploader.Uploader() self.playingUrl = None - self.nullsrc = False self.queue = Queue() # plays the next song in the queue def play(self): - self.stopPlaying() - self.nullsrc = False self.playingUrl = self.queue.get() self.downloader = downloader.Downloader(self.playingUrl, self.downloadFinished) self.transcoder = transcoder.Transcoder(self.downloader) self.uploader.setUpstream(self.transcoder) - def playNullSrc(self): - self.stopPlaying() - self.nullsrc = True - self.playingUrl = None - self.downloader = nullsrc.NullSrc() - self.transcoder = transcoder.Transcoder(self.downloader) - self.uploader.setUpstream(self.transcoder) - def isPlaying(self): return not self.playingUrl is None # blocks the caller until the uploader and trancoder recieve no more data # if this is a livestream, the end might never come! def blockUntilDonePlaying(self): - if not self.nullsrc: - self.transcoder.listener.blockUntilEmpty() - self.uploader.listener.blockUntilEmpty() + self.transcoder.listener.blockUntilEmpty() + self.uploader.listener.blockUntilEmpty() # add to queue or play right now if queue is empty def addToQueue(self,url): self.queue.put(url) def playIfSongAvailable(self): - if not self.isPlaying(): - if self.queue.empty(): - self.playNullSrc() - else: - self.play() + if not self.isPlaying() and not self.queue.empty(): + self.play() # stops playing immediately and cleans up def stopPlaying(self): - if not self.downloader is None: - self.downloader.stop() - if not self.transcoder is None: - self.transcoder.stop() + self.downloader.stop() + self.transcoder.stop() self.playingUrl = None # downloader callback function, called when the downloader is finished