示例#1
0
    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
示例#2
0
    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
示例#3
0
文件: util.py 项目: Rucia1/Peppy
    def load_playlist(self, state, playlist_provider, rows, columns):
        """ Handle playlist
        
        :param state: state object defining playlist
        :param playlist_provider: provider
        :param rows: menu rows 
        :param columns: menu columns
        
        :return: playlist 
        """
        n = getattr(state, "file_name", None)
        if n == None:
            state.file_name = self.config[FILE_PLAYBACK][FILE_AUDIO]

        p = playlist_provider(state)

        if not p:
            return

        play_list = []

        for i, n in enumerate(p):
            s = State()
            s.index = i
            s.playlist_track_number = i
            s.file_name = n
            s.file_type = FILE_AUDIO
            s.url = state.folder + os.sep + n
            s.playback_mode = FILE_PLAYLIST
            play_list.append(s)

        return self.load_playlist_content(play_list, rows, columns)
示例#4
0
 def get_cd_tracks_summary(self, cd_drive_name):
     """ Get the list of CD tracks summaries
     
     :param cd_drive_name: CD drive name
     
     :return: CD tracks summaries
     """
     drive_id = self.get_cd_drive_id_by_name(cd_drive_name)
     names = self.get_cd_track_names(drive_id)
     if not names:
         return None
     
     items = []
     for id, cd in enumerate(names):
         s = State()
         s.index = id
         s.playlist_track_number = id
         s.name = cd
         s.l_name = s.name
         s.file_type = FILE_AUDIO
         s.playback_mode = FILE_AUDIO
         s.file_name = self.get_cd_track_url(cd_drive_name, id + 1)
         s.url = s.file_name       
         items.append(s)
         
     return items
示例#5
0
    def set_audio_file(self, new_track, s=None):
        """ Set new audio file
        
        :param new_track: True - new file
        "param s" button state
        """
        state = State()
        state.folder = PODCASTS_FOLDER

        if s.status == STATUS_LOADED:
            state.url = s.file_name
            state.original_url = s.url
        else:
            state.url = s.url

        self.config[PLAYER_SETTINGS][PAUSE] = False
        state.mute = self.config[PLAYER_SETTINGS][MUTE]
        state.pause = self.config[PLAYER_SETTINGS][PAUSE]
        state.file_type = FILE_AUDIO
        state.dont_notify = True
        state.source = FILE_AUDIO
        state.playback_mode = FILE_AUDIO
        state.status = s.status
        if hasattr(s, "file_name"):
            state.file_name = s.file_name
        source = None
        if s:
            source = getattr(s, "source", None)

        if new_track:
            tt = 0.0
        else:
            tt = self.config[PODCASTS][PODCAST_EPISODE_TIME]

        if (isinstance(tt, str) and len(tt) != 0) or (
                isinstance(tt, float) or
            (source and source == RESUME)) or isinstance(tt, int):
            state.track_time = tt

        self.time_control.slider.set_position(0)

        if self.file_button and self.file_button.components[
                1] and self.file_button.components[1].content:
            state.icon_base = self.file_button.components[1].content

        if s:
            if self.config[VOLUME_CONTROL][
                    VOLUME_CONTROL_TYPE] == VOLUME_CONTROL_TYPE_PLAYER:
                state.volume = s.volume
            else:
                state.volume = None

        if getattr(s, "full_screen_image", None) != None:
            state.full_screen_image = s.full_screen_image

        self.notify_play_listeners(state)
示例#6
0
 def set_audio_file_playlist(self, index):
     """ Set file in playlist
     
     :param index: file index in playlist
     """
     state = State()
     state.playback_mode = FILE_PLAYLIST
     state.playlist_track_number = index
     state.file_type = FILE_AUDIO
     self.current_folder = self.config[FILE_PLAYBACK][CURRENT_FOLDER]
     self.notify_play_listeners(state)
示例#7
0
    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
