def test_limit_amount_of_low_rating(self):

        rules = Rules()
        songs = []

        rules.limit_low_rating_percent = 10

        expected_percent = rules.limit_low_rating_percent
        song_count = rules.limit_low_rating_percent

        for i in range(song_count):
            song = self._song("low rating", True)
            song.rating = 20
            songs.append(song)

        for i in range(song_count):
            song = self._song("high rating", True)
            self._song_played_days_ago(song, rules.star_3_min_days + 1)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(lib, rules, song_count, False)
        actual_count = sum(1 if song.title == "low rating" else 0 for song in result_songs)
        expected_count = song_count / 100 * expected_percent
        self.assertTrue(actual_count == expected_count,
                        "expected {} new songs, found {}:\n{}\n\nList of original songs:\n{}".format(
                            expected_count, actual_count,
                            self._print_songs(result_songs), self._print_songs(songs)))
    def test_limit_new_albums_by_new_song(self):

        rules = Rules()
        rules.limit_new_albums_count = 1
        rules.limit_new_songs_percent = 100
        rules.limit_artists_percent = 100

        songs = []
        song_count = 5
        for i in range(song_count):
            song = self._song("new songs", unique_artist_album=False)
            song.rating = 0
            songs.append(song)

        for i in range(song_count):
            song = self._song("high rating", unique_artist_album=False)
            self._song_played_days_ago(song, rules.star_3_min_days + 1)
            songs.append(song)

        song = self._song("expected new song", unique_artist_album=False)
        song["playcount"] = 3
        song.rating = 0
        songs.append(song)

        lib = TestLib(songs)
        result_songs = playlist_generator.generate_playlist(lib, rules, song_count, False)

        error_info = "\n\nResult songs:\n{}\n\nList of original songs:\n{}".format(self._print_songs(result_songs),
                                                                                   self._print_songs(songs))

        specific_song_found = any(result_song.title == "expected new song" for result_song in result_songs)
        self.assertTrue(specific_song_found, "expected 'expected new song' that wasn't found" + error_info)

        new_songs_count = sum(1 if song.title == "new songs" else 0 for song in result_songs)
        self.assertTrue(new_songs_count == 0, "expected 0 new songs, found {}".format(new_songs_count) + error_info)
    def test_prefer_songs_played_long_ago(self):

        rules = Rules()
        songs = []

        for i in range(5):
            song = self._song("played now", True)
            self._song_played_days_ago(song,
                                       rules.play_last_time_max_days / 10)
            songs.append(song)

        for i in range(5, 10):
            song = self._song("played long time ago", True)
            self._song_played_days_ago(song, rules.play_last_time_max_days)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(
            lib, rules, 5, False)
        self.assertTrue(
            all(result_song.title == "played long time ago"
                for result_song in result_songs),
            "found a recently played song in:\n" +
            self._print_songs(result_songs) + "\n\nList of original songs:\n" +
            self._print_songs(songs))
    def test_limit_amount_of_same_artist(self):

        rules = Rules()
        songs = []

        rules.limit_artists_percent = 10

        expected_percent = rules.limit_artists_percent
        song_count = rules.limit_artists_percent

        for i in range(song_count):
            song = self._song("same artist", False)
            songs.append(song)

        for i in range(song_count):
            song = self._song("different artist", True)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(lib, rules, song_count, False)
        actual_count = sum(1 if song.title == "same artist" else 0 for song in result_songs)
        expected_count = song_count / 100 * expected_percent
        self.assertTrue(actual_count == expected_count,
                        "expected {} new songs, found {}:\n{}\n\nList of original songs:\n{}".format(
                            expected_count, actual_count,
                            self._print_songs(result_songs), self._print_songs(songs)))
    def test_limit_amount_of_low_rating(self):

        rules = Rules()
        songs = []

        rules.limit_low_rating_percent = 10

        expected_percent = rules.limit_low_rating_percent
        song_count = rules.limit_low_rating_percent

        for i in range(song_count):
            song = self._song("low rating", True)
            song.rating = 20
            songs.append(song)

        for i in range(song_count):
            song = self._song("high rating", True)
            self._song_played_days_ago(song, rules.star_3_min_days + 1)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(
            lib, rules, song_count, False)
        actual_count = sum(1 if song.title == "low rating" else 0
                           for song in result_songs)
        expected_count = song_count / 100 * expected_percent
        self.assertTrue(
            actual_count == expected_count,
            "expected {} new songs, found {}:\n{}\n\nList of original songs:\n{}"
            .format(expected_count, actual_count,
                    self._print_songs(result_songs), self._print_songs(songs)))
Exemple #6
0
    def preview_playlist_command(self, lib, opts, args):
        name_column_length = 60
        count = 10

        self._log.info(config.user_config_path())

        if opts.count:
            count = int(opts.count)

        if opts.playlist:
            if opts.playlist not in _settings.playlists:
                self._log.error(u'Playlist not defined: {}'.format(opts.playlist))
                return
            query = _settings.playlists[opts.playlist].query.split(u" ")
        else:
            query = decargs(args)

        query = u" ".join(query)
        query = ignore_deleted_in_query(query)
        items = playlist_generator.generate_playlist(lib, _settings.rules, count, opts.shuffle, query)

        for item in items:
            score_string = ", ".join(['%s: %s' % (key.replace("rule_", ""), value) for (key, value) in sorted(item.scores.items())])
            score_sum = round(sum(item.scores.values()), 2)
            item_name = unicode(item)
            if len(item_name) > name_column_length-5:
                item_name = item_name[:name_column_length-5] + "..."
            item_string = item_name.ljust(name_column_length)
            print_(u"Track: {0} Scores: {1}=[{2}]".format(item_string, score_sum, score_string))
    def test_limit_amount_of_same_artist(self):

        rules = Rules()
        songs = []

        rules.limit_artists_percent = 10

        expected_percent = rules.limit_artists_percent
        song_count = rules.limit_artists_percent

        for i in range(song_count):
            song = self._song("same artist", False)
            songs.append(song)

        for i in range(song_count):
            song = self._song("different artist", True)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(
            lib, rules, song_count, False)
        actual_count = sum(1 if song.title == "same artist" else 0
                           for song in result_songs)
        expected_count = song_count / 100 * expected_percent
        self.assertTrue(
            actual_count == expected_count,
            "expected {} new songs, found {}:\n{}\n\nList of original songs:\n{}"
            .format(expected_count, actual_count,
                    self._print_songs(result_songs), self._print_songs(songs)))
