def set_tracks(self, tracks, page): """ Set tracks in menu :param tracks: list of tracks :param page: page number """ if tracks == None: return self.tracks = tracks items = {} start_index = TRACKS_PER_PAGE * (page - 1) end_index = start_index + TRACKS_PER_PAGE layout = GridLayout(self.bb) layout.set_pixel_constraints(TRACK_ROWS, TRACK_COLUMNS, 1, 1) constr = layout.get_next_constraints() fixed_height = int((constr.h * LABEL_HEIGHT_PERCENT) / 100.0) for i, a in enumerate(self.tracks[start_index:end_index]): state = State() state.name = a["title"] state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i state.fixed_height = fixed_height state.file_name = a["file_name"] items[state.name] = state self.set_items(items, 0, self.play_track, False)
def get_cd_drives(self, font_size, bb): """ Return the list of object representing CD drives :font_size: font size :return: list of CD drives info """ content = self.get_cd_drives_info() if not content: return None items = {} for cd in content: s = State() s.index = cd[0] s.name = cd[1] s.l_name = cd[1] s.file_type = FILE_CD_DRIVE s.icon_base = self.image_util.get_file_icon(s.file_type, "", icon_bb=bb, scale_factor=0.25) s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.fixed_height = int(font_size * 0.8) items[s.name] = s return items
def get_podcast_info_from_disk(self, index, podcast): """ Get the info of loaded podcast as State object :param index: podcast index :param podcast: podcast dictionary :return: podcast info as State object """ s = State() s.index = index s.name = podcast["name"] s.l_name = s.name s.url = podcast["url"] s.online = False s.description = podcast["summary"] s.fixed_height = int(self.podcast_button_font_size * 0.8) s.file_type = PODCASTS s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True try: img = os.path.join(self.config[PODCASTS_FOLDER], podcast["image"]) except: img = '' s.image_name = img s.icon_base = self.get_podcast_image(img, 0.5, 0.8, self.podcast_button_bb, False) self.summary_cache[s.url] = s return s
def get_episodes(self, podcast_url): """ Get podcast episodes :param podcast_url: podcast URL :return: dictionary with episodes """ try: podcast = self.summary_cache[podcast_url] podcast_image_url = podcast.image_name episodes = podcast.episodes return episodes except: pass episodes = [] rss = feedparser.parse(podcast_url) if rss == None: return episodes entries = rss.entries for i, entry in enumerate(entries): try: enclosure = entry.enclosures[0] except: continue s = State() s.index = i s.name = entry.title s.l_name = s.name s.url = getattr(enclosure, "href", None) if s.url == None: s.url = getattr(enclosure, "url", None) s.length = getattr(enclosure, "length", None) s.type = enclosure.type s.description = self.clean_summary(entry.summary) s.fixed_height = int(self.episode_button_font_size * 0.8) s.file_type = PODCASTS s.online = podcast.online s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.podcast_name = podcast.name s.podcast_url = podcast_url s.podcast_image_url = podcast_image_url episode_name = s.url.split("/")[-1] self.set_episode_icon(episode_name, self.episode_button_bb, s) episodes.append(s) self.summary_cache[podcast_url].episodes = episodes return episodes
def get_episodes_from_disk(self, podcast_url): """ Get podcast episodes from disk :param podcast_url: podcast URL :return: dictionary with episodes """ try: podcast = self.summary_cache[podcast_url] podcast_image_url = podcast.image_name episodes = podcast.episodes return episodes except: pass episodes = [] podcast = self.summary_cache[podcast_url] entries = [] for p in self.podcasts_json: if p["url"] == podcast_url: try: entries = p["episodes"] except: pass if len(entries) == 0: return [] for i, entry in enumerate(entries): s = State() s.index = i s.name = entry["name"] s.l_name = s.name s.file_name = entry["filename"] s.description = entry["summary"] s.fixed_height = int(self.episode_button_font_size * 0.8) s.file_type = PODCASTS s.online = podcast.online s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.podcast_url = podcast_url s.podcast_name = podcast.name s.url = "" s.podcast_image_url = podcast_image_url self.set_episode_icon(s.name, self.episode_button_bb, s, False) episodes.append(s) self.summary_cache[podcast_url].episodes = episodes return episodes
def get_podcast_info(self, index, podcast_url): """ Get podcast info as state object :param index: podcast index :param podcast_url: podcast url :return: podcast info as State object """ try: response = requests.get(podcast_url) if response.status_code == 404: return None rss = feedparser.parse(response.content) if rss and getattr(rss, "bozo_exception", None): return None except: return None s = State() s.index = index s.name = rss.feed.title s.l_name = s.name s.description = rss.feed.subtitle s.url = podcast_url s.online = True s.fixed_height = int(self.podcast_button_font_size * 0.8) s.file_type = PODCASTS s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True if 'image' in rss.feed and 'href' in rss.feed.image: img = rss.feed.image.href.strip() else: img = '' s.image_name = img s.icon_base = self.get_podcast_image(img, 0.48, 0.8, self.podcast_button_bb) self.summary_cache[s.url] = s return s