Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parser for lyrics.alsong.co.kr #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions lLyrics/ALSongLyricsParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Parser for lyrics.alsong.co.kr
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from xml.dom import minidom
import requests
import re
import string
import unicodedata

import Util

TEMPLATE = """\
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="ALSongWebServer/Service1Soap"
xmlns:ns1="ALSongWebServer"
xmlns:ns3="ALSongWebServer/Service1Soap12">
<SOAP-ENV:Body><ns1:GetResembleLyric2>
<ns1:stQuery>
<ns1:strTitle>{title}</ns1:strTitle>
<ns1:strArtistName>{artist}</ns1:strArtistName>
<ns1:nCurPage>{page}</ns1:nCurPage>
</ns1:stQuery>
</ns1:GetResembleLyric2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"""

class Parser(object):
def __init__(self, artist, title):
self.artist = artist
self.title = title
self.lyrics = ""

def parse(self):
data = TEMPLATE.format(
title = unicodedata.normalize("NFC", self.title),
artist = unicodedata.normalize("NFC", self.artist),
page = 0,
).encode()

# create lyrics Url
resp = requests.post(
'http://lyrics.alsong.co.kr/alsongwebservice/service1.asmx',
data,
headers={'Content-Type': 'application/soap+xml'},
)

if resp.status_code != 200:
print("Request is NOK")
return ""

return self.get_lyrics(resp)

def get_lyrics(self, resp):
dom = minidom.parseString(resp.content)
lyric_list = dom.getElementsByTagName('strLyric')
if not lyric_list:
print("can't find strLyric")
return ""

try:
return lyric_list[0].firstChild.nodeValue.replace("<br>", "\n").strip()
except:
print("Parsing error")
return ""
7 changes: 4 additions & 3 deletions lLyrics/lLyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import DarklyricsParser
import GeniusParser
import VagalumeParser
import ALSongLyricsParser
import Util

from lLyrics_rb3compat import ActionGroup
Expand Down Expand Up @@ -94,7 +95,7 @@
LYRICS_ARTIST_REPLACE = [("/", "-"), (" & ", " and ")]

LYRICS_SOURCES = ["Lyricwiki.org", "Letras.terra.com.br", "Metrolyrics.com", "AZLyrics.com", "Lyricsmania.com",
"Vagalume.com.br", "Genius.com", "Darklyrics.com", "Chartlyrics.com"]
"Vagalume.com.br", "Genius.com", "Darklyrics.com", "Chartlyrics.com", "lyrics.alsong.co.kr"]


class lLyrics(GObject.Object, Peas.Activatable):
Expand All @@ -117,7 +118,7 @@ def do_activate(self):
"Metrolyrics.com": MetrolyricsParser, "AZLyrics.com": AZLyricsParser,
"Lyricsmania.com": LyricsmaniaParser, "Chartlyrics.com": ChartlyricsParser,
"Darklyrics.com": DarklyricsParser, "Genius.com": GeniusParser,
"Vagalume.com.br": VagalumeParser})
"Vagalume.com.br": VagalumeParser, "lyrics.alsong.co.kr": ALSongLyricsParser})
self.add_builtin_lyrics_sources()

# Get the user preferences
Expand Down Expand Up @@ -357,7 +358,7 @@ def get_button_menu(self):

last_item = item_unselect

for entry in LYRICS_SOURCES[:-1]:
for entry in LYRICS_SOURCES:
last_item = self.add_radio_menu_item(self.radio_sources, entry, self.scan_selected_source_callback,
last_item)

Expand Down
8 changes: 4 additions & 4 deletions org.gnome.rhythmbox.plugins.llyrics.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<schema id="org.gnome.rhythmbox.plugins.llyrics" path="/org/gnome/rhythmbox/plugins/llyrics/">

<key name="active-sources" type="as">
<default>['Lyricwiki.org', 'Letras.terra.com.br', 'Vagalume.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Darklyrics.com', 'Chartlyrics.com', 'Genius.com']</default>
<default>['Lyricwiki.org', 'Letras.terra.com.br', 'Vagalume.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Darklyrics.com', 'Chartlyrics.com', 'Genius.com', 'lyrics.alsong.co.kr']</default>
<summary>List of lyrics sources to be scanned</summary>
<description>Possible values are: 'Lyricwiki.org', 'Letras.terra.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Vagalume.com.br', 'Darklyrics.com', 'Chartlyrics.com', 'Genius.com'</description>
<description>Possible values are: 'Lyricwiki.org', 'Letras.terra.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Vagalume.com.br', 'Darklyrics.com', 'Chartlyrics.com', 'Genius.com', 'lyrics.alsong.co.kr'</description>
</key>

<key name="scanning-order" type="as">
<default>['Lyricwiki.org', 'Letras.terra.com.br', 'Vagalume.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Genius.com', 'Darklyrics.com', 'Chartlyrics.com']</default>
<default>['Lyricwiki.org', 'Letras.terra.com.br', 'Vagalume.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Genius.com', 'Darklyrics.com', 'Chartlyrics.com', 'lyrics.alsong.co.kr']</default>
<summary>Sources are scanned in this order</summary>
<description>Possible values are: 'Lyricwiki.org', 'Letras.terra.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Vagalume.com.br', 'Genius.com', 'Darklyrics.com', 'Chartlyrics.com'</description>
<description>Possible values are: 'Lyricwiki.org', 'Letras.terra.com.br', 'Metrolyrics.com', 'AZLyrics.com', 'Lyricsmania.com', 'Vagalume.com.br', 'Genius.com', 'Darklyrics.com', 'Chartlyrics.com', 'lyrics.alsong.co.kr'</description>
</key>

<key name="show-first" type="b">
Expand Down