Skip to main content

Topic: Lyricsgrabber2 Feedback & Discussion (Read 122226 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • onanboy
  • [*]
Lyricsgrabber2 Feedback & Discussion
Reply #250
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: [Select]
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.

  • onanboy
  • [*]
Lyricsgrabber2 Feedback & Discussion
Reply #251
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: [Select]
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

  • djvasco
  • [*]
Lyricsgrabber2 Feedback & Discussion
Reply #252
---

While typing up this response, I just noticed that copying and pasting from a codebox on this forum doesn't seem to retain the indentations, which will break the script.  I've uploaded the script code here:
http://codeviewer.org/view/code:5143
Just use the dropdown in the upper-right to download the code with indentations intact.  Again, rename it to *.py and place it in the appropriate directory.



Could you please re-upload the code? The link is broken and I couldn't make it work with the indentation problem.

  • phot0nic
  • [*]
Lyricsgrabber2 Feedback & Discussion
Reply #253
LyricWiki made a small change to their API and the script I posted before stopped working.  I fixed my script, and included the unescape function so that you don't need two files (klonuo's suggestion didn't work for me).  I have attached the updated script to this post:

http://www.hydrogenaud.io/forums/index.php?showtopic=110032