Commits

Vladimir Kolev  committed f943edd

Added new options to the preferences dialog:
Download speed - Can set a maximum download speed - 0 means no speed limit
Filename pattern - Can set the way the filename is generated when downloading

  • Participants
  • Parent commits 8725305

Comments (0)

Files changed (3)

File data/preferenes_dialog.ui

           </packing>
         </child>
         <child>
+          <object class="GtkFrame" id="frame2">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkVBox" id="vbox3">
+                    <property name="visible">True</property>
+                    <property name="spacing">4</property>
+                    <child>
+                      <object class="GtkHBox" id="hbox7">
+                        <property name="visible">True</property>
+                        <child>
+                          <object class="GtkLabel" id="label6">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Maximum download speed: </property>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSpinButton" id="spinbutton1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">&#x2022;</property>
+                            <property name="overwrite_mode">True</property>
+                            <property name="adjustment">adjustment1</property>
+                            <property name="climb_rate">0.5</property>
+                            <property name="digits">2</property>
+                            <property name="snap_to_ticks">True</property>
+                            <property name="numeric">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label7">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;b&gt;Kb/s&lt;/b&gt;</property>
+                            <property name="use_markup">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="padding">5</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkVBox" id="vbox4">
+                        <property name="visible">True</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox8">
+                            <property name="visible">True</property>
+                            <property name="homogeneous">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label8">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">File renaming pattern:</property>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkEntry" id="entry1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x2022;</property>
+                              </object>
+                              <packing>
+                                <property name="padding">3</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label9">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;b&gt;You can use the following placeholders:&lt;/b&gt;
+	&lt;b&gt;{artist}&lt;/b&gt; - The name of the artist
+	&lt;b&gt;{song}&lt;/b&gt; - The name of the song
+	&lt;b&gt;{album}&lt;/b&gt; - The album name</property>
+                            <property name="use_markup">True</property>
+                          </object>
+                          <packing>
+                            <property name="fill">False</property>
+                            <property name="padding">3</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="label5">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Download options&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">5</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkHSeparator" id="hseparator1">
             <property name="visible">True</property>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="position">5</property>
+            <property name="position">6</property>
           </packing>
         </child>
         <child>
           <packing>
             <property name="expand">False</property>
             <property name="padding">5</property>
-            <property name="position">6</property>
+            <property name="position">7</property>
           </packing>
         </child>
       </object>
     </child>
   </object>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="value">100</property>
+    <property name="upper">10000</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
 </interface>

File gsharkdown.py

         CONFIG['scrobbling'] = 0
         CONFIG['lastuser'] = ""
         CONFIG['lastpass'] = ""
+
     try:
         if HAVE_NOTIFY:
             test = CONFIG['show_notification']
         test = CONFIG['startup_update_check']
     except KeyError:
         CONFIG['startup_update_check'] = 1
+    try:
+        test = CONFIG['speed_limit']
+    except:
+        CONFIG['speed_limit'] = 0
+
+    try:
+        test = CONFIG['file_pattern']
+    except KeyError:
+        CONFIG['file_pattern'] = "{artist} - {song}"
+
     CONFIG.write()
 
 else:
     CONFIG['lastpass'] = ""
     CONFIG['startup_update_check'] = 1
     CONFIG['quit_without_confirmation'] = 1
+    CONFIG['speed_limit'] = 0
+    CONFIG['file_pattern'] = "{artist} - {song}"
     CONFIG.write()
 
 
         self.quit_without_confirmation = builder.get_object("checkbutton1")
         self.quit_without_confirmation.set_active(int(CONFIG['quit_without_confirmation']))
         self.bubble = builder.get_object("checkbutton2")
+        self.speed = builder.get_object("spinbutton1")
+        self.speed.set_value(int(CONFIG['speed_limit']))
+        self.file_pattern = builder.get_object("entry1")
+        self.file_pattern.set_text(CONFIG['file_pattern'])
         self.startup_check = builder.get_object("checkbutton4")
         self.startup_check.set_active(int(CONFIG['startup_update_check']))
         if HAVE_NOTIFY:
         else:
             CONFIG['startup_update_check'] = 0
 
+        CONFIG['file_pattern'] = self.file_pattern.get_text()
+        CONFIG['speed_limit'] = self.speed.get_value_as_int()
+
         if self.scrobble.get_active():
             CONFIG['scrobbling'] = 1
             CONFIG['lastuser'] = self.lastuser.get_text()

