Commits

Vladimir Kolev  committed 947c1dc

Allow downloading from search results

  • Participants
  • Parent commits d1f4846

Comments (0)

Files changed (2)

 
 Usage:
     gsd-cli (search|play|download)
-    gsd-cli search <term> [--no-color]
+    gsd-cli search <term>
     gsd-cli play <songid> [--player <executable>]
     gsd-cli download <songid> [-o <file>]
     gsd-cli dall <term> [--folder <foldername>]
                             # Continue printing results
                             if key in ['c', 'C']:
                                 continue
+                            elif key in ['d', 'D']:
+                                try:
+                                    sid = int(raw_input(colored("Enter Song Number: ", 'white', attrs=['bold'])))
+                                    song_selected = results[sid]
+                                    filename = song_selected['ArtistName']+'-'+song_selected['SongName']+".mp3"
+                                    path = os.path.join(os.getcwd(), filename)
+                                    response = groove.getStreamKeyFromSongIDEx(song_selected['SongID'])
+                                    playurls = "http://%s/stream.php?streamKey=%s"
+                                    songurl = playurls % (response["result"]["%s" % song_selected['SongID']]["ip"],
+                                            response["result"]["%s" % song_selected['SongID']]["streamKey"])
+                                    self._dlFile(songurl, path)
+                                    continue
+                                except:
+                                    self.return_warning('You must enter an integer')
+                                    break
                             else:
                                 break
                     print colored("\t\tThis are all %d results" % (count), 'green', attrs=['bold'])
                     outfile = self.args.get('<file>', False)
 
             if songurl is not None:
-                widgets = [colored('Downloading: ', 'blue', attrs=['bold']),
-                        Percentage(), ' ', Bar(marker=RotatingMarker()), ' ',
-                        ETA(), ' ', FileTransferSpeed()]
-                self.pbar = ProgressBar(widgets=widgets)
-                urllib.urlretrieve(songurl, outfile, reporthook=self._dlProgress)
-                self.pbar.finish()
+                self._dlFile(songurl, outfile)
 
         elif self.args.get('dall', False):
             print self.args
 
             print "Downloading all from %s in %s ..." % (search, outdir)
 
+    def _dlFile(self, songurl, path):
+        widgets = [colored('Downloading: ', 'blue', attrs=['bold']),
+                Percentage(), ' ', Bar(marker=RotatingMarker()), ' ',
+                ETA(), ' ', FileTransferSpeed()]
+        self.pbar = ProgressBar(widgets=widgets)
+        urllib.urlretrieve(songurl, path, reporthook=self._dlProgress)
+        self.pbar.finish()
+
+
+
     def _dlProgress(self, count, blockSize, totalSize):
         if self.pbar.maxval is None:
             self.pbar.maxval = totalSize