IPB

Welcome Guest ( Log In | Register )

11 Pages V  « < 9 10 11  
Reply to this topicStart new topic
Lyricsgrabber2 Feedback & Discussion
onanboy
post Jun 22 2015, 12:46
Post #251





Group: Members
Posts: 18
Joined: 4-January 06
Member No.: 26850



QUOTE (phot0nic @ Jun 21 2015, 22:26) *
QUOTE (onanboy @ Jun 18 2015, 12:50) *
It would load but not work it I removed the line about importing unescape.


Sorry about that. I thought the unescape function came with the component. Here's the code for that function:
http://codeviewer.org/view/code:5289

Save the code as unescape.py, and store it in your "C:\Users\Gonzo\AppData\Roaming\foobar2000\user-components\foo_lyricsgrabber2\pygrabber\system\" directory.

For future reference (in case the codeviewer link breaks), here's the unescape function:
CODE
import re, htmlentitydefs

##
# Removes HTML or XML character references and entities from a text string.
#
# @param text The HTML (or XML) source text.
# @return The plain text, as a Unicode string, if necessary.

def unescape(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)


Thanks very much.

I will try it very soon. Leaving on a business trip this morning but I am eager to try it.
Go to the top of the page
+Quote Post
onanboy
post Jun 30 2015, 12:41
Post #252





Group: Members
Posts: 18
Joined: 4-January 06
Member No.: 26850



QUOTE (phot0nic @ Jun 21 2015, 22:26) *
QUOTE (onanboy @ Jun 18 2015, 12:50) *
It would load but not work it I removed the line about importing unescape.


Sorry about that. I thought the unescape function came with the component. Here's the code for that function:
http://codeviewer.org/view/code:5289

Save the code as unescape.py, and store it in your "C:\Users\Gonzo\AppData\Roaming\foobar2000\user-components\foo_lyricsgrabber2\pygrabber\system\" directory.

For future reference (in case the codeviewer link breaks), here's the unescape function:
CODE
import re, htmlentitydefs

##
# Removes HTML or XML character references and entities from a text string.
#
# @param text The HTML (or XML) source text.
# @return The plain text, as a Unicode string, if necessary.

def unescape(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)




That worked! Of course when I tried to copy and paste the code I got an indent error but when I just downloaded the text it worked beautifully! Gracias, phot0nic
Go to the top of the page
+Quote Post

11 Pages V  « < 9 10 11
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 30th July 2015 - 06:00