Пример #1
0
    def leaf_node(self, branch, data, menuw):
        """
        last node in branch generates a playlist.
        """
        logger.debug('leaf_node(branch=%r, data=%r, menuw=%r)', branch, data,
                     menuw)
        title = '-'.join(data)
        #creating of audio items is slow.
        #need a progress-bar.
        pl = playlist.Playlist(name='-'.join(data),
                               playlist=[],
                               display_type='audiocd')

        tracks = branch.execute(data)  #returns list of (desc, path, filename)

        pop = ProgressBox(text=_('Generating playlist...'), full=len(tracks))
        pop.show()
        items = []
        i = 0
        for desc, path, filename in tracks:
            filepath = os.path.join(path, filename)
            item = audioitem.AudioItem(filepath, parent=pl)
            item.name = desc
            item.track = i
            items.append(item)
            pop.tick()
            i += 1
        pop.destroy()

        pl.playlist = items

        mymenu = menu.Menu(title, pl.playlist, item_types="audio")
        menuw.pushmenu(mymenu)
Пример #2
0
    def leaf_node(self, branch, data, menuw):
        """
        last node in branch generates a playlist.
        """
        logger.debug('leaf_node(branch=%r, data=%r, menuw=%r)', branch, data, menuw)
        title = '-'.join(data)
        #creating of audio items is slow.
        #need a progress-bar.
        pl = playlist.Playlist(name='-'.join(data), playlist=[], display_type='audiocd')

        tracks = branch.execute(data)  #returns list of (desc, path, filename)

        pop = ProgressBox(text=_('Generating playlist...'), full=len(tracks))
        pop.show()
        items = []
        i = 0
        for desc, path, filename in tracks:
            filepath = os.path.join(path, filename)
            item = audioitem.AudioItem(filepath, parent=pl)
            item.name = desc
            item.track = i
            items.append( item)
            pop.tick()
            i+=1
        pop.destroy()

        pl.playlist = items

        mymenu = menu.Menu(title, pl.playlist, item_types="audio")
        menuw.pushmenu(mymenu)
Пример #3
0
def check_cache_status():
    """
    check if cache got updated with helper while freevo is running
    """
    from menu import MenuWidget
    global __last_status_check__
    if not isinstance(rc.focused_app(), MenuWidget):
        return
    try:
        cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo')
        if os.stat(cachefile)[stat.ST_MTIME] <= __last_status_check__:
            return
        if not __last_status_check__:
            __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
            return
    except:
        __last_status_check__ = 1
        return

    __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
    open_cache_files = []

    for cache in mmpython_cache, meta_cache:
        # save current cache
        cache.save_cache()
        # delete all info about loaded objects
        cache.current_objects = {}
        cache.current_cachefile = None
        cache.current_cachedir = None
        cache.cache_modified = False

        # file database
        for d in cache.all_directories:
            if d and not os.path.dirname(vfs.normalize(d)) in open_cache_files:
                open_cache_files.append(os.path.dirname(vfs.normalize(d)))
        cache.all_directories = {}

    # create ProgressBox for reloading
    from gui import ProgressBox
    box = ProgressBox(text=_('Reloading cache files, be patient...'),
                      full=len(open_cache_files))
    box.show()

    # reload already open cache files
    for d in open_cache_files:
        load_cache(d)
        box.tick()
    box.destroy()
Пример #4
0
def check_cache_status():
    """
    check if cache got updated with helper while freevo is running
    """
    from menu import MenuWidget
    global __last_status_check__
    if not isinstance(rc.focused_app(), MenuWidget):
        return
    try:
        cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo')
        if os.stat(cachefile)[stat.ST_MTIME] <= __last_status_check__:
            return
        if not __last_status_check__:
            __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
            return
    except:
        __last_status_check__ = 1
        return

    __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
    open_cache_files = []

    for cache in mmpython_cache, meta_cache:
        # save current cache
        cache.save_cache()
        # delete all info about loaded objects
        cache.current_objects    = {}
        cache.current_cachefile  = None
        cache.current_cachedir   = None
        cache.cache_modified     = False

        # file database
        for d in cache.all_directories:
            if d and not os.path.dirname(vfs.normalize(d)) in open_cache_files:
                open_cache_files.append(os.path.dirname(vfs.normalize(d)))
        cache.all_directories  = {}

    # create ProgressBox for reloading
    from gui import ProgressBox
    box = ProgressBox(text=_('Reloading cache files, be patient...'), full=len(open_cache_files))
    box.show()

    # reload already open cache files
    for d in open_cache_files:
        load_cache(d)
        box.tick()
    box.destroy()