示例#8
0
    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
示例#9
0
 def get_audio_files_from_playlist(self):
     """ Call player for files in the playlist 
     
     :return: list of files from playlist
     """
     files = []
     if getattr(self, "playlist", None):
         for n in range(len(self.playlist)):
             st = State()
             st.index = st.comparator_item = n
             t = self.playlist[n]
             st.file_type = FILE_AUDIO
             st.file_name = t["file_name"]
             files.append(st)
     return files
示例#10
0
 def get_filelist_items(self, get_current_playlist):
     """ Call player for files in the playlist 
     
     :return: list of files from playlist
     """
     playlist = get_current_playlist()
     files = []
     if playlist:
         for n in range(len(playlist)):
             st = State()
             st.index = st.comparator_item = n
             st.file_type = FILE_AUDIO
             st.file_name = st.url = playlist[n]
             files.append(st)
     return files
示例#11
0
    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
示例#12
0
    def recursive_change_folder(self):
        start_folder = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYLIST]
        current_folder = self.config[FILE_PLAYBACK][CURRENT_FOLDER]
        f = self.util.file_util.get_next_folder_with_audio_files(
            start_folder, current_folder)
        if f == None or (f != None and f[0] == None):
            self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYBACK_MODE] = FILE_AUDIO
            self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYLIST] = None
            return False

        self.config[FILE_PLAYBACK][CURRENT_FOLDER] = f[0]
        self.config[FILE_PLAYBACK][CURRENT_FILE] = f[1]
        self.config[FILE_PLAYBACK][CURRENT_TRACK_TIME] = None
        state = State()
        state.file_type = FOLDER
        state.url = f[0]
        state.long_press = True
        state.playback_mode = FILE_RECURSIVE
        self.current_track_index = 0
        state.dont_notify = True
        self.audio_files = self.get_audio_files()
        self.recursive_notifier(f[0])
        return True
示例#13
0
    def set_audio_file(self, new_track, s=None):
        """ Set new audio file
        
        :param new_track: True - new audio file
        :param s: button state object 
        """
        state = State()
        state.playback_mode = FILE_AUDIO
        state.playlist_track_number = 0
        name = url = None

        if s == None:
            if self.config[AUDIOBOOKS][BROWSER_TRACK_FILENAME]:
                name = self.config[AUDIOBOOKS][BROWSER_TRACK_FILENAME]
                for t in self.playlist:
                    if t["title"].endswith(name):
                        url = t["mp3"]
            else:
                i = 0
                if s != None:
                    i = s.index
                t = self.playlist[i]
                url = t["mp3"]
                name = t["title"]
        else:
            if getattr(s, "track_filename", None):
                i = self.get_current_track_index(
                    {"file_name": s.track_filename})
            elif getattr(s, "playlist_track_number", None):
                i = s.playlist_track_number
            else:
                i = self.current_track_index

            t = self.playlist[i]
            url = t["mp3"]
            name = t["title"]

        self.config[PLAYER_SETTINGS][PAUSE] = False
        state.file_name = name
        self.config[AUDIOBOOKS][BROWSER_TRACK_FILENAME] = t["file_name"]
        state.mute = self.config[PLAYER_SETTINGS][MUTE]
        state.pause = self.config[PLAYER_SETTINGS][PAUSE]
        self.play_button.draw_default_state(None)

        if self.config[VOLUME_CONTROL][
                VOLUME_CONTROL_TYPE] == VOLUME_CONTROL_TYPE_PLAYER:
            state.volume = self.config[PLAYER_SETTINGS][VOLUME]
        else:
            state.volume = None

        state.file_type = FILE_AUDIO
        state.dont_notify = True
        state.source = FILE_AUDIO
        state.url = url
        state.mode = AUDIOBOOKS

        state.playback_mode = FILE_AUDIO
        state.music_folder = self.config[AUDIO][MUSIC_FOLDER]
        self.audio_files = self.get_audio_files_from_playlist()

        if self.config[AUDIOBOOKS][BROWSER_BOOK_TIME]:
            if new_track:
                state.track_time = "0"
            else:
                state.track_time = self.config[AUDIOBOOKS][BROWSER_BOOK_TIME]

        self.reset_loading()

        logging.debug(state.url)

        self.notify_play_listeners(state)
