Commits

Vladimir Kolev committed 6211e42

Added option to search for song lyrics for a selected item from the playlist
Updated version to 0.3.2
Added library lyrdblib for searching the lyrdb webservice

Comments (0)

Files changed (6)

-0.3.1
+0.3.2

data/about_dialog.ui

-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.18"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkAboutDialog" id="aboutdialog1">
+    <property name="can_focus">False</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">About GrooveDown</property>
     <property name="window_position">center-on-parent</property>
     <property name="icon">gsharkdown_64.png</property>
     <property name="type_hint">dialog</property>
     <property name="program_name">gSharkDown</property>
-    <property name="version">0.3.1</property>
+    <property name="version">0.3.2</property>
     <property name="copyright" translatable="yes">(c) Vladimir Kolev 2011</property>
     <property name="comments" translatable="yes">Gnome-toolkit based desktop application for downloading music files from Grooveshark.com</property>
     <property name="website">https://bitbucket.org/vkolev/gsharkdown</property>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkHBox" id="hbox1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkImage" id="image1">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="stock">gtk-dialog-warning</property>
                     <property name="icon-size">6</property>
                   </object>
                   <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">&lt;b&gt;Downloading mp3s is illegal in some countries! Please check the low in your country.&lt;/b&gt;</property>
                     <property name="use_markup">True</property>
                     <property name="justify">center</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
+                    <property name="fill">True</property>
                     <property name="position">1</property>
                   </packing>
                 </child>
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="fill">True</property>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkHButtonBox" id="hbuttonbox1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="spacing">90</property>
                 <property name="layout_style">end</property>
                 <child>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="image">image3</property>
                   </object>
                   <packing>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="tooltip_text" translatable="yes">Flattr gSharkDow</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="image">image2</property>
                     <property name="relief">none</property>
                   </object>
                 </child>
               </object>
               <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">1</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">3</property>
           </packing>
         </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
       </object>
     </child>
   </object>
   <object class="GtkImage" id="image2">
     <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="pixbuf">flattr-badge-large.png</property>
   </object>
   <object class="GtkImage" id="image3">
     <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="icon_name">system-software-update</property>
   </object>
 </interface>

data/lyrics_dialog.ui

+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.24"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkDialog" id="dialog1">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Lyrics viewer</property>
+    <property name="default_width">500</property>
+    <property name="default_height">350</property>
+    <property name="icon_name">audio-x-generic</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">True</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">&lt;b&gt;Lyrics for:&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="padding">10</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">label</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <child>
+              <object class="GtkTextView" id="textview1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="pixels_above_lines">2</property>
+                <property name="pixels_below_lines">2</property>
+                <property name="editable">False</property>
+                <property name="wrap_mode">word</property>
+                <property name="buffer">textbuffer1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkTextBuffer" id="textbuffer1"/>
+</interface>

data/main_window.ui

               </packing>
             </child>
             <child>
+              <object class="GtkToolButton" id="toolbutton15">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="tooltip_text" translatable="yes">Search a lyrics for selected song from the playlist</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">Get Lyrics</property>
+                <property name="use_underline">True</property>
+                <property name="stock_id">gtk-file</property>
+                <signal name="clicked" handler="get_lyrics" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkSeparatorToolItem" id="toolbutton6">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
 from lib.tfuncs import t_play
 from lib.tfuncs import t_search
 from lib.tfuncs import t_key_listener
+import lib.lyrdblib
 import urllib2
 import webbrowser
 import pickle
             dialog.run()
             dialog.destroy()
 
+    def get_lyrics(self, widget, data=None):
+        """
+        Tries to retrieve lyrics for selected song from the playlist
+        """
+        select = self.play_view.get_selection().get_selected()
+        if select[1] != None:
+            index = self.playlist.get_path(select[1])[0]
+            song = self.playitems[index]
+            songid = lib.lyrdblib.search(song['ArtistName'],
+                                         song['SongName'])
+            if "ERROR" in songid:
+                self.show_error(songid)
+            else:
+                lyric = lib.lyrdblib.getlyrics(songid)
+                builder = gtk.Builder()
+                builder.add_from_file('%s/data/lyrics_dialog.ui' % BASEPATH)
+                lyrics = builder.get_object('dialog1')
+                songlabel = builder.get_object('label2')
+                songlabel.set_text(song['ArtistName'] + " - " + song['SongName'])
+                lyric_view = builder.get_object('textview1')
+                lyric_buff = lyric_view.get_buffer()
+                lyric_buff.set_text(lyric)
+                lyrics.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK)
+                lyrics.run()
+                lyrics.destroy()
+
     def show_about(self, widget, data=None):
         """
         About dialog for the application
+#!/usr/bin/env python
+#-*- encoding: utf-8 -*-
+
+import urllib2
+
+__doc__ = """Lyrbrary to work with the lyrdb webservices"""
+__author__ = "Vladimir Kolev <vladimir.r.kolev@gmail.com>"
+__version__ = 1.0
+__license__ = "GNU General Public License v.3"
+
+LOOKUP_URL = "http://webservices.lyrdb.com/lookup.php?q=%s&for=%s&agent=gSharkDown"
+GETLYR_URL = "http://webservices.lyrdb.com/getlyr.php?q=%s"
+
+def search(artist, track, method="match"):
+    art = artist.replace(" ", "+")
+    track = track.replace(" ", "+")
+    query = art + "|" + track
+    
+    if method == "trackname":
+        query = track
+    elif method == "artist":
+        query = art
+    elif method == "fullt":
+        query = art + "+" + track
+
+    req = urllib2.urlopen(LOOKUP_URL % (query, method))
+    result = req.read()
+    if "error" in result:
+        return "ERROR: Can't find lyrics for this track"
+    elif result == "":
+        return "ERROR: Can't find lyrics for this track"
+    else:
+        t = result.splitlines()
+        return t[0].split("\\")[0]
+
+def getlyrics(songid):
+    req = urllib2.urlopen(GETLYR_URL % songid)
+    lyric = req.read()
+    return lyric