示例#1
0
    def do_search(self, line):
        if not line:
            if self.results is False:
                print "No search is in progress"
            elif self.results is None:
                print "Searching is in progress"
            else:
                print "Artists:"
                for a in self.results.artists():
                    print "    ", Link.from_artist(a), a.name()
                print "Albums:"
                for a in self.results.albums():
                    print "    ", Link.from_album(a), a.name()
                print "Tracks:"
                for a in self.results.tracks():
                    print "    ", Link.from_track(a, 0), a.name()
                print "%d tracks not shown" % (self.results.total_tracks() -
                                               len(self.results.tracks()))
        else:
            line = line.decode('utf-8')
            self.results = None

            def search_finished(results, userdata):
                print "\nSearch results received"
                self.results = results
                self.print_search_results()

            self.jukebox.search(line, search_finished)
示例#2
0
文件: translator.py 项目: xim/mopidy
 def to_mopidy_artist(cls, spotify_artist):
     if not spotify_artist.is_loaded():
         return Artist(name=u'[loading...]')
     return Artist(
         uri=str(Link.from_artist(spotify_artist)),
         name=spotify_artist.name()
     )
示例#3
0
文件: translator.py 项目: Amli/mopidy
 def to_mopidy_artist(cls, spotify_artist):
     if not spotify_artist.is_loaded():
         return Artist(name=u'[loading...]')
     return Artist(
         uri=str(Link.from_artist(spotify_artist)),
         name=spotify_artist.name()
     )
示例#4
0
def to_mopidy_artist(spotify_artist):
    if spotify_artist is None:
        return
    uri = str(Link.from_artist(spotify_artist))
    if not spotify_artist.is_loaded():
        return Artist(uri=uri, name='[loading...]')
    return Artist(uri=uri, name=spotify_artist.name())
示例#5
0
	def do_search(self, line):
		if not line:
			if self.results is False:
				print "No search is in progress"
			elif self.results is None:
				print "Searching is in progress"
			else:
				print "Artists:"
				for a in self.results.artists():
					print "	", Link.from_artist(a), a.name()
				print "Albums:"
				for a in self.results.albums():
					print "	", Link.from_album(a), a.name()
				print "Tracks:"
				for a in self.results.tracks():
					print "	", Link.from_track(a, 0), a.name()
				print self.results.total_tracks() - \
						len(self.results.tracks()), "Tracks not shown"
		else:
			line = line.decode('utf-8')
			self.results = None
			def search_finished(results, userdata):
				print "\nSearch results received"
				self.results = results
				self.print_search_results()
			self.jukebox.search(line, search_finished)
示例#6
0
 def add_artist_to_directory(self, artist, directory):
     artist_uri = str(Link.from_artist(artist))
     directory.add(
         DirectoryObject(key=Callback(self.get_artist_albums,
                                      uri=artist_uri),
                         title=artist.name().decode("utf-8"),
                         thumb=R("placeholder-artist.png")))
示例#7
0
    def add_artist_link(self, artist, source):
        """
        Add an artist link to the queue.
        """
        link = str(Link.from_artist(artist))

        if not self._items:
            self._items = [ ]

            with open('queue.json', 'r') as fp:
                self._items = json.load(fp)

        found = False

        for item in self._items:
            if item['link'] == link:
                found = True
                break

        if not found:
            while not artist.is_loaded():
                time.sleep(0.1)

            print 'Adding %s' % artist.name()

            self._items.append({
                    'name':   artist.name(),
                    'link':   link,
                    'source': source,
                    })

            with open('queue.json', 'w') as fp:
                json.dump(self._items, fp, indent=2)

        return True
示例#8
0
    def action_search(self, line):
        if not line:
            if self.results is False:
                print "No search is in progress"
                return False
            elif self.results is None:
                print "Searching is in progress"
            else:
                print "Artists:"
                for a in self.results.artists():
                    print "    ", Link.from_artist(a), a.name()
                print "Albums:"
                for a in self.results.albums():
                    print "    ", Link.from_album(a), a.name()
                print "Tracks:"
                for a in self.results.tracks():
                    print "    ", Link.from_track(a, 0), a.name()
                print self.results.total_tracks() - len(
                    self.results.tracks()), "Tracks not shown"
                self.results = False
        else:
            self.results = None

            def _(results, userdata):
                print "\nSearch results received"
                self.results = results

            self.search(line, _)
