Mercurial > audlegacy
annotate contrib/lap.py @ 4812:a7b80f765d6f
moved libSAD.h to src/audlegacy for the path for header files.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 26 Nov 2008 02:56:18 +0900 |
parents | 9da616784f11 |
children |
rev | line source |
---|---|
3255
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
2 """Locate and Play |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
3 Author: Stephan Sokolow (deitarion/SSokolow) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
4 License: GNU GPL-2 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
5 Version: 1.0 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
6 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
7 Description: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
8 - A quick wrapper to make playing songs via the local command quick and easy. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
9 - Works with any player which implements the MPRIS standard for remote control via D-Bus. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
10 - Accepts multiple space- and/or comma-separated choices after presenting the results. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
11 - Can enqueue or enqueue and play. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
12 - Can show full paths or just filenames. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
13 - Will behave in a sane fashion when asked to enqueue and play multiple files. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
14 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
15 TODO: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
16 - Complete the list of extensions for ModPlug, Embedded MPlayer (plugins-ugly), and UADE (3rd-party) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
17 - Support sticking a 'q' in the result to choose enqueue on the fly |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
18 - Support an "all" keyword and an alternative to Ctrl+C for cancelling. (maybe 0) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
19 """ |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
20 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
21 ADLIB_EXTS = ['.a2m', '.adl', '.adlib', '.amd', '.bam', '.cff', '.cmf', '.d00', '.dfm', '.dmo', '.dro', '.dtm', '.hsc', '.hsp', |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
22 '.jbm', '.ksm', '.laa', '.lds', '.m', '.mad', '.mkj', '.msc', '.mtk', '.rad', '.raw', '.rix', '.rol', '.sat', |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
23 '.sa2', '.sci', '.sng', '.imf', '.wlf', '.xad', '.xsm'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
24 CONSOLE_EXTS = ['.adx', '.ay', '.gbs', '.gym', '.hes', '.kss', '.minipsf', '.nsf', '.nsfe', '.psf', '.sap', '.sid', '.spc', |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
25 '.vgm', '.vgz', '.vtx', '.ym'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
26 MIDI_EXTS = ['.mid', '.midi', '.rmi'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
27 MODULE_EXTS = [ '.it', ',mod', '.s3m', '.stm', '.xm'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
28 PLAYLIST_EXTS = ['.cue', '.m3u', '.pls', '.xspf'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
29 WAVEFORM_EXTS = ['.aac', '.aif', '.aiff', '.au', '.flac', '.m4a', '.mp2', '.mp3', '.mpc', '.ogg', '.snd', '.tta', '.voc', '.wav', |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
30 '.wma', '.wv'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
31 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
32 # Edit these lines to choose the kind of files to be filtered for. By default, playlist extensions are excluded. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
33 OK_EXTS = WAVEFORM_EXTS + MODULE_EXTS + CONSOLE_EXTS + MIDI_EXTS + ADLIB_EXTS |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
34 # If you want true format filtering, YOU write the mimetype cache. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
35 USE_PAGER = False # Should we page output if it's more than a screenful? |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
36 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
37 locate_command = ['locate', '-i'] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
38 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
39 # ========== Configuration Ends ========== |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
40 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
41 import fnmatch, optparse, os, subprocess |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
42 from dbus import Bus, DBusException |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
43 |
3352
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
44 # Support audtool as a fallback but don't depend on it |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
45 try: import subprocess |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
46 except ImportError: pass |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
47 |
3255
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
48 # Use readline if available but don't depend on it |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
49 try: import readline |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
50 except ImportError: pass |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
51 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
52 # connect to DBus |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
53 bus = Bus(Bus.TYPE_SESSION) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
54 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
55 def get_results(query): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
56 """Given a query or series of queries for the locate command, run them.""" |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
57 results, cmd = [], locate_command + (isinstance(query, basestring) and [query] or query) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
58 for line in subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
59 result = line.strip() |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
60 if os.path.splitext(result)[1] in OK_EXTS: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
61 results.append(result) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
62 results.sort() |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
63 return results |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
64 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
65 def filter(results, filters): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
66 for filter in filters: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
67 results = [x for x in results if fnmatch.fnmatch(x.lower(), '*%s*' % filter.lower())] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
68 return results |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
69 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
70 def makeMenu(results, strip_path=True): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
71 for pos, val in enumerate(results): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
72 val = strip_path and os.path.split(val)[1] or val |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
73 print "%3d) %s" % (pos+1, val) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
74 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
75 def addTrack(path, play=False): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
76 try: |
3352
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
77 file_url = 'file://' + path |
3255
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
78 mp = bus.get_object('org.freedesktop.MediaPlayer', '/TrackList') |
3352
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
79 mp.AddTrack(file_url, play) |
3255
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
80 except DBusException: |
3352
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
81 try: |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
82 if subprocess.call(['audtool','playlist-addurl',file_url]): |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
83 print "ERROR: audtool fallback returned an error for: %s" % file_url |
3362
9da616784f11
Fixed lap.py's -q option when used with the audtool fallback.
ssokolow@monolith.multiverse
parents:
3352
diff
changeset
|
84 elif play: |
3352
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
85 os.system('audtool playlist-jump `audtool playlist-length`; audtool playback-play') |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
86 except OSError: |
b35d905d1a83
Make contrib/lap.py support pre-DBus Audacious via an audtool-wrapping fallback.
ssokolow@monolith.multiverse
parents:
3351
diff
changeset
|
87 print "ERROR: Unable to call audtool as a fallback for: %s" % file_url |
3255
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
88 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
89 def parseChoice(inString): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
90 try: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
91 return [int(inString)] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
92 except ValueError: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
93 choices = [] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
94 for x in inString.replace(',',' ').split(): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
95 try: choices.append(int(x)) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
96 except ValueError: print "Not an integer: %s" % x |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
97 return choices |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
98 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
99 if __name__ == '__main__': |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
100 try: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
101 op = optparse.OptionParser() |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
102 op.add_option("-q", "--enqueue", action="store_true", dest="enqueue", default=False, |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
103 help="Don't start the song playing after enqueueing it.") |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
104 op.add_option("-p", "--show_path", action="store_true", dest="show_path", default=False, |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
105 help="Show the full path to each result.") |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
106 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
107 (opts, args) = op.parse_args() |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
108 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
109 results = (len(args) > 0) and get_results(args.pop(0)) or [] |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
110 results = filter(results, args) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
111 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
112 def takeChoice(index, play=False): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
113 index = index - 1 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
114 if index >= 0 and index < len(results): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
115 addTrack(results[index], play) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
116 else: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
117 print "Invalid result index: %s" % (index + 1) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
118 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
119 if len(results): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
120 makeMenu(results, not opts.show_path) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
121 choices = parseChoice(raw_input("Choice(s) (Ctrl+C to cancel): ")) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
122 |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
123 if len(choices): |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
124 takeChoice(choices.pop(0), not opts.enqueue) |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
125 for item in choices: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
126 takeChoice(item, False) # This ensures proper behaviour with no --enqueue and multiple choices. |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
127 else: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
128 print "No Results" |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
129 except KeyboardInterrupt: |
3c3a3f3c2269
- Added my "Locate and Play" script to contrib.
"Stephan Sokolow <http://www.ssokolow.com/ContactMe>"
parents:
diff
changeset
|
130 pass |