mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 01:23:09 +01:00
Change spottily plugin output to use syserr for everything except printing the plugin tracks. Allows output to be piped.
This commit is contained in:
parent
d076e14515
commit
9330e49013
2 changed files with 26 additions and 26 deletions
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import print_function
|
||||
import sys
|
||||
import re
|
||||
import webbrowser
|
||||
import requests
|
||||
|
|
@ -42,7 +44,7 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
spotify_cmd.parser.add_option(
|
||||
'-m', '--mode', action='store',
|
||||
help='"open" to open spotify with playlist, '
|
||||
'"list" to copy/paste (default)'
|
||||
'"list" to print (default)'
|
||||
)
|
||||
spotify_cmd.parser.add_option(
|
||||
'-f', '--show_failures', action='store_true',
|
||||
|
|
@ -63,7 +65,7 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
self.config['show_failures'].set(True)
|
||||
|
||||
if self.config['mode'].get() not in ['list', 'open']:
|
||||
print self.config['mode'].get() + " is not a valid mode"
|
||||
self.warning(self.config['mode'].get() + " is not a valid mode")
|
||||
return False
|
||||
|
||||
self.opts = opts
|
||||
|
|
@ -80,7 +82,7 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
self.out("Your beets query returned no items, skipping spotify")
|
||||
return
|
||||
|
||||
print "Processing " + str(len(items)) + " tracks..."
|
||||
self.warning("Processing " + str(len(items)) + " tracks...")
|
||||
|
||||
for item in items:
|
||||
|
||||
|
|
@ -146,16 +148,17 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
failure_count = len(failures)
|
||||
if failure_count > 0:
|
||||
if self.config['show_failures'].get():
|
||||
print
|
||||
print str(failure_count) + \
|
||||
" track(s) did not match a Spotify ID"
|
||||
print "#########################"
|
||||
self.warning("\n#########################")
|
||||
self.warning(str(failure_count) +
|
||||
" track(s) did not match a Spotify ID")
|
||||
for track in failures:
|
||||
print "track:" + track
|
||||
print "#########################"
|
||||
self.warning("track:" + track)
|
||||
self.warning("#########################\n")
|
||||
else:
|
||||
print str(failure_count) + " track(s) did not match " + \
|
||||
self.warning(
|
||||
str(failure_count) + " track(s) did not match "
|
||||
"a Spotify ID, --show_failures to display"
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
|
@ -163,21 +166,21 @@ class SpotifyPlugin(BeetsPlugin):
|
|||
if results:
|
||||
ids = map(lambda x: x['id'], results)
|
||||
if self.config['mode'].get() == "open":
|
||||
print "Attempting to open Spotify with playlist"
|
||||
self.warning("Attempting to open Spotify with playlist")
|
||||
spotify_url = self.playlist_partial + ",".join(ids)
|
||||
webbrowser.open(spotify_url)
|
||||
|
||||
else:
|
||||
print
|
||||
print "Copy everything between the hashes and paste into " + \
|
||||
"a Spotify playlist"
|
||||
print "#########################"
|
||||
self.warning("")
|
||||
for item in ids:
|
||||
print unicode.encode(self.open_url + item)
|
||||
print "#########################"
|
||||
print(unicode.encode(self.open_url + item))
|
||||
self.warning("")
|
||||
else:
|
||||
print "No Spotify tracks found from beets query"
|
||||
self.warning("No Spotify tracks found from beets query")
|
||||
|
||||
def out(self, msg):
|
||||
if self.config['verbose'].get() or self.opts.verbose:
|
||||
print msg
|
||||
self.warning(msg)
|
||||
|
||||
def warning(self, msg):
|
||||
print(msg, file=sys.stderr)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
Spotify Plugin
|
||||
=====================
|
||||
|
||||
The ``spotify`` plugin generates Spotify playlists from tracks within the Beets library. Using the `Spotify Web API`_, any tracks that can be matched with a Spotify ID are returned, and the results can be either copy/pasted in to a playlist, or opened directly in Spotify.
|
||||
The ``spotify`` plugin generates Spotify playlists from tracks within the Beets library. Using the `Spotify Web API`_, any tracks that can be matched with a Spotify ID are returned, and the results can be either pasted in to a playlist, or opened directly in Spotify.
|
||||
|
||||
.. _Spotify Web API: https://developer.spotify.com/web-api/search-item/
|
||||
|
||||
|
|
@ -29,8 +29,6 @@ An example command, and it's output::
|
|||
|
||||
Processing 14 tracks...
|
||||
|
||||
Copy everything between the hashes and paste into a Spotify playlist
|
||||
#########################
|
||||
http://open.spotify.com/track/19w0OHr8SiZzRhjpnjctJ4
|
||||
http://open.spotify.com/track/3PRLM4FzhplXfySa4B7bxS
|
||||
http://open.spotify.com/track/0ci6bxPw8muHTmSRs1MOjD
|
||||
|
|
@ -45,7 +43,6 @@ An example command, and it's output::
|
|||
http://open.spotify.com/track/3aoAkxvRjwhXDajp5aSZS6
|
||||
http://open.spotify.com/track/7cG68oOj0pZYoSVuP1Jzot
|
||||
http://open.spotify.com/track/4qPtIDBT2iVQv13tjpXMDt
|
||||
#########################
|
||||
|
||||
Options for the command::
|
||||
|
||||
|
|
@ -54,7 +51,7 @@ Options for the command::
|
|||
Options:
|
||||
-h, --help show this help message and exit
|
||||
-m MODE, --mode=MODE "open" to open spotify with playlist, "list" to
|
||||
copy/paste (default)
|
||||
print (default)
|
||||
-f, --show_failures Print out list of any tracks that did not match a
|
||||
Sptoify ID
|
||||
-v, --verbose show extra output
|
||||
|
|
@ -77,7 +74,7 @@ Example config.yaml
|
|||
Examples of the configuration options::
|
||||
|
||||
spotify:
|
||||
mode: "open" # Default is list, shows the copy/paste output. open attempts to open directly in Spotify (only tested on Mac)
|
||||
mode: "open" # Default is list, shows the plugin output. open attempts to open directly in Spotify (only tested on Mac)
|
||||
region_filter: "US" # Filters tracks by only that market (2-letter code)
|
||||
show_faiulres: on # Displays the tracks that did not match a Spotify ID
|
||||
tiebreak: "first" # Need to break ties when then are multiple tracks. Default is popularity.
|
||||
|
|
@ -100,6 +97,6 @@ Examples of the configuration options::
|
|||
Spotify Plugin Modes
|
||||
---------------------
|
||||
|
||||
* ``list``: The default mode for the spotify plugin is to print out the playlist as a list of links. This list can then be copied and pasted in to a new or existing spotify playlist.
|
||||
* ``list``: The default mode for the spotify plugin is to print out the playlist as a list of links. This list can then be pasted in to a new or existing spotify playlist.
|
||||
* ``open``: This mode actually sends a link to your default webbrowser with instructions to open spotify with the playlist you created. Until this has been tested on all platforms, it will remain optional.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue