def is_visible(self): try: logger.info('Checking if player is visible') self.player_visible = self.player_driver.find_element_by_xpath( config('track_title_label')).is_displayed() logger.info(str(self.player_visible)) return self.player_visible except NoSuchElementException: return False
def _is_stopped(self): try: logger.info('Checking if player is paused') self.player_stopped = self.player_driver.find_element_by_xpath( config('play_pause_as_play')).is_displayed() logger.info(str(self.player_stopped)) return self.player_stopped except NoSuchElementException: return False
def _parse_seconds(self): # should get smth like '00:00 / 01:00' label = self._find_element(config('time_info_label')) time_parts = re.split(r'/', label.text) if len(time_parts) != 2: return current_time = time_parts[0].strip() max_time = time_parts[1].strip() self.current_play_seconds = text_to_seconds(current_time) self.max_play_seconds = text_to_seconds(max_time)
async def update_player(): if yt_player is not None and yt_player.is_visible(): now = arrow.now() hours = int(now.format('HH')) forbidden_to_play = hours >= int( config("hours_after")) or hours <= int(config("hours_until")) if forbidden_to_play and not yt_player.player_stopped: logger.info("It's forbidden to play now. Pressing pause") yt_player.press_pause() play_after = int(config("play_after")) should_play = play_after <= hours <= play_after + 1 if should_play and yt_player.player_stopped: logger.info("It's time to play. Pressing play and next") yt_player.press_play() yt_player.press_next() morning_sound_level = config("morning_sound_level") while int(yt_player.sound_level) > int(morning_sound_level): logger.info("Current sound is " + yt_player.sound_level + ". Lowering to " + morning_sound_level) yt_player.lower_sound() if player_message_id != 0: if yt_player.max_play_seconds == 0 and not forbidden_to_play: yt_player.press_next() msg = ' player was stuck, pressed next' logger.info(msg) send_error(msg) yt_player.parse() msg = yt_player.generate_message() try: logger.info('updating player info') await bot.edit_message_text(text=msg, chat_id=MY_CHAT_ID, message_id=player_message_id, reply_markup=markup) except MessageNotModified: pass
def find_elem(self, elem_name): return self.player_driver.find_element_by_xpath(config(elem_name))
def _parse_song_info(self): track_info = self._find_element(config('track_info_label')) info_text = track_info.get_attribute('title') self.current_song_info = info_text
def _parse_author(self): track_title = self._find_element(config('track_title_label')) self.current_track = str(track_title.text)
def _press_btn(self, btn_name, alert=True): logger.info('Pressing ' + btn_name) element = self._find_element(config(btn_name), alert) if element is not None: element.click()