File lib/tfuncs.py

 locale.bindtextdomain(APP, DIR)
 gettext.bindtextdomain(APP, DIR)
 gettext.textdomain(APP)
-gettext.install(APP, localedir=DIR, unicode=True)
+gettext.install(APP, localedir = DIR, unicode = True)
 
 
 class InitThread(threading.Thread):
 
 class DownloadThread(threading.Thread):
 
-    def __init__(self, _window, _song, _filename):
+    def __init__(self, _window, _song, _filename, _speed = 0):
         """
         _window: The main window object
         _song: The song to download
         _filename: The full path file name to download the song
         """
         threading.Thread.__init__(self)
-        
+
         self.win = _window
-        
+
         self.filename = _filename
         try:
             self.file = open(self.filename, "w")
                 _("Failed to create '%s' for writing.") % self.filename)
             error.show_all()
             raise
-        
+
         self.song = _song
         self.songid = _song["SongID"]
+        self.speed = _speed
         self._stop = threading.Event()
-        
+
         self.iter = self.win.downloads.append([os.path.basename(self.filename), self.songid, 0, "", self])
         self.win.update_downloads_count()
 
         except Exception, e:
             print e
             return
-        
+
         try:
             url = "http://" + key["result"]["%s" % self.songid]["ip"] + "/stream.php"
             url = str(url)
             c.setopt(pycurl.FILE, self.file)
             c.setopt(pycurl.POST, True)
             c.setopt(pycurl.NOSIGNAL, True)
+            if self.speed != 0:
+                c.setopt(pycurl.MAX_RECV_SPEED_LARGE, self.speed)
             c.setopt(pycurl.POSTFIELDS, str("streamKey=" + key["result"]["%s" % self.songid]["streamKey"]))
             c.perform()
             self.file.close()
                 mb = 1024 ** 2
                 self.set_value(2, progress)
                 self.set_value(3, "%.02f MB" % (downloadTotal / mb))
-                
+
         if self._stop.isSet():
             return True
         else:
             return False
-       
+
     def _remove_download(self):
         self.win.downloads.remove(self.iter)
         self.iter = None
         self.win.update_downloads_count()
-        
+
     def set_value(self, column, value):
         try:
             self.win.downloads.set_value(self.iter, column, value)
 #            self.update_buttons(new)
 #        return gst.BUS_PASS
 
-    def on_stopped(self, config, widget=None, data=None):
+    def on_stopped(self, config, widget = None, data = None):
         """
         Called when the player reaches the end of the stream
         sets state gst.STATE_NULL and calls the play_next 
 #            self.win.play_button.set_stock_id(gtk.STOCK_MEDIA_PLAY)
 #        else:
 #            self.win.play_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
-            
+
 
 class KeyListenerThread(threading.Thread):
 
         Run as a dbus deamon
         """
         try:
-            dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+            dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
             bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
             bus_object = bus.get_object('org.gnome.SettingsDaemon',
                                 '/org/gnome/SettingsDaemon/MediaKeys')
-    
+
             dbus_interface = 'org.gnome.SettingsDaemon.MediaKeys'
             bus_object.GrabMediaPlayerKeys("MyMultimediaThingy", 0,
-                                  dbus_interface=dbus_interface)
+                                  dbus_interface = dbus_interface)
 
             bus_object.connect_to_signal('MediaPlayerKeyPressed',
                                 self.on_media_key)
         except:
             pass
-    
+
     def on_media_key(self, comes_from, what):
         """
         If a key was press see where it comes from and what key it is
 
 
 class UpdateThread(threading.Thread):
-    
+
     def __init__(self, _basepath, _updatemsg, _noupdate, _secondary):
         """
         Thread for comparing the local version with the remote. Accepts 
         self.noupdate = _noupdate
         self.secondary = _secondary
         self.checkurl = 'http://bitbucket.org/vkolev/gsharkdown/raw/tip/VERSION'
-        
+
     def run(self):
         local = open("%s/VERSION" % self.path, 'r')
         localversion = local.read().replace('\n', '')
         threading.Thread.__init__(self)
         self.parent = _parent
         self.iter = _iter
-    
+
     def run(self):
         cover_url = self.parent.playlist_song(self.iter)['CoverArtFilename']
         pixbuf = None
-        
+
         try:
             url = "http://beta.grooveshark.com/static/amazonart/s%s"
             response = urllib2.urlopen(url % cover_url)
             pixbuf = self.parent.create_cornered_image(image)
         except:
             pixbuf = self.parent.create_default_track_icon()
-            
+
         self.parent.playlist[self.iter][1] = pixbuf