Exemple #8
0
def playlist_by_name(name):
    print("getting playlist: " + name)
    query = _settings.playlists[name].query
    query = ignore_deleted_in_query(query)
    tracks = playlist_generator.generate_playlist(g.lib, _settings.rules, 4, True, query)

    return tracks
Exemple #9
0
def playlist_by_name(name):
    print("getting playlist: " + name)
    query = _settings.playlists[name].query
    query = ignore_deleted_in_query(query)
    tracks = playlist_generator.generate_playlist(g.lib, _settings.rules, 4,
                                                  True, query)

    return tracks
Exemple #10
0
def preview_playlist():
    query = request.args.get('query')
    print("Query: " + query)
    if query is None:
        bad_request("query parameter is required")

    print("getting tracks")
    query = ignore_deleted_in_query(query)
    tracks = playlist_generator.generate_playlist(g.lib, _settings.rules, 30, True, query)

    return tracks
Exemple #11
0
def preview_playlist():
    query = request.args.get('query')
    print("Query: " + query)
    if query is None:
        bad_request("query parameter is required")

    print("getting tracks")
    query = ignore_deleted_in_query(query)
    tracks = playlist_generator.generate_playlist(g.lib, _settings.rules, 30,
                                                  True, query)

    return tracks
    def test_limit_new_albums_by_not_new_song(self):

        rules = Rules()
        rules.limit_new_albums_count = 1
        rules.limit_new_songs_percent = 100
        rules.limit_artists_percent = 100

        songs = []
        song_count = 5
        for i in range(song_count * 2):
            song = self._song("new songs", unique_artist_album=False)
            song.rating = 0
            songs.append(song)

        for i in range(song_count):
            song = self._song("high rating", unique_artist_album=False)
            self._song_played_days_ago(song, rules.star_3_min_days + 1)
            songs.append(song)

        # this song isn't technically new but it is used to find other new songs
        song = self._song("expected new song", unique_artist_album=False)
        song["playcount"] = 3
        songs.append(song)

        song = self._song("expected new song", unique_artist_album=False)
        song.rating = 0
        songs.append(song)

        lib = TestLib(songs)
        result_songs = playlist_generator.generate_playlist(
            lib, rules, song_count, False)

        error_info = "\n\nResult songs:\n{}\n\nList of original songs:\n{}".format(
            self._print_songs(result_songs), self._print_songs(songs))

        specific_song_found = any(result_song.title == "expected new song"
                                  for result_song in result_songs)
        self.assertTrue(
            specific_song_found,
            "expected 'expected new song' that wasn't found" + error_info)

        new_songs_count = sum(1 if song.title == "new songs" else 0
                              for song in result_songs)
        self.assertTrue(
            new_songs_count == 0,
            "expected 0 new songs, found {}".format(new_songs_count) +
            error_info)
    def test_prefer_songs_played_long_ago(self):

        rules = Rules()
        songs = []

        for i in range(5):
            song = self._song("played now", True)
            self._song_played_days_ago(song, rules.play_last_time_max_days / 10)
            songs.append(song)

        for i in range(5, 10):
            song = self._song("played long time ago", True)
            self._song_played_days_ago(song, rules.play_last_time_max_days)
            songs.append(song)

        lib = TestLib(songs)

        result_songs = playlist_generator.generate_playlist(lib, rules, 5, False)
        self.assertTrue(all(result_song.title == "played long time ago" for result_song in result_songs),
                        "found a recently played song in:\n" + self._print_songs(
                            result_songs) + "\n\nList of original songs:\n" + self._print_songs(songs))
Exemple #14
0
    def preview_playlist_command(self, lib, opts, args):
        name_column_length = 60
        count = 10

        self._log.info(config.user_config_path())

        if opts.count:
            count = int(opts.count)

        if opts.playlist:
            if opts.playlist not in _settings.playlists:
                self._log.error(u'Playlist not defined: {}'.format(
                    opts.playlist))
                return
            query = _settings.playlists[opts.playlist].query.split(u" ")
        else:
            query = decargs(args)

        query = u" ".join(query)
        query = ignore_deleted_in_query(query)
        items = playlist_generator.generate_playlist(lib, _settings.rules,
                                                     count, opts.shuffle,
                                                     query)

        for item in items:
            score_string = ", ".join([
                '%s: %s' % (key.replace("rule_", ""), value)
                for (key, value) in sorted(item.scores.items())
            ])
            score_sum = round(sum(item.scores.values()), 2)
            item_name = unicode(item)
            if len(item_name) > name_column_length - 5:
                item_name = item_name[:name_column_length - 5] + "..."
            item_string = item_name.ljust(name_column_length)
            print_(u"Track: {0} Scores: {1}=[{2}]".format(
                item_string, score_sum, score_string))