import random
from .track import Track
-from .meta import Album, Artist
+from .meta import Album, Artist, MetaContainer
class Plugin:
Move around items in alist in order to have first not recently
played (or about to be played) artists.
- :param list(str) alist: artist name list (Not an Artist object)
+ :param {Artist} alist: Artist objects list/container
"""
- queued_artist = {_.artist for _ in self.player.queue}
- not_queued_artist = set(alist) - queued_artist
+ queued_artist = MetaContainer([Artist(_.artist) for _ in self.player.queue])
+ not_queued_artist = alist - queued_artist
duration = self.main_conf.getint('sima', 'history_duration')
hist = []
for art in self.sdb.get_artists_history(alist,
hist.insert(0, art)
else:
hist.append(art)
- # Find not recently played (not in history)
+ # Find not recently played (not in history) & not in queue
reorg = [art for art in not_queued_artist if art not in hist]
reorg.extend(hist)
return reorg
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2009-2013, 2019 kaliko <kaliko@azylum.org>
+# Copyright (c) 2009-2013, 2019-2020 kaliko <kaliko@azylum.org>
# Copyright (c) 2009, Eric Casteleijn <thisfred@gmail.com>
# Copyright (c) 2008 Rick van Hattem
#
def get_artists_history(self, artists, duration=__HIST_DURATION__):
"""
+ :param list artists: list of object that can evaluate equality with
+ artist name, iterable of str or Artist object
"""
date = datetime.utcnow() - timedelta(hours=duration)
connection = self.get_database_connection()
# get them reorg to pick up best element
ret_extra = self.get_reorg_artists_list(ret_extra)
# tries to pickup less artist from extra art
- if len(ret) < 4:
- ret_extra = MetaContainer(ret_extra)
- else:
+ if len(ret) > 4:
ret_extra = MetaContainer(ret_extra[:max(4, len(ret))//2])
if ret_extra:
self.log.debug('extra found in library: %s',
# Move around similars items to get in unplayed|not recently played
# artist first.
self.log.info('Got %d artists in library', len(ret))
- candidates = self.get_reorg_artists_list(list(ret))
+ candidates = self.get_reorg_artists_list(ret)
if candidates:
self.log.info(' / '.join(map(str, candidates)))
return candidates
nb_album_add = 0
target_album_to_add = self.plugin_conf.getint('album_to_add')
for artist in artists:
- album = self.album_candidate(artist)
+ album = self.album_candidate(artist, unplayed=True)
+ if not album:
+ continue
nb_album_add += 1
candidates = self.player.find_tracks(album)
if self.plugin_conf.getboolean('shuffle_album'):
for artist in artists:
self.log.debug('Trying to find titles to add for "%r"', artist)
found = self.player.find_tracks(artist)
- random.shuffle(found)
if not found:
self.log.debug('Found nothing to queue for %s', artist)
continue
+ random.shuffle(found)
# find tracks not in history for artist
track_candidate = self.filter_track(found)
if track_candidate:
# local import
from ...lib.plugin import AdvancedPlugin
-from ...lib.meta import Artist
+from ...lib.meta import Artist, MetaContainer
from ...utils.utils import PluginException
queue_mode = self.plugin_conf.get('queue_mode', 'track')
target = self.plugin_conf.getint(f'{queue_mode}_to_add')
# look for artists acording to filter
- artists = self.player.list('artist', self.mpd_filter)
- random.shuffle(artists)
+ artists = MetaContainer([Artist(name=a) for a in self.player.list('artist', self.mpd_filter)])
+ if not artists:
+ self.log.info('Tags plugin found nothing to queue')
+ return candidates
artists = self.get_reorg_artists_list(artists)
- self.log.debug('Tags artists found: %s', ' / '.join(artists))
+ self.log.debug('Tags plugin found: %s', ' / '.join(map(str, artists)))
for artist in artists:
self.log.debug('looking for %s', artist)
- tracks = self.player.find_tracks(Artist(name=artist))
+ tracks = self.player.find_tracks(artist)
trk = self.filter_track(tracks)
if not trk:
continue