def __init__(self, data): PlayingMode.__init__(self, data.get('name')) self.repeat_pattern = DefaultRepeat() self.name = "DefaultMode " + data.get('name') self.content_provider = RandomFileProvider(False, data.get('musicSource')) self.speech_provider = RandomFileProvider(True, data.get('speechSource')) self.priority = 1 self.time_counter = 0 self._playing_time = 0 self.start_time = 0 self.is_playing = False
class DefaultMode(PlayingMode): last_speech = Properties.DEFAULT_SPEECH_COUNT def __init__(self, data): PlayingMode.__init__(self, data.get('name')) self.repeat_pattern = DefaultRepeat() self.name = "DefaultMode " + data.get('name') self.content_provider = RandomFileProvider(False, data.get('musicSource')) self.speech_provider = RandomFileProvider(True, data.get('speechSource')) self.priority = 1 self.time_counter = 0 self._playing_time = 0 self.start_time = 0 self.is_playing = False def next(self): PlayingMode.next(self) if DefaultMode.last_speech >= Properties.DEFAULT_SPEECH_COUNT: next_song = self.speech_provider.next() DefaultMode.last_speech = 0 else: next_song = self.content_provider.next() DefaultMode.last_speech += 1 return next_song def on_play(self): self.is_playing = True self.start_time = time.time() def on_stop(self): self.is_playing = False def invalidate(self): if self.is_playing: # TODO: Only Count Music. self.priority += (time.time() - self.start_time) self.start_time = time.time() def web(self): this = self class DefaultWeb(object): @cherrypy.expose def index(self): return "Hello World! from " + this.name return DefaultWeb
def __init__(self, name, source, rp): PlayingMode.__init__(self, name) self.repeat_pattern = rp self.name = "ShowMode " + str(name) self.priority = 1 self.queue = Queue.Queue() self.content_provider = RandomFileProvider(False, source)
class ShowMode(PlayingMode): def __init__(self, name, source, rp): PlayingMode.__init__(self, name) self.repeat_pattern = rp self.name = "ShowMode " + str(name) self.priority = 1 self.queue = Queue.Queue() self.content_provider = RandomFileProvider(False, source) def add_random(self): self.queue.put(self.content_provider.next()) def add_random_from(self, source): temp_provider = RandomFileProvider(False, source) self.queue.put(temp_provider.next()) def add_specific(self, path): self.queue.put(path) def on_stop(self): if self.queue.empty(): self.priority = 10000 else: self.priority = -1 def next(self): if not self.queue.empty(): return self.queue.get()
def next(self): year = datetime.now().year month = datetime.now().month day = datetime.now().day weekday = datetime.now().weekday() folder = self.source + "/" + str(year)+ "-" + str(month) + "-" + str(day) + "/" if self._is_folder_empty(folder): folder = self.source + "/" + str(year) + "-" + str(month) + "/" if self._is_folder_empty(folder): folder = self.source + "/" + weekday if self._is_folder_empty(folder): folder = self.source + "/yolo/" provider = RandomFileProvider(True, folder) return provider.next()
def add_random_from(self, source): temp_provider = RandomFileProvider(False, source) self.queue.put(temp_provider.next())