Commits

Vladimir Kolev committed 83f9e7b

Implemented play option and removed download all

Comments (0)

Files changed (2)

     gsd-cli search <term>
     gsd-cli play <songid> [--player <executable>]
     gsd-cli download <songid> [-o <file>]
-    gsd-cli dall <term> [--folder <foldername>]
     gsd-cli -h | --help
     gsd-cli -v | --version
 
     --no-color      Don't use colors
     --player        Player to use
     --file          Save the mp3 in a specified filepath
-    --folder        Create new folder at current position to download list
     -h --help       Show help
     -v --version    Show version
 
 import os
 import sys
 import urllib
+import subprocess
 from progressbar import Bar, ETA, Percentage, FileTransferSpeed, RotatingMarker, ProgressBar
 from termcolor import colored
 import groove
         self.pbar = None
 
     def start(self):
+        # Interactive search for a song
         if self.args.get('search'):
             search = ""
             if self.args.get('<term>'):
             else:
                 self.return_warning("Nothing to search for")
 
+        # Play a song by songid
+        elif self.args.get('play', False):
+            songid = None
+            player = None
+            if self.args.get("<songid>"):
+                songid = self.args.get("<songid>", False)
+            else:
+                self.return_error('No songid specified.')
 
-        elif self.args.get('play', False):
-            songid = ""
-            player = ""
-            if self.args.get("<song:id>"):
-                songid = self.args.get("<song:id>", False)
-            else:
-                self.return_error('No song:id specified.')
-            if self.args.get("--player"):
+            if self.args.get("--player", False):
                 player = self.args.get('<executable>')
             else:
                 self.return_error("No player specified.")
-            print "Playing %s in %s ..." % (songid, player)
 
+            if songid is not None:
+                try:
+                    groove.init()
+                    response = groove.getStreamKeyFromSongIDEx(songid)
+                    playurls = "http://%s/stream.php?streamKey=%s"
+                    songurl = playurls % (response['result']['%s' % songid]['ip'],
+                            response['result']['%s' % songid]['streamKey'])
+                    subprocess.call([player, songurl])
+                except Exception:
+                    self.return_error("Song with this ID was not found")
+                    sys.exit()
+
+
+        # Download a song by id
         elif self.args.get('download', False):
             songid = ""
             songurl = None
             if songurl is not None:
                 self._dlFile(songurl, outfile)
 
-        elif self.args.get('dall', False):
-            print self.args
-            search = ""
-            outdir = ""
-            if self.args.get('<term>'):
-                search = self.args.get('<term>', False)
-
-            if self.args.get('--folder', False):
-                outdir = self.args.get('<foldername>', False)
-
-            print "Downloading all from %s in %s ..." % (search, outdir)
 
     def _dlFile(self, songurl, path):
         widgets = [colored('Downloading: ', 'blue', attrs=['bold']),