示例#14
0
    def get_folder_content(self,
                           folder_name,
                           store_folder_name=True,
                           load_images=True):
        """ Return the list representing folder content 
        
        :param folder_name: folder name
        :param store_folder_name: remember folder name

        :return:  
        """
        files = []

        if not os.path.exists(folder_name):
            return

        if folder_name.endswith(":") and WINDOWS in self.platform:
            folder_name += "\\"

        if store_folder_name:
            self.current_folder = folder_name

        if folder_name == self.ROOT and WINDOWS in self.platform:
            disks = self.get_windows_disks()
            for d in disks:
                state = State()
                state.folder = folder_name
                state.file_type = FOLDER
                state.file_name = d
                state.url = d
                files.append(state)
            return files

        for f in os.listdir(folder_name):
            file_path = os.path.join(folder_name, f)
            real_path = os.path.realpath(file_path)

            state = State()
            state.folder = folder_name
            state.file_type = FOLDER
            state.file_name = f
            state.url = real_path

            if os.path.isdir(file_path) and not re.match(
                    RE_HIDDEN_FOLDER_PREFIXES, f):  # folder
                try:
                    folder_image_path = self.util.get_folder_image_path(
                        real_path)
                    if folder_image_path:
                        state.file_type = FOLDER_WITH_ICON
                        state.file_image_path = folder_image_path
                    files.append(state)
                except PermissionError:
                    pass
            elif os.path.isfile(file_path) and not f.startswith("."):  # file
                if self.is_audio_file(f):
                    state.file_type = FILE_AUDIO
                    if load_images and self.image_util.get_image_from_audio_file(
                            file_path):
                        state.has_embedded_image = True
                    else:
                        state.has_embedded_image = False
                    files.append(state)
                elif self.is_playlist_file(f):
                    # had issues using cue playlists and vlc python binding
                    p = self.config[AUDIO][CLIENT_NAME]
                    if p == VLC and f.endswith(".cue"):
                        continue
                    state.file_type = FILE_PLAYLIST
                    files.append(state)

        if self.config[SORT_BY_TYPE]:
            files = sorted(files, key=attrgetter("file_type"), reverse=True)
        else:
            files = sorted(files, key=attrgetter("file_name"), reverse=False)

        for n, f in enumerate(files):
            f.comparator_item = n

        return files
示例#15
0
    def get_folder_content(self, folder_name):
        """ Return the list representing folder content 
        
        :param folder_name: folder name
        :return:  
        """
        files = []

        if not os.path.exists(folder_name):
            return

        if folder_name.endswith(":") and WINDOWS in self.platform:
            folder_name += "\\"

        self.current_folder = folder_name

        if folder_name == self.ROOT and WINDOWS in self.platform:
            disks = self.get_windows_disks()
            for d in disks:
                state = State()
                state.folder = self.current_folder
                state.file_type = FOLDER
                state.file_name = d
                state.url = d
                files.append(state)
            return files

        for f in os.listdir(folder_name):
            file_path = os.path.join(folder_name, f)
            real_path = os.path.realpath(file_path)

            state = State()
            state.folder = self.current_folder
            state.file_type = FOLDER
            state.file_name = f
            state.url = real_path

            if os.path.isdir(file_path) and not re.match(
                    RE_HIDDEN_FOLDER_PREFIXES, f):  # folder
                try:
                    folder_image_path = self.get_folder_image_path(real_path)
                    if folder_image_path:
                        state.file_type = FOLDER_WITH_ICON
                        state.file_image_path = folder_image_path
                    files.append(state)
                except PermissionError:
                    pass
            elif os.path.isfile(file_path) and not f.startswith("."):  # file
                if self.is_audio_file(f):
                    state.file_type = FILE_AUDIO
                    if self.util.get_image_from_audio_file(file_path):
                        state.has_embedded_image = True
                    else:
                        state.has_embedded_image = False
                    files.append(state)
                elif self.is_playlist_file(f):
                    # had issues with mplayer and cue files:
                    # https://en.wikipedia.org/wiki/Talk%3ACue_sheet_(computing)#mplayer_have_more_faults
                    # had also issues using cue playlists and vlc python binding
                    p = self.config[AUDIO][CLIENT_NAME]
                    if (p == MPLAYER or p == VLC) and f.endswith(".cue"):
                        continue
                    state.file_type = FILE_PLAYLIST
                    files.append(state)
        files.sort(key=lambda x: [
            int(n) if n.isdigit() else n.lower()
            for n in split(self.cre, x.file_name)
        ])

        for n, f in enumerate(files):
            f.comparator_item = n

        return files
