示例#1
0
    def album_imported(self, lib, album):
        if self.on_import == False :
            pass

        print_("Tagging Lyrics:  %s - %s" % (album.albumartist, album.album))

        def fetch(item, artist, title):
            try:
                #print_("    -%s:" % (title), ui.colorize('yellow', 'Fetching'))
                lyrics = self.fetchLyrics(scrub(artist), scrub(title))
                return (item, lyrics)
            except:
                return None
                
        def tag( item, lyrics):
            try:
                #print_("    -%s:" % (item.title), ui.colorize('green', 'Updated!'))
                item.lyrics = lyrics
                item.write()
                lib.store(item)
            except:
                pass
                
        [(item, item.artist, item.title) for item in album.items()]  \
            >> ThreadPool(apply(fetch), poolsize=self.processcount)  \
            >> filter( lambda itm: itm != None) \
            >> ThreadPool(apply(tag), poolsize=1)
示例#2
0
    def process_path(self, basePath):
        def produce():
            def create_mf(path):
                try:
                    mf = MediaFile(path)
                    if( len(mf.lyrics) == 0 or self.force):
                        #print_("    -%s:" % (mf.title), ui.colorize('yellow', 'Queued'))
                        return mf
                except FileTypeError:
                     return None

            for path in basePath:
                if os.path.isdir(path):
                # Find all files in the directory.
                    filepaths = []
                    for root, dirs, files in sorted_walk(path):
                        for filename in files:
                            yield create_mf(os.path.join(root, filename))
                else:
                    # Just add the file.
                    yield create_mf(path)


        def fetch(mf):
            try:
                print_("    -%s:" % (mf.title), ui.colorize('yellow', 'Fetching'))
                lyrics = self.fetchLyrics(scrub(mf.artist), scrub(mf.title))
                result = (mf, lyrics);
                return result
            except:
                return None

        def tag(mf, lyrics):
            try:
                if( lyrics ):
                    mf.lyrics = lyrics
                    mf.save()

                    print_("    -%s:" % (mf.title), ui.colorize('green', 'Updated!'))
                else:
                    print_("    -%s: " % (mf.title), ui.colorize('red', 'Not Found'))
            except:
                return

         #setup and run the pipeline
        ThreadedFeeder(produce) \
            >> filter( lambda itm: itm != None) \
            >> ThreadPool(map(fetch), poolsize=self.processcount) \
            >> ThreadPool(apply(tag), poolsize=1)