diff --git a/lLyrics/AZLyricsParser.py b/lLyrics/AZLyricsParser.py
index fcb5830..b6d84d3 100755
--- a/lLyrics/AZLyricsParser.py
+++ b/lLyrics/AZLyricsParser.py
@@ -18,13 +18,13 @@
import Util
+
class Parser(object):
-
def __init__(self, artist, title):
self.artist = artist
self.title = title
self.lyrics = ""
-
+
def parse(self):
# remove unwanted characters from artist and title strings
clean_artist = self.artist
@@ -33,11 +33,11 @@ def parse(self):
clean_artist = clean_artist.replace(" and ", "")
clean_artist = clean_artist.replace(" ", "")
clean_artist = Util.remove_punctuation(clean_artist)
-
+
clean_title = self.title
clean_title = clean_title.replace(" ", "")
clean_title = Util.remove_punctuation(clean_title)
-
+
# create lyrics Url
url = "http://www.azlyrics.com/lyrics/" + clean_artist + "/" + clean_title + ".html"
print("azlyrics Url " + url)
@@ -46,30 +46,29 @@ def parse(self):
except:
print("could not connect to azlyrics.com")
return ""
-
+
resp = Util.bytes_to_string(resp)
self.lyrics = self.get_lyrics(resp)
self.lyrics = string.capwords(self.lyrics, "\n").strip()
-
+
return self.lyrics
-
+
def get_lyrics(self, resp):
# cut HTML source to relevant part
start = resp.find("that. -->")
if start == -1:
print("lyrics start not found")
return ""
- resp = resp[(start+9):]
+ resp = resp[(start + 9):]
end = resp.find("")
if end == -1:
print("lyrics end not found ")
return ""
- resp = resp[:(end-1)]
-
+ resp = resp[:(end - 1)]
+
# replace unwanted parts
resp = resp.replace("
", "")
resp = resp.replace("", "")
resp = resp.replace("", "")
-
+
return resp
-
diff --git a/lLyrics/ChartlyricsParser.py b/lLyrics/ChartlyricsParser.py
index fd3bc02..1a34896 100755
--- a/lLyrics/ChartlyricsParser.py
+++ b/lLyrics/ChartlyricsParser.py
@@ -24,8 +24,8 @@
import Util
+
class Parser(HTMLParser):
-
def __init__(self, artist, title):
HTMLParser.__init__(self)
self.artist = artist
@@ -33,15 +33,15 @@ def __init__(self, artist, title):
self.tag = None
self.correct = True
self.lyrics = ""
-
+
# define handler for parsing
def handle_starttag(self, tag, attrs):
self.tag = tag
-
+
# definde handler for parsing
def handle_endtag(self, tag):
self.tag = None
-
+
# definde handler for parsing
def handle_data(self, data):
if self.tag == "lyricsong":
@@ -54,20 +54,20 @@ def handle_data(self, data):
return
if self.correct and self.tag == "lyric":
self.lyrics = data
-
+
def parse(self):
# API searchLyric request
- url = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=" + urllib.parse.quote(self.artist) + "&song=" + urllib.parse.quote(self.title)
+ url = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=" + urllib.parse.quote(
+ self.artist) + "&song=" + urllib.parse.quote(self.title)
print("call chartlyrics API: " + url)
try:
resp = urllib.request.urlopen(url, None, 3).read()
except:
print("could not connect to chartlyric.com API")
-
+
resp = Util.bytes_to_string(resp)
self.feed(resp)
-
+
self.lyrics = string.capwords(self.lyrics, "\n").strip()
-
+
return self.lyrics
-
\ No newline at end of file
diff --git a/lLyrics/Config.py b/lLyrics/Config.py
index ad5cd6b..238bfdb 100755
--- a/lLyrics/Config.py
+++ b/lLyrics/Config.py
@@ -26,15 +26,14 @@
import lLyrics
import lLyrics_rb3compat as Compat
-
DCONF_DIR = 'org.gnome.rhythmbox.plugins.llyrics'
+
class Config(object):
-
def __init__(self):
self.settings = Gio.Settings(DCONF_DIR)
-
- def check_active_sources(self):
+
+ def check_active_sources(self):
# remove invalid entries
changed = False
entries = self.settings["active-sources"]
@@ -43,11 +42,11 @@ def check_active_sources(self):
entries.remove(source)
changed = True
print("remove invalid entry in active-sources: " + source)
-
+
# update key, if changed
if changed:
self.settings["active-sources"] = entries
-
+
def check_scanning_order(self):
# remove invalid entries
changed = False
@@ -57,27 +56,27 @@ def check_scanning_order(self):
entries.remove(source)
changed = True
print("remove invalid entry in scanning-order: " + source)
-
+
# fill up missing keys
for source in lLyrics.LYRICS_SOURCES:
if source not in entries:
entries.append(source)
changed = True
print("append missing entry in scanning-order: " + source)
-
+
# update key, if changed
if changed:
self.settings["scanning-order"] = entries
-
+
def check_lyrics_folder(self):
folder = self.settings["lyrics-folder"]
changed = False
-
+
# expand user directory
if "~" in folder:
folder = os.path.expanduser(folder)
changed = True
-
+
# path not set or invalid
if not folder or not os.path.exists(folder):
folder = os.path.join(RB.user_cache_dir(), "lyrics")
@@ -86,13 +85,13 @@ def check_lyrics_folder(self):
os.mkdir(folder)
changed = True
print("invalid path in lyrics-folder, set to default")
-
+
if changed:
self.settings["lyrics-folder"] = folder
-
+
def get_settings(self):
return self.settings
-
+
def get_lyrics_sources(self):
self.check_active_sources()
self.check_scanning_order()
@@ -100,30 +99,29 @@ def get_lyrics_sources(self):
for source in self.settings["scanning-order"]:
if source in self.settings["active-sources"]:
lyrics_sources.append(source)
-
+
return lyrics_sources
-
+
def get_show_first(self):
return self.settings["show-first"]
-
+
def get_cache_lyrics(self):
return self.settings["cache-lyrics"]
-
+
def get_lyrics_folder(self):
self.check_lyrics_folder()
return self.settings["lyrics-folder"]
-
+
def get_ignore_brackets(self):
return self.settings["ignore-brackets"]
-
+
def get_left_sidebar(self):
return self.settings["left-sidebar"]
-
+
def get_hide_label(self):
return self.settings["hide-label"]
-
-
-
+
+
class ConfigDialog(GObject.Object, PeasGtk.Configurable):
__gtype_name__ = 'lLyricsConfigDialog'
object = GObject.property(type=GObject.Object)
@@ -138,93 +136,94 @@ def do_create_configure_widget(self):
# page 1 for general settings
page1 = Gtk.VBox()
-
+
# switch for show-first
hbox = Gtk.HBox()
switch = Gtk.Switch()
switch.set_active(self.settings["show-first"])
switch.connect("notify::active", self.switch_toggled, "show-first")
-
+
label = Gtk.Label("" + _("Show sidebar on first playback") + "")
label.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(switch, False, False, 5)
page1.pack_start(hbox, False, False, 10)
-
+
# switch for cache-lyrics
hbox = Gtk.HBox()
switch = Gtk.Switch()
switch.set_active(self.settings["cache-lyrics"])
switch.connect("notify::active", self.switch_toggled, "cache-lyrics")
-
+
label = Gtk.Label("" + _("Save lyrics ") + "")
label.set_use_markup(True)
-
- descr = Gtk.Label("" + _("Whether to automatically save retrieved lyrics in the folder specified below") + "")
+
+ descr = Gtk.Label(
+ "" + _("Whether to automatically save retrieved lyrics in the folder specified below") + "")
descr.set_alignment(0, 0)
descr.set_margin_left(15)
descr.set_line_wrap(True)
descr.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(switch, False, False, 5)
vbox = Gtk.VBox()
vbox.pack_start(hbox, False, False, 0)
vbox.pack_start(descr, False, False, 0)
page1.pack_start(vbox, False, False, 10)
-
+
# file chooser for lyrics-folder
hbox = Gtk.HBox()
file_chooser = Gtk.FileChooserButton()
file_chooser.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
file_chooser.set_current_folder(self.settings["lyrics-folder"])
file_chooser.connect("current-folder-changed", self.folder_set)
-
+
default_button = Gtk.Button(_("default"))
default_button.connect("clicked", self.set_folder_default, file_chooser)
-
+
label = Gtk.Label("" + _("Folder for lyrics") + "")
label.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(file_chooser, True, True, 5)
hbox.pack_start(default_button, False, False, 5)
page1.pack_start(hbox, False, False, 10)
-
+
# switch for ignore-brackets
hbox = Gtk.HBox()
switch = Gtk.Switch()
switch.set_active(self.settings["ignore-brackets"])
switch.connect("notify::active", self.switch_toggled, "ignore-brackets")
-
+
label = Gtk.Label("" + _("Always ignore parentheses in song title") + "")
label.set_use_markup(True)
-
+
descr = Gtk.Label("" + _("When turned off, only parentheses containing specific strings "
- "(e.g. 'remix', 'live', 'edit', etc) are filtered") + "")
+ "(e.g. 'remix', 'live', 'edit', etc) are filtered") + "")
descr.set_alignment(0, 0)
descr.set_margin_left(15)
descr.set_line_wrap(True)
descr.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(switch, False, False, 5)
vbox = Gtk.VBox()
vbox.pack_start(hbox, False, False, 0)
vbox.pack_start(descr, False, False, 0)
-
+
page1.pack_start(vbox, False, False, 10)
-
+
# page 2 for sources settings
page2 = Gtk.VBox()
-
+
# check buttons for lyric sources
label = Gtk.Label("" + _("Sources:") + "")
label.set_alignment(0, 0)
label.set_padding(5, 0)
label.set_use_markup(True)
-
+
vbox = Gtk.VBox()
vbox.set_margin_left(30)
vbox.set_margin_top(5)
@@ -235,102 +234,102 @@ def do_create_configure_widget(self):
check.set_active(source in self.settings["active-sources"])
check.connect("toggled", self.source_toggled, source)
hbox.pack_start(check, True, True, 3)
-
+
button_up = Gtk.Button('\u2191')
button_up.connect("clicked", self.reorder_sources, source, hbox, vbox, "up")
hbox.pack_start(button_up, False, False, 3)
if self.settings["scanning-order"].index(source) == 0:
button_up.set_sensitive(False)
-
+
button_down = Gtk.Button('\u2193')
button_down.connect("clicked", self.reorder_sources, source, hbox, vbox, "down")
hbox.pack_start(button_down, False, False, 3)
if self.settings["scanning-order"].index(source) == len(self.settings["scanning-order"]) - 1:
button_down.set_sensitive(False)
-
+
vbox.pack_start(hbox, False, False, 0)
-
- warn = Gtk.Label("" +
- _("Warning: 'External' calls the Rhythmbox built-in lyrics plugin. "
- "It can not be guaranteed that the provided engines work properly. "
- "If you experience any problems, deactivate this option.")
- + "")
+
+ warn = Gtk.Label("" +
+ _("Warning: 'External' calls the Rhythmbox built-in lyrics plugin. "
+ "It can not be guaranteed that the provided engines work properly. "
+ "If you experience any problems, deactivate this option.")
+ + "")
warn.set_alignment(0, 0)
warn.set_margin_left(15)
warn.set_line_wrap(True)
warn.set_use_markup(True)
-
+
vbox2 = Gtk.VBox()
vbox2.pack_start(label, False, False, 0)
vbox2.pack_start(vbox, False, False, 0)
vbox2.pack_start(warn, False, False, 0)
-
+
page2.pack_start(vbox2, False, False, 10)
-
+
# page 3 for appearance settings
page3 = Gtk.VBox()
-
+
# switch for hide-label
hbox = Gtk.HBox()
switch = Gtk.Switch()
switch.set_active(self.settings["hide-label"])
switch.connect("notify::active", self.switch_toggled, "hide-label")
-
+
label = Gtk.Label("" + _("Hide sidebar label") + "")
label.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(switch, False, False, 5)
-
+
page3.pack_start(hbox, False, False, 10)
-
+
# switch for left-sidebar
hbox = Gtk.HBox()
switch = Gtk.Switch()
switch.set_active(self.settings["left-sidebar"])
switch.connect("notify::active", self.switch_toggled, "left-sidebar")
-
+
label = Gtk.Label("" + _("Show lyrics in left sidebar instead of right one") + "")
label.set_use_markup(True)
-
+
descr = Gtk.Label("" + _("You have to disable and re-enable this plugin or restart Rhythmbox "
"to apply changes here") + "")
descr.set_alignment(0, 0)
descr.set_margin_left(15)
descr.set_line_wrap(True)
descr.set_use_markup(True)
-
+
hbox.pack_start(label, False, False, 5)
hbox.pack_start(switch, False, False, 5)
vbox = Gtk.VBox()
vbox.pack_start(hbox, False, False, 0)
vbox.pack_start(descr, False, False, 0)
-
+
page3.pack_start(vbox, False, False, 10)
-
+
# create a notebook as top level container
nb = Gtk.Notebook()
nb.append_page(page1, Gtk.Label(_("General")))
nb.append_page(page2, Gtk.Label(_("Sources")))
nb.append_page(page3, Gtk.Label(_("Appearance")))
-
+
nb.show_all()
nb.set_size_request(300, -1)
-
+
return nb
-
+
def switch_toggled(self, switch, active, key):
self.settings[key] = switch.get_active()
-
+
def source_toggled(self, checkbutton, source):
entries = self.settings["active-sources"]
if checkbutton.get_active():
entries.append(source)
else:
entries.remove(source)
-
+
self.settings["active-sources"] = entries
-
+
def reorder_sources(self, button, source, hbox, vbox, direction):
rows = vbox.get_children()
if direction == "up":
@@ -349,20 +348,19 @@ def reorder_sources(self, button, source, hbox, vbox, direction):
if new_index == 1:
rows[1].get_children()[1].set_sensitive(False)
rows[0].get_children()[1].set_sensitive(True)
-
+
vbox.reorder_child(hbox, new_index)
-
+
entries = self.settings["scanning-order"]
entries.remove(source)
entries.insert(new_index, source)
self.settings["scanning-order"] = entries
-
+
def folder_set(self, file_chooser):
new_folder = file_chooser.get_current_folder()
if self.settings["lyrics-folder"] != new_folder:
print("folder changed")
self.settings["lyrics-folder"] = new_folder
-
+
def set_folder_default(self, button, file_chooser):
file_chooser.set_current_folder(os.path.join(RB.user_cache_dir(), "lyrics"))
-
\ No newline at end of file
diff --git a/lLyrics/DarklyricsParser.py b/lLyrics/DarklyricsParser.py
index 227b336..6e32bca 100755
--- a/lLyrics/DarklyricsParser.py
+++ b/lLyrics/DarklyricsParser.py
@@ -19,19 +19,19 @@
import Util
+
class Parser(object):
-
def __init__(self, artist, title):
self.artist = artist
self.title = title
self.lyrics = ""
-
+
def parse(self):
# remove unwanted characters from artist and title strings
clean_artist = self.artist
clean_artist = Util.remove_punctuation(clean_artist)
clean_artist = clean_artist.replace(" ", "")
-
+
# create artist Url
url = "http://www.darklyrics.com/" + clean_artist[:1] + "/" + clean_artist + ".html"
print("darklyrics artist Url " + url)
@@ -40,9 +40,9 @@ def parse(self):
except:
print("could not connect to darklyrics.com")
return ""
-
+
resp = Util.bytes_to_string(resp)
-
+
# find title with lyrics url
match = re.search("" + self.title + "
", resp, re.I)
if match is None:
@@ -55,25 +55,26 @@ def parse(self):
except:
print("could not connect to darklyrics.com")
return ""
-
+
resp = Util.bytes_to_string(resp)
-
- self.track_no = url.split("#")[1]
-
+
+ self.track_no = url.split("#")[1]
+
self.lyrics = self.get_lyrics(resp)
self.lyrics = string.capwords(self.lyrics, "\n").strip()
-
+
return self.lyrics
-
+
def get_lyrics(self, resp):
# search for the relevant lyrics
- match = re.search("
") if start == -1: print("lyrics start not found") return "" - resp = resp[(start+6):] + resp = resp[(start + 6):] end = resp.find("
") if end == -1: print("lyrics end not found ") return "" resp = resp[:end] - + # replace unwanted parts resp = resp.replace("", "\n\n") resp = html.unescape(resp) - + return resp - + def verify(self, resp): # verify song artist/title title = resp @@ -80,41 +80,41 @@ def verify(self, resp): if start == -1: print("no title found") return False - title = title[(start+4):] - + title = title[(start + 4):] + start = title.find(">") if start == -1: print("no title start found") return False - title = title[(start+1):] - + title = title[(start + 1):] + end = title.find("") if end == -1: print("no title end found") return False title = html.unescape(title[:end]).lower() - + artist = resp start = artist.find("
") if start == -1: print("lyrics start not found") return "" - resp = resp[(start+28):] + resp = resp[(start + 28):] end = resp.find("") if end == -1: print("lyrics end not found") return "" resp = resp[:end] - + return resp - + def verify(self, resp): for entry in resp: title = entry["title"].lower() @@ -94,6 +94,5 @@ def verify(self, resp): if self.artist == artist and self.title == title: return entry print("wrong artist/title! " + artist + " - " + title) - + return None - \ No newline at end of file diff --git a/lLyrics/LyricsmaniaParser.py b/lLyrics/LyricsmaniaParser.py index 05eaa1b..1895f26 100755 --- a/lLyrics/LyricsmaniaParser.py +++ b/lLyrics/LyricsmaniaParser.py @@ -18,23 +18,23 @@ import Util + class Parser(object): - def __init__(self, artist, title): self.artist = artist self.title = title self.lyrics = "" - + def parse(self): # remove unwanted characters from artist and title strings clean_artist = self.artist.replace("+", "and") clean_artist = Util.remove_punctuation(clean_artist) clean_artist = clean_artist.replace(" ", "_") - + clean_title = self.title clean_title = Util.remove_punctuation(clean_title) clean_title = clean_title.replace(" ", "_") - + # create lyrics Url url = "http://www.lyricsmania.com/" + clean_title + "_lyrics_" + clean_artist + ".html" print("lyricsmania Url " + url) @@ -43,26 +43,26 @@ def parse(self): except: print("could not connect to lyricsmania.com") return "" - + resp = Util.bytes_to_string(resp) self.lyrics = self.get_lyrics(resp) self.lyrics = string.capwords(self.lyrics, "\n").strip() - + return self.lyrics - + def get_lyrics(self, resp): # cut HTML source to relevant part start = resp.find("") if start == -1: print("lyrics start not found") return "" - resp = resp[(start+9):] + resp = resp[(start + 9):] end = resp.find("") if end == -1: print("lyrics end not found ") return "" resp = resp[:end] - + # replace unwanted parts resp = resp.replace("