Example #1
0
 def browse(self, link, callback):
     if link.type() == link.LINK_ALBUM:
         browser = self.session.browse_album(link.as_album(), callback)
         while not browser.is_loaded():
             time.sleep(0.1)
         for track in browser:
             print track.name()
     if link.type() == link.LINK_ARTIST:
         browser = ArtistBrowser(link.as_artist())
         while not browser.is_loaded():
             time.sleep(0.1)
         for album in browser:
             print album.name()
Example #2
0
	def browse(self, link, callback):
		if link.type() == link.LINK_ALBUM:
			browser = self.session.browse_album(link.as_album(), callback)
			while not browser.is_loaded():
				time.sleep(0.1)
			for track in browser:
				print track.name()
		if link.type() == link.LINK_ARTIST:
			browser = ArtistBrowser(link.as_artist())
			while not browser.is_loaded():
				time.sleep(0.1)
			for album in browser:
				print album.name()
Example #3
0
	def run(self):
		container_loaded.wait()
		container_loaded.clear()
		
		print "Starting consume loop..."
		for uri in self.queue_play.consume():
			if uri:
				print "Try to play", uri
				link = Link.from_string(uri)
				if link.type() == Link.LINK_TRACK:
					self.jukebox.load_track(link.as_track())
					self.jukebox.play()
				elif link.type() == Link.LINK_ARTIST:
					browser = ArtistBrowser(link.as_artist())
					while not browser.is_loaded():
						time.sleep(0.1)
					toptracks = browser.tophit_tracks()
					print toptracks
					#random.shuffle(toptracks)					
					track = choice(toptracks)
					self.jukebox.load_track(track)
					self.jukebox.play()
				elif link.type() == 7: #Link.LINK_PLAYLIST:
					playlist = self.jukebox.starred
					track = choice(playlist)

					while track.availability() != 1:
						track = choice(playlist)

					self.jukebox.load_track(track)
					self.jukebox.play()
					
			else:
				self.jukebox.stop()
				
		try:
			self.cmdloop()
		finally:
			self.do_quit(None)
Example #4
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
Example #5
0
    def run(self):
        # wait for container
        container_loaded.wait()
        container_loaded.clear()

        while True:
            link_string = self._queue.next_link()

            if link_string == '':
                break

            link = Link.from_string(link_string)

            if link.type() == Link.LINK_TRACK:
                track = link.as_track()
                itrack = iter([track])

            elif link.type() == Link.LINK_PLAYLIST \
                    or link_string == 'spotify:user:'******'username')+':starred':
                print 'Loading playlist %s ...' % link_string

                playlist = link.as_playlist()

                while not playlist.is_loaded():
                    time.sleep(0.1)

                itrack = iter(playlist)

            elif link.type() == Link.LINK_ALBUM:
                print 'Processing album %s' % str(link)
                itrack = [ ]
                album = link.as_album()
                album_browser = AlbumBrowser(album)

                while not album_browser.is_loaded():
                    time.sleep(0.1)

                if self._util.is_compilation(album):
                    continue

                if album.is_available():
                    print 'Getting tracks for %s' % album.name()
                    for track in album_browser:
                        itrack.append(track)

            elif link.type() == Link.LINK_ARTIST:
                print "Processing artist %s ..." % str(link)

                artist         = link.as_artist()
                artist_browser = ArtistBrowser(artist, 'no_tracks')

                while not artist_browser.is_loaded():
                    time.sleep(0.1)

                print "Artist loaded"
                print(artist.name())

                similar_artists = artist_browser.similar_artists()

                for similar_artist in similar_artists:
                    self._queue.add_artist_link(similar_artist, 'similar')

                albums           = artist_browser.albums()
                processed_albums = [ ]
                itrack           = [ ]

                for album in albums:
                    if self._util.is_compilation(album):
                        continue

                    if album.is_available() and Link.from_album(album) \
                            not in processed_albums:
                        processed_albums.append(Link.from_album(album))
                        print 'Getting tracks for %s' % album.name()
                        album_browser = AlbumBrowser(album)

                        while not album_browser.is_loaded():
                            time.sleep(0.1)

                        for track in album_browser:
                            itrack.append(track)

            else:
                print "Unrecognised link"
                os._exit(2)
                return

            # ripping loop
            session = self._ripper.session

            for track in itrack:
                if self._util.is_known_not_available(Link.from_track(track)):
                    continue

                try:
                    self._ripper.load_track(track)

                    while not track.is_loaded():
                        time.sleep(0.1)

                    for track_artist in track.artists():
                        self._queue.add_artist_link(track_artist, 'track')

                    if self._ripper.rip_init(session, track):
                        self._ripper.play()
                        self._end_of_track.wait()
                        self._end_of_track.clear()
                        self._ripper.rip_terminate(session, track)
                        self._ripper.rip_id3(session, track)

                except TrackNotAvailableException:
                    print "Track not available (%s)" % track.name()
                    self._util.mark_as_not_available(Link.from_track(track))

        self._ripper.disconnect()
Example #6
0
    def run(self):
        # wait for container
        container_loaded.wait()
        container_loaded.clear()

        # output dir
        outputdir = os.getcwd()
        if args.outputdir != None:
            outputdir = os.path.normpath(os.path.realpath(args.outputdir[0]))

        session = self.ripper.session

        # create track iterator
        link = Link.from_string(args.url[0])
        if link.type() == Link.LINK_TRACK:
            track = link.as_track()
            itrack = iter([track])
        elif link.type() == Link.LINK_PLAYLIST or link.type() == Link.LINK_STARRED:
            playlist = link.as_playlist()
            print('loading playlist ...')
            while not playlist.is_loaded():
                print(' pending playlist ')
                time.sleep(0.5)
            print('done')
            itrack = iter(playlist)
        elif link.type() == Link.LINK_ALBUM:
            album = AlbumBrowser(link.as_album())
            print('loading album ...')            
            while not album.is_loaded():
                print(' pending album ')
                time.sleep(0.5)
            print('done')
            itrack = iter(album)
        elif link.type() == Link.LINK_ARTIST:
            artist = ArtistBrowser(link.as_artist())
            print('loading artist')
            while not artist.is_loaded():
                print(' pending artist ')
                time.sleep(0.5)
            print('done')
            itrack = iter(artist)
                  

        # ripping loop
        count = 0
        for track in itrack:
                count += 1
                # if the track is not loaded, track.availability is not ready
                self.ripper.load_track(track)
                if interrupt.isSet():
                    break
                while not track.is_loaded():
                    time.sleep(0.1)
                if track.availability() != 1:
                    print('Skipping. Track not available')
                else:
                    #self.ripper.load_track(track)
                    exists = library_track_exists(track, outputdir)
                    if exists:
                        print("Skipping. Track found at " + exists)
                    else:
                        try:
                            rip_init(session, track, outputdir)

                            self.ripper.play()

                            end_of_track.wait()
                            end_of_track.clear() # TODO check if necessary

                            rip_terminate(session, track)
                            if interrupt.isSet():
                                rip_delete(track, outputdir)
                                break
                            rip_id3(session, track, outputdir)
                        except (KeyboardInterrupt, SystemExit):
                            raise
                        except Exception as inst:
                            if not args.ignoreerrors:
                                raise
                            print("Unexpected error: ", type(inst))
                            print(inst)
                            print("Skipping to next track, if in playlist")

        self.ripper.disconnect()