From: kaliko Date: Wed, 11 Jun 2014 15:35:34 +0000 (+0200) Subject: Use last track in queue instead of currently played X-Git-Tag: 0.12.0~8 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;ds=sidebyside;h=28745ed78f2c3020f35268e7609cf937c9fd5175;p=mpd-sima.git Use last track in queue instead of currently played --- diff --git a/data/man/mpd-sima.1 b/data/man/mpd-sima.1 index 9fedc50..f2fffd6 100644 --- a/data/man/mpd-sima.1 +++ b/data/man/mpd-sima.1 @@ -2,12 +2,12 @@ .\" Title: mpd-sima .\" Author: Jack Kaliko .\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 06/10/2014 +.\" Date: 06/11/2014 .\" Manual: mpd-sima 0.12.0 User Manual .\" Source: mpd-sima .\" Language: English .\" -.TH "MPD\-SIMA" "1" "06/10/2014" "mpd-sima" "mpd-sima 0.12.0 User Manual" +.TH "MPD\-SIMA" "1" "06/11/2014" "mpd-sima" "mpd-sima 0.12.0 User Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -28,7 +28,7 @@ .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" -mpd-sima \- mpd\-sima will try to maintain some titles ahead in your play list following different policies\&. +mpd-sima \- mpd\-sima will try to maintain some titles ahead in the queue following different policies\&. .SH "SYNOPSIS" .HP \w'\fBmpd\-sima\fR\ 'u \fBmpd\-sima\fR [\fB\-\-daemon\fR] [\fB\-\-config=\fR\fIconf_file\fR] [\fB\-\-var_dir=\fR\fIvar_directory\fR] [\fB\-\-pid=\fR\fIpid_file\fR] [\fB\-\-log=\fR\fIlog_file\fR] [\fB\-\-log\-level=\fR\fIlog_level\fR] [\fB\-\-host=\fR\fImpd_host\fR] [\fB\-\-mpd_port=\fR\fImpd_port\fR] @@ -46,7 +46,8 @@ At start up default configuration is first overridden by user configuration in m the section called \(lqFILES\(rq) and finally command lines options are honored\&. For instance you can override default MPD_HOST set in defaults (localhost) or in your configuration file with \fB\-S\ \&my_mpd_server\fR option\&. For default configuration see -the section called \(lqCONFIGURATION\(rq\&. +the section called \(lqCONFIGURATION\(rq\&. See also environment variables special case for MPD host and port in +the section called \(lqENVIRONMENT\(rq\&. .SH "EXAMPLE" .SS "Launch as a system service (d\(aemon)\&." .PP @@ -122,14 +123,17 @@ Use the specific file to set up configuration instead of looking for the default user configuration file\&. .br Default is to look for -\fB$XDG_CONFIG_HOME/mpd_sima/mpd_sima\&.cfg\fR\&. Concerning this file see also +\fB$XDG_CONFIG_HOME/mpd_sima/mpd_sima\&.cfg\fR\&. +.br + +CLI option overrides any equivalent mentioned in configuration file, ie\&. launching mpd\-sima with \*(Aq\fB\-\-port\fR\*(Aq CLI option will ignore port setting in configuration file\&. +.br + +For more details on configuration file cf\&. +\fBmpd_sima.cfg\fR(5), see also the section called \(lqFILES\(rq\&. .br -Pay attention: Because you load a specific configuration file from command line interface -\fIdoes not mean\fR -it will override others options pass to mpd_sima\&. In other words launching with -\fB\-P 6666\fR -will override port setting whatever the configuration file your using, default or command line specified\&. + .RE .PP \fB\-\-var_dir=\fR\fB\fIvar_directory\fR\fR @@ -254,7 +258,7 @@ DEFAULTS .RS 4 Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env\&. var\&. if set)\&. .sp -The default behavior is to add one track, this track is to be chosen among titles from artists similar to the artist of the currently played track\&. MPD_sima will add one track when the play list is one track long\&. +The default behavior is to add one track, this track is to be chosen among titles from artists similar to the artist of the currently played track\&. MPD_sima will add one track when the unplayed queue is one track long\&. .sp To change these defaults, use the configuration file mpd_sima\&.cfg diff --git a/data/man/mpd_sima.1.xml b/data/man/mpd_sima.1.xml index 5362cb9..f187b5e 100644 --- a/data/man/mpd_sima.1.xml +++ b/data/man/mpd_sima.1.xml @@ -57,7 +57,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ &dhpackage; - &dhpackage; will try to maintain some titles ahead in your play list following different policies. + &dhpackage; will try to maintain some titles ahead in the queue following different policies. @@ -100,7 +100,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ command lines options are honored. For instance you can override default MPD_HOST set in defaults (localhost) or in your configuration file with -S my_mpd_server option. For default - configuration see . + configuration see . See also environment + variables special case for MPD host and port in . + EXAMPLE @@ -167,11 +169,19 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Verbosity in [debug,info,warning,error].Default is to log info messages. - + - Use the specific file conf_file to set up configuration instead of looking for the default user configuration file.Default is to look for $XDG_CONFIG_HOME/mpd_sima/mpd_sima.cfg. Concerning this file see also .Pay attention: Because you load a specific configuration file from command line interface does not mean it will override others options pass to mpd_sima. In other words launching with will override port setting whatever the configuration file your using, default or command line specified. + Use the specific file conf_file to set up + configuration instead of looking for the default user + configuration file.Default is to look for + $XDG_CONFIG_HOME/mpd_sima/mpd_sima.cfg. + CLI option overrides any equivalent mentioned in configuration file, ie. launching &dhutils; with '' CLI option will ignore port setting in configuration file. + For more details on configuration file cf. + mpd_sima.cfg + 5, see also . + @@ -244,7 +254,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ this track is to be chosen among titles from artists similar to the artist of the currently played track. MPD_sima will add one track when the - play list is one track long. + unplayed queue is one track long. To change these defaults, use the configuration file mpd_sima.cfg diff --git a/data/man/mpd_sima.cfg.5 b/data/man/mpd_sima.cfg.5 index 95bc337..48c882d 100644 --- a/data/man/mpd_sima.cfg.5 +++ b/data/man/mpd_sima.cfg.5 @@ -2,12 +2,12 @@ .\" Title: mpd_sima.cfg .\" Author: Jack Kaliko .\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 06/10/2014 +.\" Date: 06/11/2014 .\" Manual: mpd-sima 0.12.0 User Manual .\" Source: mpd-sima .\" Language: English .\" -.TH "MPD_SIMA\&.CFG" "5" "06/10/2014" "mpd-sima" "mpd-sima 0.12.0 User Manual" +.TH "MPD_SIMA\&.CFG" "5" "06/11/2014" "mpd-sima" "mpd-sima 0.12.0 User Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -28,7 +28,7 @@ .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" -mpd_sima.cfg \- mpd\-sima will try to maintain some titles ahead in your play list following different policies\&. This manual document the configuration file for mpd\-sima\&. +mpd_sima.cfg \- mpd\-sima will try to maintain some titles ahead in the queue following different policies\&. This manual document the configuration file for mpd\-sima\&. .SH "DESCRIPTION" .PP This manual page documents briefly @@ -142,7 +142,7 @@ How far to look back in history to avoid to play twice the same track/title (dur .PP \fBqueue_length=\fR\fI1\fR .RS 4 -This value triggers queue process if the play list length is less than specified queue_length\&. +This value triggers queue process if the queue length is less than specified queue_length\&. .RE .PP \fBuser_db=\fR\fIfalse\fR @@ -192,7 +192,7 @@ crop plugin\*(Aqs configuration: .PP \fBconsume=\fR\fI0\fR .RS 4 -How many played tracks to keep in the play list\&. Allow to maintain a fixed length play list\&. Set to 0 to keep all played tracks\&. +How many played tracks to keep in the queue\&. Allow to maintain a fixed length queue\&. Set to 0 to keep all played tracks\&. .RE .SS "RandomFallback section" .PP @@ -315,7 +315,7 @@ If set to "false", caching is still done but in memory\&. .RE .SH "QUEUE MODES" .PP -mpd\-sima offers different queue modes\&. All of them pick up tracks from artists similar to the one currently played\&. +mpd\-sima offers different queue modes\&. All of them pick up tracks from artists similar to the last track in the queue\&. .PP mpd\-sima tries preferably to chose among unplayed artists or at least not recently played artist\&. Concerning track and album queue modes titles are chosen purely at random among unplayed tracks\&. .PP diff --git a/data/man/mpd_sima.cfg.5.xml b/data/man/mpd_sima.cfg.5.xml index cb6f47d..3ddd938 100644 --- a/data/man/mpd_sima.cfg.5.xml +++ b/data/man/mpd_sima.cfg.5.xml @@ -57,8 +57,8 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ &dhutils; - &dhpackage; will try to maintain some titles ahead in your play - list following different policies. This manual document the + &dhpackage; will try to maintain some titles ahead in the queue + following different policies. This manual document the configuration file for &dhpackage;. @@ -174,8 +174,8 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ 1 - This value triggers queue process if the play - list length is less than specified + This value triggers queue process if the queue + length is less than specified queue_length. @@ -224,8 +224,8 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ 0 - How many played tracks to keep in the play list. - Allow to maintain a fixed length play list. + How many played tracks to keep in the queue. + Allow to maintain a fixed length queue. Set to 0 to keep all played tracks. @@ -341,7 +341,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ QUEUE MODES &dhpackage; offers different queue modes. All of them pick up - tracks from artists similar to the one currently played. + tracks from artists similar to the last track in the queue. &dhpackage; tries preferably to chose among unplayed artists or at least not recently played artist. Concerning track and album queue modes titles are chosen purely at random among unplayed diff --git a/doc/Changelog b/doc/Changelog index 0506bd7..3e58411 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,6 +8,7 @@ sima v0.12.0 configuration file change internal database remains the same * Temporarily removed userdb feature + * Base artist for similarity is the last track queued -- kaliko jack UNRELEASED diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index c84c78c..fd15815 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -176,18 +176,11 @@ class WebService(Plugin): """ Retrieve similar artists from WebServive. """ - if artist is None: - curr = self.player.current.__dict__ - name = curr.get('artist') - mbid = curr.get('musicbrainz_artistid', None) - current = Artist(name=name, mbid=mbid) - else: - current = artist # initialize artists deque list to construct from DB as_art = deque() - as_artists = self.ws().get_similar(artist=current) - self.log.debug('Requesting {1} for "{0}"'.format(current, - self.ws.name)) + as_artists = self.ws().get_similar(artist=artist) + self.log.debug('Requesting {1} for "{0}"'.format(artist, + self.ws.name)) try: # TODO: let's propagate Artist type [as_art.append(str(art)) for art in as_artists] @@ -202,14 +195,14 @@ class WebService(Plugin): history = deque(self.history) history.popleft() depth = 0 - current = self.player.current + last_trk = self.player.playlist[-1] extra_arts = list() while depth < self.plugin_conf.getint('depth'): if len(history) == 0: break trk = history.popleft() if (trk.get_artist() in extra_arts - or trk.get_artist() == current.get_artist()): + or trk.get_artist() == last_trk.get_artist()): continue extra_arts.append(trk.get_artist()) depth += 1 @@ -222,16 +215,17 @@ class WebService(Plugin): if not similar: return ret_extra ret_extra.extend(self.get_artists_from_player(similar)) - if current.artist in ret_extra: - ret_extra.remove(current.artist) + if last_trk.artist in ret_extra: + ret_extra.remove(last_trk.artist) return ret_extra def get_local_similar_artists(self): """Check against local player for similar artists """ - current = self.player.current - self.log.info('Looking for artist similar to "{0.artist}"'.format(current)) - similar = self.ws_similar_artists() + tolookfor = self.player.playlist[-1].get_artist() + self.log.info('Looking for artist similar ' + 'to "{0.artist}"'.format(self.player.playlist[-1])) + similar = self.ws_similar_artists(tolookfor) if not similar: self.log.info('Got nothing from {0}!'.format(self.ws.name)) return [] @@ -372,11 +366,11 @@ class WebService(Plugin): def callback_need_track(self): self._cleanup_cache() - if not self.player.current: - self.log.info('No current track, cannot queue') + if len(self.player.playlist) == 0: + self.log.info('No last track, cannot queue') return None - if not self.player.current.artist: - self.log.warning('No artist set for the current track') + if not self.player.playlist[-1].artist: + self.log.warning('No artist set for the last track in queue') self.log.debug(repr(self.player.current)) return None self.queue_mode()