示例#9
0
 def action_search(self, line):
     if not line:
         if self.results is False:
             print "No search is in progress"
             return False
         elif self.results is None:
             print "Searching is in progress"
         else:
             print "Artists:"
             for a in self.results.artists():
                 print "    ", Link.from_artist(a), a.name()
             print "Albums:"
             for a in self.results.albums():
                 print "    ", Link.from_album(a), a.name()
             print "Tracks:"
             for a in self.results.tracks():
                 print "    ", Link.from_track(a, 0), a.name()
             print self.results.total_tracks() - len(self.results.tracks()), "Tracks not shown"
             self.results = False
     else:
         self.results = None
         def _(results, userdata):
             print "\nSearch results received"
             self.results = results
         self.search(line, _)
示例#10
0
 def add_artist_to_directory(self, artist, directory):
     artist_uri = str(Link.from_artist(artist))
     directory.add(
         DirectoryObject(
             key = Callback(self.get_artist_albums, uri = artist_uri),
             title = artist.name().decode("utf-8"),
             thumb = R("placeholder-artist.png")
         )
     )
示例#11
0
def to_mopidy_artist(spotify_artist):
    if spotify_artist is None:
        return
    uri = str(Link.from_artist(spotify_artist))
    if uri in artist_cache:
        return artist_cache[uri]
    if not spotify_artist.is_loaded():
        return Artist(uri=uri, name='[loading...]')
    artist_cache[uri] = Artist(uri=uri, name=spotify_artist.name())
    return artist_cache[uri]
示例#12
0
 def print_search_results(self):
     print "Artists:"
     for a in self.results.artists():
         print "    ", Link.from_artist(a), a.name()
     print "Albums:"
     for a in self.results.albums():
         print "    ", Link.from_album(a), a.name()
     print "Tracks:"
     for a in self.results.tracks():
         print "    ", Link.from_track(a, 0), a.name()
     print self.results.total_tracks() - len(self.results.tracks()), \
         "Tracks not shown"
示例#13
0
	def print_search_results(self):
		print "Artists:"
		for a in self.results.artists():
			print "	", Link.from_artist(a), a.name()
		print "Albums:"
		for a in self.results.albums():
			print "	", Link.from_album(a), a.name()
		print "Tracks:"
		for a in self.results.tracks():
			print "	", Link.from_track(a, 0), a.name()
		print self.results.total_tracks() - len(self.results.tracks()), \
			"Tracks not shown"
示例#14
0
    def browse_artist(self, artist, callback):
        ''' Browse an artist, invoking the callback when done

        :param artist:         An artist instance to browse.
        :param callback:       A callback to invoke when the album is loaded.
                               Should take the browser as a single parameter.
        '''
        link = Link.from_artist(artist)
        def callback_wrapper(browser, userdata):
            self.log("Artist browse complete: %s" % Link.from_artist(artist))
            callback(browser)
        self.log("Browse artist: %s" % link)
        browser = ArtistBrowser(artist, "no_tracks", callback_wrapper)
        return browser
示例#15
0
    def browse_artist(self, artist, callback):
        ''' Browse an artist, invoking the callback when done

        :param artist:         An artist instance to browse.
        :param callback:       A callback to invoke when the album is loaded.
                               Should take the browser as a single parameter.
        '''
        link = Link.from_artist(artist)

        def callback_wrapper(browser):
            self.log("Artist browse complete: %s" % Link.from_artist(artist))
            callback(browser)

        self.log("Browse artist: %s" % link)
        browser = self.session.browse_artist(artist, callback_wrapper)
        return browser
示例#16
0
 def callback_wrapper(browser, userdata):
     self.log("Artist browse complete: %s" % Link.from_artist(artist))
     callback(browser)
示例#17
0
 def callback_wrapper(browser):
     self.log("Artist browse complete: %s" % Link.from_artist(artist))
     callback(browser)
示例#18
0
 def _to_mopidy_artist(self, spotify_artist):
     return Artist(
         uri=str(Link.from_artist(spotify_artist)),
         name=spotify_artist.name().decode(ENCODING),
     )