Пример #5
0
    def onchoose_last_node(self, tree, data, menuw):
        """
        last node in tree generates a playlist.
        """
        title = '-'.join(data)
        #creating of audio items is slow.
        #need a progress-bar.
        pl = playlist.Playlist(name='-'.join(data),
                               playlist=[],
                               display_type='audiocd')

        tracks = tree.execute(data)  #returns list of (desc,path,filename)

        pop = ProgressBox(text=_('Generating playlist...'), full=len(tracks))
        pop.show()
        items = []
        i = 0
        for desc, path, filename in tracks:
            filepath = os.path.join(path, filename)
            item = audioitem.AudioItem(filepath, parent=pl)
            item.name = desc
            item.track = i
            items.append(item)
            pop.tick()
            i += 1
        pop.destroy()

        pl.playlist = items

        #note/question for core developers:
        #command below causes strange errors?
        #plugin.__plugin_type_list__ is empty??? but it's Not?
        #pl.browse(arg=None,menuw=menuw)
        #print 'LIST=',plugin.__plugin_type_list__['mimetype']
        #workaround: not all features of a real playlist :(

        mymenu = menu.Menu(title, pl.playlist, item_types="audio")
        menuw.pushmenu(mymenu)
Пример #6
0
    def build(self, arg=None, menuw=None):
        """
        build the items for the directory
        """
        self.menuw = menuw
        self.playlist = []
        self.play_items = []
        self.dir_items = []
        self.pl_items = []

        if self.media:
            self.media.mount()

        if hasattr(self, '__dirwatcher_last_time__'):
            del self.__dirwatcher_last_time__

        if arg == 'update':
            if not self.menu.choices:
                selected_pos = -1
            else:
                # store the current selected item
                selected_id = self.menu.selected.id()
                selected_pos = self.menu.choices.index(self.menu.selected)
            if hasattr(self.menu, 'skin_default_has_description'):
                del self.menu.skin_default_has_description
            if hasattr(self.menu, 'skin_default_no_images'):
                del self.menu.skin_default_no_images
            if hasattr(self.menu, 'skin_force_text_view'):
                del self.menu.skin_force_text_view
        elif not os.path.exists(self.dir):
            AlertBox(text=_('Directory does not exist')).show()
            return

        display_type = self.display_type
        if self.display_type == 'tv':
            display_type = 'video'

        if arg and arg.startswith('playlist:'):
            if arg.endswith(':random'):
                Playlist(playlist=[(self.dir, 0)],
                         parent=self,
                         display_type=display_type,
                         random=True).play(menuw=menuw)
            elif arg.endswith(':recursive'):
                Playlist(playlist=[(self.dir, 1)],
                         parent=self,
                         display_type=display_type,
                         random=False).play(menuw=menuw)
            elif arg.endswith(':random_recursive'):
                Playlist(playlist=[(self.dir, 1)],
                         parent=self,
                         display_type=display_type,
                         random=True).play(menuw=menuw)
            return

        if config.OSD_BUSYICON_TIMER:
            osd.get_singleton().busyicon.wait(config.OSD_BUSYICON_TIMER[0])

        files = vfs.listdir(self.dir, include_overlay=True)
        num_changes = mediainfo.check_cache(self.dir)

        pop = None
        callback = None
        if skin.active():
            if (num_changes > 10) or (num_changes and self.media):
                if self.media:
                    pop = ProgressBox(text=_('Scanning disc, be patient...'),
                                      full=num_changes)
                else:
                    pop = ProgressBox(
                        text=_('Scanning directory, be patient...'),
                        full=num_changes)
                pop.show()
                callback = pop.tick

        elif config.OSD_BUSYICON_TIMER and len(
                files) > config.OSD_BUSYICON_TIMER[1]:
            # many files, just show the busy icon now
            osd.get_singleton().busyicon.wait(0)

        if num_changes > 0:
            mediainfo.cache_dir(self.dir, callback=callback)

        #
        # build items
        #
        # build play_items, pl_items and dir_items
        for p in plugin.mimetype(display_type):
            for i in p.get(self, files):
                if i.type == 'playlist':
                    self.pl_items.append(i)
                elif i.type == 'dir':
                    self.dir_items.append(i)
                else:
                    self.play_items.append(i)

        # normal DirItems
        for filename in files:
            if os.path.isdir(filename):
                d = DirItem(filename, self, display_type=self.display_type)
                self.dir_items.append(d)

        # remove same beginning from all play_items
        if self.DIRECTORY_SMART_NAMES:
            substr = ''
            if len(self.play_items) > 4 and len(self.play_items[0].name) > 5:
                substr = self.play_items[0].name[:-5].lower()
                for i in self.play_items[1:]:
                    if len(i.name) > 5:
                        substr = util.find_start_string(i.name.lower(), substr)
                        if not substr or len(substr) < 10:
                            break
                    else:
                        break
                else:
                    for i in self.play_items:
                        i.name = util.remove_start_string(i.name, substr)

        #
        # sort all items
        #

        # sort directories
        if self.DIRECTORY_SMART_SORT:
            self.dir_items.sort(lambda l, o: util.smartsort(l.dir, o.dir))
        else:
            self.dir_items.sort(lambda l, o: cmp(l.dir.upper(), o.dir.upper()))

        # sort playlist
        self.pl_items.sort(lambda l, o: cmp(l.name.upper(), o.name.upper()))

        # sort normal items
        if self.DIRECTORY_SORT_BY_DATE:
            self.play_items.sort(lambda l, o: cmp(
                l.sort('date').upper(),
                o.sort('date').upper()))
        elif self['%s_advanced_sort' % display_type]:
            self.play_items.sort(lambda l, o: cmp(
                l.sort('advanced').upper(),
                o.sort('advanced').upper()))
        else:
            self.play_items.sort(lambda l, o: cmp(l.sort().upper(),
                                                  o.sort().upper()))

        if self['num_dir_items'] != len(self.dir_items):
            self['num_dir_items'] = len(self.dir_items)

        if self['num_%s_items' %
                display_type] != len(self.play_items) + len(self.pl_items):
            self['num_%s_items' %
                 display_type] = len(self.play_items) + len(self.pl_items)

        if self.DIRECTORY_REVERSE_SORT:
            self.dir_items.reverse()
            self.play_items.reverse()
            self.pl_items.reverse()

        # delete pl_items if they should not be displayed
        if self.display_type and not self.display_type in self.DIRECTORY_ADD_PLAYLIST_FILES:
            self.pl_items = []

        # add all playable items to the playlist of the directory
        # to play one files after the other
        if not self.display_type or self.display_type in self.DIRECTORY_CREATE_PLAYLIST:
            self.playlist = self.play_items

        # build a list of all items
        items = self.dir_items + self.pl_items + self.play_items

        # random playlist (only active for audio)
        if self.display_type and self.display_type in self.DIRECTORY_ADD_RANDOM_PLAYLIST \
               and len(self.play_items) > 1:
            pl = Playlist(_('Random playlist'),
                          self.play_items,
                          self,
                          random=True)
            pl.autoplay = True
            items = [pl] + items

        if pop:
            pop.destroy()
            # closing the poup will rebuild the menu which may umount
            # the drive
            if self.media:
                self.media.mount()

        if config.OSD_BUSYICON_TIMER:
            # stop the timer. If the icons is drawn, it will stay there
            # until the osd is redrawn, if not, we don't need it to pop
            # up the next milliseconds
            osd.get_singleton().busyicon.stop()

        #
        # action
        #

        if arg == 'update':
            # update because of dirwatcher changes
            self.menu.choices = items

            if selected_pos != -1:
                for i in items:
                    if Unicode(i.id()) == Unicode(selected_id):
                        self.menu.selected = i
                        break
                else:
                    # item is gone now, try to the selection close
                    # to the old item
                    pos = max(0, min(selected_pos - 1, len(items) - 1))
                    if items:
                        self.menu.selected = items[pos]
                    else:
                        self.menu.selected = None
            if self.menuw:
                if self.menu.selected and selected_pos != -1:
                    self.menuw.rebuild_page()
                else:
                    self.menuw.init_page()
                self.menuw.refresh()


        elif len(items) == 1 and items[0].actions() and \
                 self.DIRECTORY_AUTOPLAY_SINGLE_ITEM:
            # autoplay
            items[0].actions()[0][0](menuw=menuw)

        elif arg == 'play' and self.play_items:
            # called by play function
            self.playlist = self.play_items
            Playlist.play(self, menuw=menuw)

        else:
            # normal menu build
            item_menu = menu.Menu(
                self.name,
                items,
                reload_func=self.reload,
                item_types=self.skin_display_type,
                force_skin_layout=self.DIRECTORY_FORCE_SKIN_LAYOUT)

            if self.skin_fxd:
                item_menu.skin_settings = skin.load(self.skin_fxd)

            menuw.pushmenu(item_menu)

            dirwatcher.cwd(menuw, self, item_menu, self.dir)
            self.menu = item_menu
            self.menuw = menuw