Beispiel #1
0
    def test_str(self):
        # Arrange
        library = pylast.Library(user=self.username, network=self.network)

        # Act
        string = str(library)

        # Assert
        self.assert_endswith(string, "'s Library")
Beispiel #2
0
    def test_repr(self):
        # Arrange
        library = pylast.Library(user=self.username, network=self.network)

        # Act
        representation = repr(library)

        # Assert
        self.assert_startswith(representation, "pylast.Library(")
Beispiel #3
0
    def test_get_user(self):
        # Arrange
        library = pylast.Library(user=self.username, network=self.network)
        user_to_get = self.network.get_user(self.username)

        # Act
        library_user = library.get_user()

        # Assert
        assert library_user == user_to_get
Beispiel #4
0
    def Track(self, operation, payload):
        """ Performs operations on Track objects. Only supports the GET
		operation (you can get a user's tracks, you can't create them).

		Returns a set of Tracks depending on the payload.

		:param operation: The operation to perform (GET)
		:type operation: str
		:param payload:
			Provide a Person (whose id is username) to return a set
			of that user's Loved Tracks
		:type payload: SocialObject
		:returns: list[track] - set of tracks matching criteria
		"""
        if (operation == "GET"):
            user = self.network.get_user(payload)
            tracks = user.get_loved_tracks(limit=10)
            track_coll = Playlist()
            track_coll.author = self.__get_author_from_username(payload)

            track_set = []
            for track in tracks:
                this_track = Track()
                #this_track.author = payload
                this_track.author = track_coll.author
                this_track.artist = track.track.artist.name
                this_track.title = track.track.title
                #this_track.tag = track.track.get_top_tags(limit=1)[0].item.name
                this_track.tag = "test_tag"
                track_set.append(this_track)
            track_coll.objects = track_set
            return track_coll
        elif (operation == "POST"):
            target = self.network.get_user(payload.addTo.id)
            artist = payload.artist
            song = payload.song
            track = self.network.get_track(song, artist)
            lib = pylast.Library(target, network="LastFM")
            lib.add_track(track)
Beispiel #5
0
    def test_cacheable_library(self):
        # Arrange
        library = pylast.Library(self.username, self.network)

        # Act/Assert
        self.helper_validate_cacheable(library, "get_artists")
Beispiel #6
0
    def test_library_is_hashable(self):
        # Arrange
        library = pylast.Library(user=self.username, network=self.network)

        # Act/Assert
        self.helper_is_thing_hashable(library)
Beispiel #7
0
def get_library(username):
    return pylast.Library(username, network)
Beispiel #8
0
                        '--username',
                        default=lastfm_username,
                        help="Last.fm username")
    parser.add_argument('-n',
                        '--number',
                        default=1,
                        type=int,
                        help="Number of tracks to unscrobble")
    args = parser.parse_args()

    print("Last scrobbles:")
    # +1 because now-playing tracks may also be included
    last_scrobbles = get_recent_tracks(lastfm_username, args.number + 1)
    # Now make sure we only unscrobble the required number
    last_scrobbles = last_scrobbles[:args.number]

    answer = query_yes_no("Unscrobble last " + str(args.number) + "?")
    if not answer:
        sys.exit("Scrobble kept")
    else:
        my_library = pylast.Library(user=lastfm_username,
                                    network=lastfm_network)

        for last_scrobble in last_scrobbles:
            unscrobble(my_library, last_scrobble)

    print("Last few are now:")
    get_recent_tracks(lastfm_username, 5)

# End of file
Beispiel #9
0
print('[LOG] Initializing')

N = 50
topperiod = '1month'
taglimit = 5
user = '******'
playlist = []

API_KEY = 'REDACTED'
API_SECRET = 'REDACTED'

#TODO tag/similar weight to accept

network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET)
userobj = network.get_user(user)
library = pylast.Library(user=user, network=network)
allArt = library.get_artists(limit=None)

topArt = userobj.get_top_artists(period=topperiod, limit=N)
recent = userobj.get_recent_tracks(limit=N)

tags = defaultdict(float)
simart = []
simtrk = []

print('[LOG] This will take a while')
for i in range(0, N - 1):
    #parallelize A
    if len(topArt) >= i:
        #weight check
        #FIXME Nones probably coming from here