示例#16
0
    def set_audio_file(self, new_track, s=None):
        """ Set new audio file
        
        :param new_track: True - new audio file
        "param s" button state object
        """
        state = State()
        state.playback_mode = FILE_AUDIO
        self.current_folder = s.folder
        state.folder = self.current_folder
        state.file_name = s.file_name
        state.url = s.url

        if state.folder[-1] == os.sep:
            state.folder = state.folder[:-1]

        state.full_screen_image = self.set_audio_file_image(
            state.url.replace('\"', ""), state.folder)
        self.config[PLAYER_SETTINGS][PAUSE] = False
        state.mute = self.config[PLAYER_SETTINGS][MUTE]
        state.pause = self.config[PLAYER_SETTINGS][PAUSE]
        self.play_button.draw_default_state(None)
        state.file_type = FILE_AUDIO
        state.dont_notify = True

        folder = self.config[COLLECTION_PLAYBACK][COLLECTION_FOLDER]
        self.audio_files = self.util.get_audio_files_in_folder(folder, False)
        source = None
        if s:
            source = getattr(s, "source", None)

        tt = 0.0

        if new_track and hasattr(s, "source") and s.source != INIT:
            tt = 0.0
        else:
            tt = self.config[COLLECTION_PLAYBACK][COLLECTION_TRACK_TIME]

        if (isinstance(tt, str) and len(tt) != 0) or (
                isinstance(tt, float) or
            (source and source == RESUME)) or isinstance(tt, int):
            state.track_time = tt

        if self.show_time_control:
            self.time_control.slider.set_position(0)

        if self.file_button and self.file_button.components[
                1] and self.file_button.components[1].content:
            state.icon_base = self.file_button.components[1].content

        if self.file_button and hasattr(s, "index"):
            self.file_button.state.index = s.index
        else:
            self.file_button.state.index = 0

        if s:
            if self.config[VOLUME_CONTROL][
                    VOLUME_CONTROL_TYPE] == VOLUME_CONTROL_TYPE_PLAYER:
                state.volume = s.volume
            else:
                state.volume = None

        if getattr(s, "full_screen_image", None) != None:
            state.full_screen_image = s.full_screen_image

        song_name = self.get_song_name(s)
        if song_name != None:
            state.album = song_name

        self.notify_play_listeners(state)
示例#17
0
    def set_audio_file(self, new_track, s=None):
        """ Set new audio file
        
        :param new_track: True - new audio file
        "param s" button state object
        """
        state = State()

        if s:
            state.playback_mode = getattr(s, "playback_mode", FILE_AUDIO)
            state.playlist_track_number = getattr(s, "playlist_track_number",
                                                  None)
            if self.config[CURRENT][MODE] == CD_PLAYER and getattr(
                    s, "source", None) != INIT:
                image_base = getattr(s, "image_base", None)
                if image_base != None:
                    state.image_base = image_base
        else:
            m = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYBACK_MODE]
            if m:
                state.playback_mode = m
            else:
                state.playback_mode = FILE_AUDIO

        if self.config[CURRENT][MODE] == AUDIO_FILES:
            self.current_folder = self.config[FILE_PLAYBACK][CURRENT_FOLDER]
            if not self.current_folder:
                return
            state.folder = self.current_folder
            state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE]
            if state.folder[-1] == os.sep:
                state.folder = state.folder[:-1]

            if os.sep in state.file_name:
                state.url = "\"" + state.file_name + "\""
            else:
                state.url = "\"" + state.folder + os.sep + state.file_name + "\""

            state.music_folder = self.config[AUDIO][MUSIC_FOLDER]
        elif self.config[CURRENT][MODE] == CD_PLAYER:
            state.file_name = s.file_name
            state.url = getattr(s, "url", s.file_name)
            parts = s.file_name.split()
            self.config[CD_PLAYBACK][CD_DRIVE_NAME] = parts[0][len("cdda:///"
                                                                   ):]
            id = self.cdutil.get_cd_drive_id_by_name(
                self.config[CD_PLAYBACK][CD_DRIVE_NAME])
            self.config[CD_PLAYBACK][CD_DRIVE_ID] = int(id)
            self.config[CD_PLAYBACK][CD_TRACK] = int(parts[1].split("=")[1])

        self.config[PLAYER_SETTINGS][PAUSE] = False
        state.mute = self.config[PLAYER_SETTINGS][MUTE]
        state.pause = self.config[PLAYER_SETTINGS][PAUSE]
        state.file_type = FILE_AUDIO
        state.dont_notify = True
        state.source = FILE_AUDIO

        if self.config[FILE_PLAYBACK][
                CURRENT_FILE_PLAYBACK_MODE] == FILE_AUDIO or self.config[
                    CURRENT][MODE] == CD_PLAYER:
            self.audio_files = self.get_audio_files()
        elif self.config[FILE_PLAYBACK][
                CURRENT_FILE_PLAYBACK_MODE] == FILE_PLAYLIST:
            state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYLIST]
            self.load_playlist(state)
            state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE]
            self.audio_files = self.get_audio_files_from_playlist()
            state.playback_mode = FILE_PLAYLIST
            n = getattr(s, "file_name", None)
            if n:
                state.file_name = n

            try:
                state.playlist_track_number = int(state.file_name) - 1
            except:
                state.playlist_track_number = self.get_current_track_index(
                    state)

        source = None
        if s:
            source = getattr(s, "source", None)

        if new_track:
            tt = 0.0
        else:
            if self.config[CURRENT][MODE] == CD_PLAYER:
                tt = self.config[CD_PLAYBACK][CD_TRACK_TIME]
            else:
                tt = self.config[FILE_PLAYBACK][CURRENT_TRACK_TIME]

        if (isinstance(tt, str) and len(tt) != 0) or (
                isinstance(tt, float) or
            (source and source == RESUME)) or isinstance(tt, int):
            state.track_time = tt

        self.time_control.slider.set_position(0)

        if self.file_button and self.file_button.components[
                1] and self.file_button.components[1].content:
            state.icon_base = self.file_button.components[1].content

        if s and s.volume:
            state.volume = s.volume

        if self.config[CURRENT][MODE] == CD_PLAYER and s and getattr(
                s, "source", None) == INIT:
            try:
                self.cd_album = self.util.cd_titles[self.config[CD_PLAYBACK]
                                                    [CD_DRIVE_NAME]]
                self.set_cd_album_art_image()
                state.image_base = self.file_button.components[1].content
            except:
                self.cd_album = None

        if getattr(s, "full_screen_image", None) != None:
            state.full_screen_image = s.full_screen_image

        song_name = self.get_song_name(s)
        if song_name != None:
            state.album = song_name

        self.notify_play_listeners(state)