diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/common/__init__.py b/mythtv/programs/scripts/metadata/Music/lyrics/common/__init__.py
index b1b9bddeaf..391fdc6bbe 100644
|
a
|
b
|
|
| 1 | 1 | __version__ = "1.0.0" |
| 2 | 2 | |
| 3 | | import utilities, audiofile |
| | 3 | from . import utilities, audiofile |
| | 4 | |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/common/utilities.py b/mythtv/programs/scripts/metadata/Music/lyrics/common/utilities.py
index 4ad657d21b..dfca3b2cd6 100644
|
a
|
b
|
import sys
|
| 2 | 2 | import os |
| 3 | 3 | import unicodedata |
| 4 | 4 | |
| | 5 | IS_PY2 = sys.version_info[0] == 2 |
| | 6 | |
| 5 | 7 | def log(debug, txt): |
| 6 | 8 | if debug: |
| 7 | | print txt |
| | 9 | print(txt) |
| 8 | 10 | |
| 9 | 11 | class Lyrics: |
| 10 | 12 | def __init__(self): |
| … |
… |
class Lyrics:
|
| 19 | 21 | |
| 20 | 22 | def deAccent(str): |
| 21 | 23 | return unicodedata.normalize('NFKD', unicode(str, 'utf-8')) |
| | 24 | |
| | 25 | def convert_etree(etostr): |
| | 26 | """lxml.etree.tostring is a bytes object in python3, and a str in python2. |
| | 27 | """ |
| | 28 | if IS_PY2: |
| | 29 | return(etostr) |
| | 30 | else: |
| | 31 | return(etostr.decode()) |
| | 32 | |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/darklyrics.py b/mythtv/programs/scripts/metadata/Music/lyrics/darklyrics.py
index 8c3363d459..9b0a9250a8 100644
|
a
|
b
|
scraper by smory
|
| 6 | 6 | """ |
| 7 | 7 | |
| 8 | 8 | import hashlib |
| 9 | | import urllib2 |
| | 9 | try: |
| | 10 | from urllib2 import quote, urlopen |
| | 11 | except ImportError: |
| | 12 | from urllib.request import urlopen |
| | 13 | from urllib.parse import quote |
| 10 | 14 | import re |
| 11 | 15 | import chardet |
| 12 | 16 | import sys |
| … |
… |
from common import utilities
|
| 16 | 20 | __author__ = "Paul Harrison and smory'" |
| 17 | 21 | __title__ = "DarkLyrics" |
| 18 | 22 | __description__ = "Search http://www.darklyrics.com/ - the largest metal lyrics archive on the Web" |
| 19 | | __priority__ = "180"; |
| | 23 | __priority__ = "180" |
| 20 | 24 | __version__ = "0.1" |
| 21 | | __syncronized__ = False; |
| | 25 | __syncronized__ = False |
| 22 | 26 | |
| 23 | 27 | debug = False |
| 24 | 28 | |
| … |
… |
class LyricsFetcher:
|
| 29 | 33 | self.searchUrl = "http://www.darklyrics.com/search?q=%term%" |
| 30 | 34 | |
| 31 | 35 | def search(self, artist, title): |
| 32 | | term = urllib2.quote((artist if artist else "") + " " + (title if title else "")); |
| | 36 | term = quote((artist if artist else "") + " " + (title if title else "")) |
| 33 | 37 | |
| 34 | 38 | try: |
| 35 | | request = urllib2.urlopen(self.searchUrl.replace("%term%", term)) |
| 36 | | searchResponse = request.read(); |
| | 39 | request = urlopen(self.searchUrl.replace("%term%", term)) |
| | 40 | searchResponse = request.read() |
| 37 | 41 | except: |
| 38 | 42 | return None |
| 39 | 43 | |
| 40 | | searchResult = re.findall("<h2><a\shref=\"(.*?#([0-9]+))\".*?>(.*?)</a></h2>", searchResponse); |
| | 44 | searchResult = re.findall(b"<h2><a\shref=\"(.*?#([0-9]+))\".*?>(.*?)</a></h2>", searchResponse) |
| 41 | 45 | |
| 42 | 46 | if len(searchResult) == 0: |
| 43 | | return None; |
| | 47 | return None |
| 44 | 48 | |
| 45 | | links = []; |
| | 49 | links = [] |
| 46 | 50 | |
| 47 | | i = 0; |
| | 51 | i = 0 |
| 48 | 52 | for result in searchResult: |
| 49 | | a = []; |
| 50 | | a.append(result[2] + ( " " + self.getAlbumName(self.base_url + result[0]) if i < 6 else "")); # title from server + album nane |
| 51 | | a.append(self.base_url + result[0]); # url with lyrics |
| 52 | | a.append(artist); |
| 53 | | a.append(title); |
| 54 | | a.append(result[1]); # id of the side part containing this song lyrics |
| 55 | | links.append(a); |
| 56 | | i += 1; |
| | 53 | a = [] |
| | 54 | a.append(result[2] + ( b" " + self.getAlbumName(self.base_url + result[0].decode('utf-8') )if i < 6 else b"")) # title from server + album nane |
| | 55 | a.append(self.base_url + result[0].decode('utf-8')) # url with lyrics |
| | 56 | a.append(artist) |
| | 57 | a.append(title) |
| | 58 | a.append(result[1]) # id of the side part containing this song lyrics |
| | 59 | links.append(a) |
| | 60 | i += 1 |
| 57 | 61 | |
| 58 | | return links; |
| | 62 | return links |
| 59 | 63 | |
| 60 | 64 | def findLyrics(self, url, index): |
| 61 | 65 | try: |
| 62 | | request = urllib2.urlopen(url); |
| 63 | | res = request.read(); |
| | 66 | request = urlopen(url) |
| | 67 | res = request.read() |
| 64 | 68 | except: |
| 65 | 69 | return None |
| 66 | 70 | |
| 67 | | pattern = "<a\sname=\"%index%\">(.*?)(?:<h3>|<div)"; # require multi line and dot all mode |
| 68 | | pattern = pattern.replace("%index%", index); |
| | 71 | pattern = b"<a\sname=\"%index%\">(.*?)(?:<h3>|<div)" # require multi line and dot all mode |
| | 72 | pattern = pattern.replace(b"%index%", index) |
| 69 | 73 | |
| 70 | | match = re.search(pattern, res, re.MULTILINE | re.DOTALL); |
| | 74 | match = re.search(pattern, res, re.MULTILINE | re.DOTALL) |
| 71 | 75 | if match: |
| 72 | | s = match.group(1); |
| 73 | | s = s.replace("<br />", ""); |
| 74 | | s = s.replace("<i>", ""); |
| 75 | | s = s.replace("</i>", ""); |
| 76 | | s = s.replace("</a>", ""); |
| 77 | | s = s.replace("</h3>", ""); |
| 78 | | return s; |
| | 76 | s = match.group(1) |
| | 77 | s = s.replace(b"<br />", b"") |
| | 78 | s = s.replace(b"<i>", b"") |
| | 79 | s = s.replace(b"</i>", b"") |
| | 80 | s = s.replace(b"</a>", b"") |
| | 81 | s = s.replace(b"</h3>", b"") |
| | 82 | return s |
| 79 | 83 | else: |
| 80 | | return None; |
| | 84 | return None |
| 81 | 85 | |
| 82 | 86 | def getAlbumName(self, url): |
| 83 | 87 | try: |
| 84 | | request = urllib2.urlopen(url); |
| 85 | | res = request.read(); |
| | 88 | request = urlopen(url) |
| | 89 | res = request.read() |
| 86 | 90 | except: |
| 87 | | return ""; |
| | 91 | return b"" |
| 88 | 92 | |
| 89 | | match = re.search("<h2>(?:album|single|ep|live):?\s?(.*?)</h2>", res, re.IGNORECASE); |
| | 93 | match = re.search(b"<h2>(?:album|single|ep|live):?\s?(.*?)</h2>", res, re.IGNORECASE) |
| 90 | 94 | |
| 91 | 95 | if match: |
| 92 | | return ("(" + match.group(1) + ")").replace("\"", ""); |
| | 96 | ret = (b"(" + match.group(1) + b")").replace(b"\"", b"") |
| 93 | 97 | else: |
| 94 | | return ""; |
| | 98 | ret = b"" |
| | 99 | return(ret) |
| | 100 | |
| | 101 | |
| 95 | 102 | |
| 96 | 103 | def get_lyrics(self, lyrics): |
| 97 | 104 | utilities.log(debug, "%s: searching lyrics for %s - %s - %s" % (__title__, lyrics.artist, lyrics.album, lyrics.title)) |
| 98 | | links = self.search(lyrics.artist, lyrics.title); |
| | 105 | links = self.search(lyrics.artist, lyrics.title) |
| 99 | 106 | |
| 100 | 107 | if(links == None or len(links) == 0): |
| 101 | | return False; |
| | 108 | return False |
| 102 | 109 | elif len(links) > 1: |
| 103 | 110 | lyrics.list = links |
| 104 | 111 | |
| … |
… |
class LyricsFetcher:
|
| 109 | 116 | enc = chardet.detect(lyr) |
| 110 | 117 | lyr = lyr.decode(enc['encoding'], 'ignore') |
| 111 | 118 | lyrics.lyrics = lyr |
| 112 | | return True; |
| | 119 | return True |
| 113 | 120 | |
| 114 | 121 | def get_lyrics_from_list(self, link): |
| 115 | | title, url, artist, song, index = link; |
| 116 | | return self.findLyrics(url, index); |
| | 122 | title, url, artist, song, index = link |
| | 123 | return self.findLyrics(url, index) |
| 117 | 124 | |
| 118 | 125 | def performSelfTest(): |
| 119 | 126 | found = False |
| … |
… |
def performSelfTest():
|
| 129 | 136 | |
| 130 | 137 | if found: |
| 131 | 138 | utilities.log(True, "Everything appears in order.") |
| | 139 | buildLyrics(lyrics) |
| 132 | 140 | sys.exit(0) |
| 133 | 141 | |
| 134 | 142 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 148 | 156 | line2 = re.sub(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\u10000-\u10FFFF]+', '', line) |
| 149 | 157 | etree.SubElement(xml, "lyric").text = line2 |
| 150 | 158 | |
| 151 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 152 | | xml_declaration=True)) |
| | 159 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 160 | pretty_print=True, xml_declaration=True))) |
| 153 | 161 | sys.exit(0) |
| 154 | 162 | |
| 155 | 163 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 164 | 172 | etree.SubElement(version, "priority").text = __priority__ |
| 165 | 173 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 166 | 174 | |
| 167 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 168 | | xml_declaration=True)) |
| | 175 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 176 | pretty_print=True, xml_declaration=True))) |
| 169 | 177 | sys.exit(0) |
| 170 | 178 | |
| 171 | 179 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/embedlrc.py b/mythtv/programs/scripts/metadata/Music/lyrics/embedlrc.py
index f3d36484f6..3f5815c243 100644
|
a
|
b
|
class LyricsFetcher:
|
| 124 | 124 | def get_lyrics(self, lyrics): |
| 125 | 125 | utilities.log(debug, "%s: searching lyrics for %s - %s - %s" % (__title__, lyrics.artist, lyrics.album, lyrics.title)) |
| 126 | 126 | |
| 127 | | filename = lyrics.filename.decode("utf-8") |
| | 127 | if utilities.IS_PY2: |
| | 128 | filename = lyrics.filename.decode("utf-8") |
| | 129 | else: |
| | 130 | filename = lyrics.filename |
| | 131 | |
| 128 | 132 | ext = os.path.splitext(filename)[1].lower() |
| 129 | 133 | lry = None |
| 130 | 134 | |
| … |
… |
def performSelfTest():
|
| 173 | 177 | |
| 174 | 178 | if found: |
| 175 | 179 | utilities.log(True, "Everything appears in order.") |
| | 180 | buildLyrics(lyrics) |
| 176 | 181 | sys.exit(0) |
| 177 | 182 | |
| 178 | 183 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 191 | 196 | for line in lines: |
| 192 | 197 | etree.SubElement(xml, "lyric").text = line |
| 193 | 198 | |
| 194 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 195 | | xml_declaration=True)) |
| | 199 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 200 | pretty_print=True, xml_declaration=True))) |
| 196 | 201 | sys.exit(0) |
| 197 | 202 | |
| 198 | 203 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 207 | 212 | etree.SubElement(version, "priority").text = __priority__ |
| 208 | 213 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 209 | 214 | |
| 210 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 211 | | xml_declaration=True)) |
| | 215 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 216 | pretty_print=True, xml_declaration=True))) |
| 212 | 217 | sys.exit(0) |
| 213 | 218 | |
| 214 | 219 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/filelyrics.py b/mythtv/programs/scripts/metadata/Music/lyrics/filelyrics.py
index bf34f2e29d..7aadb9dd52 100644
|
a
|
b
|
class LyricsFetcher:
|
| 26 | 26 | def get_lyrics(self, lyrics): |
| 27 | 27 | utilities.log(debug, "%s: searching lyrics for %s - %s - %s" % (__title__, lyrics.artist, lyrics.album, lyrics.title)) |
| 28 | 28 | |
| 29 | | filename = lyrics.filename.decode("utf-8") |
| | 29 | if utilities.IS_PY2: |
| | 30 | filename = lyrics.filename.decode("utf-8") |
| | 31 | else: |
| | 32 | filename = lyrics.filename |
| 30 | 33 | filename = os.path.splitext(filename)[0] |
| 31 | 34 | |
| 32 | 35 | # look for a file ending in .lrc with the same filename as the track minus the extension |
| … |
… |
def buildLyrics(lyrics):
|
| 83 | 86 | for line in lines: |
| 84 | 87 | etree.SubElement(xml, "lyric").text = line |
| 85 | 88 | |
| 86 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 87 | | xml_declaration=True)) |
| | 89 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 90 | pretty_print=True, xml_declaration=True))) |
| 88 | 91 | |
| 89 | 92 | def buildVersion(): |
| 90 | 93 | from lxml import etree |
| … |
… |
def buildVersion():
|
| 98 | 101 | etree.SubElement(version, "priority").text = __priority__ |
| 99 | 102 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 100 | 103 | |
| 101 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 102 | | xml_declaration=True)) |
| | 104 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 105 | pretty_print=True, xml_declaration=True))) |
| 103 | 106 | sys.exit(0) |
| 104 | 107 | |
| 105 | 108 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/genius.py b/mythtv/programs/scripts/metadata/Music/lyrics/genius.py
index a07d1ff489..3b163b781e 100644
|
a
|
b
|
Scraper for http://www.genius.com
|
| 5 | 5 | taxigps |
| 6 | 6 | """ |
| 7 | 7 | import sys |
| 8 | | import urllib |
| 9 | | import urllib2 |
| | 8 | try: |
| | 9 | from urllib2 import quote, urlopen, Request |
| | 10 | except ImportError: |
| | 11 | from urllib.request import urlopen, Request |
| | 12 | from urllib.parse import quote |
| | 13 | try: |
| | 14 | import HTMLParser as html_parser |
| | 15 | except ImportError: |
| | 16 | from html import parser as html_parser |
| 10 | 17 | import socket |
| 11 | 18 | import re |
| 12 | | import chardet |
| 13 | | import HTMLParser |
| 14 | 19 | from hashlib import md5 |
| 15 | | import chardet |
| 16 | 20 | import difflib |
| 17 | 21 | from optparse import OptionParser |
| 18 | 22 | from common import utilities |
| … |
… |
class LyricsFetcher:
|
| 42 | 46 | utilities.log(debug, "%s: searching lyrics for %s - %s - %s" % (__title__, lyrics.artist, lyrics.album, lyrics.title)) |
| 43 | 47 | |
| 44 | 48 | try: |
| 45 | | request = urllib2.Request(self.url % (urllib2.quote(lyrics.artist), '%20', urllib2.quote(lyrics.title))) |
| | 49 | request = Request(self.url % (quote(lyrics.artist), '%20', quote(lyrics.title))) |
| 46 | 50 | request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0') |
| 47 | | req = urllib2.urlopen(request) |
| 48 | | response = req.read() |
| | 51 | req = urlopen(request) |
| | 52 | response = req.read().decode('utf-8') |
| 49 | 53 | except: |
| 50 | 54 | return False |
| 51 | 55 | |
| … |
… |
class LyricsFetcher:
|
| 60 | 64 | utilities.log(debug, "%s: search url: %s" % (__title__, self.page)) |
| 61 | 65 | |
| 62 | 66 | try: |
| 63 | | request = urllib2.Request(self.page) |
| | 67 | request = Request(self.page) |
| 64 | 68 | request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0') |
| 65 | | req = urllib2.urlopen(request) |
| 66 | | response = req.read() |
| | 69 | req = urlopen(request) |
| | 70 | response = req.read().decode('utf-8') |
| 67 | 71 | except: |
| 68 | 72 | return False |
| 69 | 73 | |
| 70 | 74 | req.close() |
| 71 | | matchcode = re.search('<div class="lyrics">(.*?)</div>', response, flags=re.DOTALL) |
| | 75 | matchcode = re.search(u'<div class="lyrics">(.*?)</div>', response, flags=re.DOTALL) |
| 72 | 76 | |
| 73 | 77 | try: |
| 74 | 78 | lyricscode = (matchcode.group(1)) |
| 75 | | htmlparser = HTMLParser.HTMLParser() |
| 76 | | lyricstext = htmlparser.unescape(lyricscode).replace('<br />', '\n') |
| 77 | | templyr = re.sub('<[^<]+?>', '', lyricstext) |
| 78 | | lyr = re.sub('\[(.*?)\]', '', templyr) |
| 79 | | lyrics.lyrics = lyr.strip().replace('\n\n\n', '\n\n') |
| | 79 | htmlparser = html_parser.HTMLParser() |
| | 80 | lyricstext = htmlparser.unescape(lyricscode).replace(u'<br />', u'\n') |
| | 81 | templyr = re.sub(u'<[^<]+?>', '', lyricstext) |
| | 82 | lyr = re.sub(u'\[(.*?)\]', '', templyr) |
| | 83 | lyrics.lyrics = lyr.strip().replace(u'\n\n\n', u'\n\n') |
| 80 | 84 | return True |
| 81 | 85 | except: |
| 82 | 86 | return False |
| … |
… |
def performSelfTest():
|
| 96 | 100 | |
| 97 | 101 | if found: |
| 98 | 102 | utilities.log(True, "Everything appears in order.") |
| | 103 | buildLyrics(lyrics) |
| 99 | 104 | sys.exit(0) |
| 100 | 105 | |
| 101 | 106 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 114 | 119 | for line in lines: |
| 115 | 120 | etree.SubElement(xml, "lyric").text = line |
| 116 | 121 | |
| 117 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 118 | | xml_declaration=True)) |
| | 122 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 123 | pretty_print=True, xml_declaration=True))) |
| 119 | 124 | sys.exit(0) |
| 120 | 125 | |
| 121 | 126 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 130 | 135 | etree.SubElement(version, "priority").text = __priority__ |
| 131 | 136 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 132 | 137 | |
| 133 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 134 | | xml_declaration=True)) |
| | 138 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 139 | pretty_print=True, xml_declaration=True))) |
| 135 | 140 | sys.exit(0) |
| 136 | 141 | |
| 137 | 142 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/lyricscom.py b/mythtv/programs/scripts/metadata/Music/lyrics/lyricscom.py
index 14993c8fb4..9ce9e1a185 100644
|
a
|
b
|
ronie
|
| 7 | 7 | |
| 8 | 8 | import sys |
| 9 | 9 | import re |
| 10 | | import urllib |
| 11 | | import urllib2 |
| | 10 | try: |
| | 11 | from urllib import quote_plus |
| | 12 | from urllib2 import urlopen |
| | 13 | except ImportError: |
| | 14 | from urllib.parse import quote_plus |
| | 15 | from urllib.request import urlopen |
| | 16 | |
| 12 | 17 | import socket |
| 13 | 18 | import difflib |
| 14 | 19 | from optparse import OptionParser |
| … |
… |
class LyricsFetcher:
|
| 39 | 44 | return False |
| 40 | 45 | |
| 41 | 46 | try: |
| 42 | | request = urllib2.urlopen(self.url % urllib.quote_plus(lyrics.artist)) |
| | 47 | request = urlopen(self.url % quote_plus(lyrics.artist)) |
| 43 | 48 | response = request.read() |
| 44 | 49 | except: |
| 45 | 50 | return False |
| … |
… |
class LyricsFetcher:
|
| 54 | 59 | if url: |
| 55 | 60 | utilities.log(debug, "%s: Artist url is %s" % (__title__, url)) |
| 56 | 61 | try: |
| 57 | | req = urllib2.urlopen(url) |
| 58 | | resp = req.read() |
| | 62 | req = urlopen(url) |
| | 63 | resp = req.read().decode('utf-8') |
| 59 | 64 | except: |
| 60 | 65 | return False |
| 61 | 66 | req.close() |
| … |
… |
class LyricsFetcher:
|
| 70 | 75 | utilities.log(debug, "%s: Song url is %s" % (__title__, url)) |
| 71 | 76 | |
| 72 | 77 | try: |
| 73 | | req2 = urllib2.urlopen(url) |
| 74 | | resp2 = req2.read() |
| | 78 | req2 = urlopen(url) |
| | 79 | resp2 = req2.read().decode('utf-8') |
| 75 | 80 | except: |
| 76 | 81 | return False |
| 77 | 82 | req2.close() |
| 78 | 83 | |
| 79 | | matchcode = re.search('<pre.*?>(.*?)</pre>', resp2, flags=re.DOTALL) |
| | 84 | matchcode = re.search(u'<pre.*?>(.*?)</pre>', resp2, flags=re.DOTALL) |
| 80 | 85 | if matchcode: |
| 81 | 86 | lyricscode = (matchcode.group(1)) |
| 82 | | lyr = re.sub('<[^<]+?>', '', lyricscode) |
| | 87 | lyr = re.sub(u'<[^<]+?>', '', lyricscode) |
| 83 | 88 | lyrics.lyrics = lyr.replace('\\n','\n') |
| 84 | 89 | return True |
| 85 | 90 | |
| … |
… |
def performSelfTest():
|
| 105 | 110 | |
| 106 | 111 | if found: |
| 107 | 112 | utilities.log(True, "Everything appears in order.") |
| | 113 | buildLyrics(lyrics) |
| 108 | 114 | sys.exit(0) |
| 109 | 115 | |
| 110 | 116 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 123 | 129 | for line in lines: |
| 124 | 130 | etree.SubElement(xml, "lyric").text = line |
| 125 | 131 | |
| 126 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 127 | | xml_declaration=True)) |
| | 132 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 133 | pretty_print=True, xml_declaration=True))) |
| 128 | 134 | sys.exit(0) |
| 129 | 135 | |
| 130 | 136 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 139 | 145 | etree.SubElement(version, "priority").text = __priority__ |
| 140 | 146 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 141 | 147 | |
| 142 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 143 | | xml_declaration=True)) |
| | 148 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 149 | pretty_print=True, xml_declaration=True))) |
| 144 | 150 | sys.exit(0) |
| 145 | 151 | |
| 146 | 152 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/lyricsmode.py b/mythtv/programs/scripts/metadata/Music/lyrics/lyricsmode.py
index b89c085416..e194c4171f 100644
|
a
|
b
|
|
| 1 | 1 | #-*- coding: UTF-8 -*- |
| 2 | 2 | import sys |
| 3 | | import urllib |
| | 3 | |
| | 4 | try: |
| | 5 | from urllib import urlopen, quote_plus |
| | 6 | except ImportError: |
| | 7 | from urllib.request import urlopen |
| | 8 | from urllib.parse import quote_plus |
| | 9 | |
| 4 | 10 | import re |
| 5 | 11 | from optparse import OptionParser |
| 6 | 12 | from common import utilities |
| … |
… |
class LyricsFetcher:
|
| 32 | 38 | lyrics_found = False |
| 33 | 39 | while True: |
| 34 | 40 | utilities.log(debug, "%s: search url: %s" % (__title__, url)) |
| 35 | | song_search = urllib.urlopen(url).read() |
| | 41 | song_search = urlopen(url).read() |
| 36 | 42 | if song_search.find("<p id=\"lyrics_text\" class=\"ui-annotatable\">") >= 0: |
| 37 | 43 | break |
| 38 | 44 | |
| … |
… |
class LyricsFetcher:
|
| 43 | 49 | |
| 44 | 50 | # Let's try to use the research box if we didn't yet |
| 45 | 51 | if not 'search' in url: |
| 46 | | url = "http://www.lyricsmode.com/search.php?what=songs&s=" + urllib.quote_plus(title.lower()) |
| | 52 | url = "http://www.lyricsmode.com/search.php?what=songs&s=" + quote_plus(title.lower()) |
| 47 | 53 | else: |
| 48 | 54 | # the search gave more than on result, let's try to find our song |
| 49 | 55 | url = "" |
| … |
… |
def performSelfTest():
|
| 102 | 108 | |
| 103 | 109 | if found: |
| 104 | 110 | utilities.log(True, "Everything appears in order.") |
| | 111 | buildLyrics(lyrics) |
| 105 | 112 | sys.exit(0) |
| 106 | 113 | |
| 107 | 114 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 120 | 127 | for line in lines: |
| 121 | 128 | etree.SubElement(xml, "lyric").text = line |
| 122 | 129 | |
| 123 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 124 | | xml_declaration=True)) |
| | 130 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 131 | pretty_print=True, xml_declaration=True))) |
| 125 | 132 | sys.exit(0) |
| 126 | 133 | |
| 127 | 134 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 136 | 143 | etree.SubElement(version, "priority").text = __priority__ |
| 137 | 144 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 138 | 145 | |
| 139 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 140 | | xml_declaration=True)) |
| | 146 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 147 | pretty_print=True, xml_declaration=True))) |
| 141 | 148 | sys.exit(0) |
| 142 | 149 | |
| 143 | 150 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/lyricswiki.py b/mythtv/programs/scripts/metadata/Music/lyrics/lyricswiki.py
index bcda8959f7..34179c180c 100644
|
a
|
b
|
|
| 1 | 1 | #-*- coding: UTF-8 -*- |
| 2 | | import sys, re, urllib2, socket, HTMLParser |
| | 2 | |
| | 3 | import sys, re, socket |
| | 4 | |
| | 5 | try: |
| | 6 | from urllib2 import quote, urlopen, HTTPError |
| | 7 | except ImportError: |
| | 8 | from urllib.request import urlopen, HTTPError |
| | 9 | from urllib.parse import quote |
| | 10 | |
| | 11 | try: |
| | 12 | import HTMLParser as html_parser |
| | 13 | except ImportError: |
| | 14 | from html import parser as html_parser |
| | 15 | |
| 3 | 16 | from optparse import OptionParser |
| 4 | 17 | |
| 5 | 18 | if sys.version_info < (2, 7): |
| … |
… |
class LyricsFetcher:
|
| 31 | 44 | utilities.log(debug, "%s: searching lyrics for %s - %s - %s" % (__title__, lyrics.artist, lyrics.album, lyrics.title)) |
| 32 | 45 | |
| 33 | 46 | try: |
| 34 | | req = urllib2.urlopen(self.url % (urllib2.quote(lyrics.artist), urllib2.quote(lyrics.title))) |
| 35 | | response = req.read() |
| | 47 | req = urlopen(self.url % (quote(lyrics.artist), quote(lyrics.title))) |
| | 48 | response = req.read().decode('utf-8') |
| 36 | 49 | except: |
| 37 | 50 | return False |
| 38 | 51 | req.close() |
| … |
… |
class LyricsFetcher:
|
| 44 | 57 | if not self.page.endswith('action=edit'): |
| 45 | 58 | utilities.log(debug, "%s: search url: %s" % (__title__, self.page)) |
| 46 | 59 | try: |
| 47 | | req = urllib2.urlopen(self.page) |
| 48 | | response = req.read() |
| 49 | | except urllib2.HTTPError, error: # strange... sometimes lyrics are returned with a 404 error |
| | 60 | req = urlopen(self.page) |
| | 61 | response = req.read().decode('utf-8') |
| | 62 | except HTTPError as error: # strange... sometimes lyrics are returned with a 404 error |
| 50 | 63 | if error.code == 404: |
| 51 | | response = error.read() |
| | 64 | response = error.read().decode('utf-8') |
| 52 | 65 | else: |
| 53 | 66 | return False |
| 54 | 67 | req.close() |
| 55 | 68 | matchcode = re.search("lyricbox'>.*?(&#.*?)<div", response) |
| 56 | 69 | try: |
| 57 | 70 | lyricscode = (matchcode.group(1)) |
| 58 | | htmlparser = HTMLParser.HTMLParser() |
| | 71 | htmlparser = html_parser.HTMLParser() |
| 59 | 72 | lyricstext = htmlparser.unescape(lyricscode).replace('<br />', '\n') |
| 60 | 73 | lyr = re.sub('<[^<]+?>', '', lyricstext) |
| 61 | 74 | if LIC_TXT in lyr: |
| … |
… |
def performSelfTest():
|
| 81 | 94 | |
| 82 | 95 | if found: |
| 83 | 96 | utilities.log(True, "Everything appears in order.") |
| | 97 | buildLyrics(lyrics) |
| 84 | 98 | sys.exit(0) |
| 85 | 99 | |
| 86 | 100 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 99 | 113 | for line in lines: |
| 100 | 114 | etree.SubElement(xml, "lyric").text = line |
| 101 | 115 | |
| 102 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 103 | | xml_declaration=True)) |
| | 116 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 117 | pretty_print=True, xml_declaration=True))) |
| 104 | 118 | sys.exit(0) |
| 105 | 119 | |
| 106 | 120 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 115 | 129 | etree.SubElement(version, "priority").text = __priority__ |
| 116 | 130 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 117 | 131 | |
| 118 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 119 | | xml_declaration=True)) |
| | 132 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 133 | pretty_print=True, xml_declaration=True))) |
| 120 | 134 | sys.exit(0) |
| 121 | 135 | |
| 122 | 136 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/lyrics/ttplayer.py b/mythtv/programs/scripts/metadata/Music/lyrics/ttplayer.py
index a573bce1c9..48a3898615 100644
|
a
|
b
|
taxigps
|
| 8 | 8 | import os |
| 9 | 9 | import sys |
| 10 | 10 | import socket |
| 11 | | import urllib |
| | 11 | |
| | 12 | try: |
| | 13 | from urllib import urlopen |
| | 14 | except ImportError: |
| | 15 | from urllib.request import urlopen |
| | 16 | |
| 12 | 17 | import re |
| 13 | 18 | import chardet |
| 14 | 19 | import random |
| … |
… |
class ttpClient(object):
|
| 108 | 113 | return tmp1 |
| 109 | 114 | |
| 110 | 115 | @staticmethod |
| 111 | | def EncodeArtTit(str): |
| | 116 | def EncodeArtTit(mystr): |
| 112 | 117 | rtn = '' |
| 113 | | uni = unicode(str, 'UTF-8') |
| 114 | | str = uni.encode('UTF-16')[2:] |
| 115 | | for i in range(len(str)): |
| 116 | | rtn += '%02x' % ord(str[i]) |
| 117 | | |
| | 118 | if utilities.IS_PY2: |
| | 119 | uni = unicode(mystr, 'UTF-8') |
| | 120 | mystr = uni.encode('UTF-16')[2:] |
| | 121 | for i in range(len(mystr)): |
| | 122 | rtn += '%02x' % ord(mystr[i]) |
| | 123 | else: |
| | 124 | uni = str(mystr) |
| | 125 | mystr = uni.encode('UTF-16')[2:] |
| | 126 | for i in range(len(mystr)): |
| | 127 | rtn += '%02x' % (mystr[i]) |
| 118 | 128 | return rtn |
| 119 | 129 | |
| 120 | 130 | |
| … |
… |
class LyricsFetcher:
|
| 145 | 155 | |
| 146 | 156 | try: |
| 147 | 157 | url = self.LIST_URL %(ttpClient.EncodeArtTit(artist.replace(' ','').lower()), ttpClient.EncodeArtTit(title.replace(' ','').lower())) |
| 148 | | f = urllib.urlopen(url) |
| 149 | | Page = f.read() |
| | 158 | f = urlopen(url) |
| | 159 | Page = f.read().decode('utf-8') |
| 150 | 160 | except: |
| 151 | 161 | utilities.log(True, "%s: %s::%s (%d) [%s]" % ( |
| 152 | 162 | __title__, self.__class__.__name__, |
| … |
… |
class LyricsFetcher:
|
| 168 | 178 | lyrics.list = links |
| 169 | 179 | for link in links: |
| 170 | 180 | lyr = self.get_lyrics_from_list(link) |
| 171 | | if lyr and lyr.startswith('['): |
| | 181 | if lyr and lyr.startswith(b'['): |
| 172 | 182 | enc = chardet.detect(lyr) |
| 173 | 183 | lyr = lyr.decode(enc['encoding'], 'ignore') |
| 174 | 184 | lyrics.lyrics = lyr |
| … |
… |
class LyricsFetcher:
|
| 180 | 190 | utilities.log(debug, '%s %s %s' %(Id, artist, song)) |
| 181 | 191 | try: |
| 182 | 192 | url = self.LYRIC_URL %(int(Id),ttpClient.CodeFunc(int(Id), artist + song), random.randint(0,0xFFFFFFFFFFFF)) |
| 183 | | f = urllib.urlopen(url) |
| | 193 | f = urlopen(url) |
| 184 | 194 | Page = f.read() |
| 185 | 195 | except: |
| 186 | 196 | utilities.log(True, "%s: %s::%s (%d) [%s]" % ( |
| … |
… |
class LyricsFetcher:
|
| 190 | 200 | sys.exc_info()[ 1 ] |
| 191 | 201 | )) |
| 192 | 202 | return None |
| 193 | | if Page.startswith('['): |
| | 203 | if Page.startswith(b'['): |
| 194 | 204 | return Page |
| 195 | 205 | return '' |
| 196 | 206 | |
| … |
… |
def performSelfTest():
|
| 208 | 218 | |
| 209 | 219 | if found: |
| 210 | 220 | utilities.log(True, "Everything appears in order.") |
| | 221 | buildLyrics(lyrics) |
| 211 | 222 | sys.exit(0) |
| 212 | 223 | |
| 213 | 224 | utilities.log(True, "The lyrics for the test search failed!") |
| … |
… |
def buildLyrics(lyrics):
|
| 226 | 237 | for line in lines: |
| 227 | 238 | etree.SubElement(xml, "lyric").text = line |
| 228 | 239 | |
| 229 | | utilities.log(True, etree.tostring(xml, encoding='UTF-8', pretty_print=True, |
| 230 | | xml_declaration=True)) |
| | 240 | utilities.log(True, utilities.convert_etree(etree.tostring(xml, encoding='UTF-8', |
| | 241 | pretty_print=True, xml_declaration=True))) |
| 231 | 242 | sys.exit(0) |
| 232 | 243 | |
| 233 | 244 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 242 | 253 | etree.SubElement(version, "priority").text = __priority__ |
| 243 | 254 | etree.SubElement(version, "syncronized").text = 'True' if __syncronized__ else 'False' |
| 244 | 255 | |
| 245 | | utilities.log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 246 | | xml_declaration=True)) |
| | 256 | utilities.log(True, utilities.convert_etree(etree.tostring(version, encoding='UTF-8', |
| | 257 | pretty_print=True, xml_declaration=True))) |
| 247 | 258 | sys.exit(0) |
| 248 | 259 | |
| 249 | 260 | def main(): |
diff --git a/mythtv/programs/scripts/metadata/Music/mbutils.py b/mythtv/programs/scripts/metadata/Music/mbutils.py
index 2e63371f38..fa4fe6965a 100755
|
a
|
b
|
from __future__ import print_function
|
| 19 | 19 | from __future__ import unicode_literals |
| 20 | 20 | from optparse import OptionParser |
| 21 | 21 | import musicbrainzngs |
| | 22 | from musicbrainzngs.compat import is_py2 |
| 22 | 23 | import sys |
| 23 | 24 | import pprint |
| 24 | 25 | |
| … |
… |
musicbrainzngs.set_hostname("musicbrainz-mirror.eu:5000")
|
| 42 | 43 | def log(debug, txt): |
| 43 | 44 | if debug: |
| 44 | 45 | print(txt) |
| | 46 | |
| | 47 | def convert_etree(etostr): |
| | 48 | """lxml.etree.tostring is a bytes object in python3, and a str in python2. |
| | 49 | """ |
| | 50 | if is_py2: |
| | 51 | return(etostr) |
| | 52 | else: |
| | 53 | return(etostr.decode()) |
| 45 | 54 | |
| 46 | 55 | def search_releases(artist, album, limit): |
| 47 | 56 | from lxml import etree |
| … |
… |
def search_releases(artist, album, limit):
|
| 52 | 61 | |
| 53 | 62 | if not result['release-list']: |
| 54 | 63 | etree.SubElement(root, "error").text = "No Releases found" |
| 55 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 64 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 56 | 65 | sys.exit(1) |
| 57 | 66 | |
| 58 | 67 | for (idx, release) in enumerate(result['release-list']): |
| … |
… |
def search_releases(artist, album, limit):
|
| 72 | 81 | if 'release-group' in release: |
| 73 | 82 | etree.SubElement(relNode, "releasegroup").text = release["release-group"]["id"] |
| 74 | 83 | |
| 75 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 84 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 76 | 85 | |
| 77 | 86 | sys.exit(0) |
| 78 | 87 | |
| … |
… |
def search_artists(artist, limit):
|
| 93 | 102 | etree.SubElement(artistNode, "sort-name").text = artist['sort-name'] |
| 94 | 103 | else: |
| 95 | 104 | etree.SubElement(root, "error").text = "No Artists found" |
| 96 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 105 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 97 | 106 | sys.exit(1) |
| 98 | 107 | |
| 99 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 108 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 100 | 109 | |
| 101 | 110 | sys.exit(0) |
| 102 | 111 | |
| … |
… |
def get_artist(artistid):
|
| 125 | 134 | node.set("type", url['type']) |
| 126 | 135 | else: |
| 127 | 136 | etree.SubElement(root, "error").text = "MusicBrainz ID was not found" |
| 128 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 137 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 129 | 138 | sys.exit(1) |
| 130 | 139 | |
| 131 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 140 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 132 | 141 | sys.exit(0) |
| 133 | 142 | |
| 134 | 143 | def find_coverart(release): |
| … |
… |
def find_coverart(release):
|
| 141 | 150 | except musicbrainzngs.ResponseError as err: |
| 142 | 151 | if err.cause.code == 404: |
| 143 | 152 | etree.SubElement(root, "error").text = "Release ID not found" |
| 144 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 153 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 145 | 154 | sys.exit(1) |
| 146 | 155 | else: |
| 147 | 156 | etree.SubElement(root, "error").text = "Received bad response from the MB server" |
| 148 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 157 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 149 | 158 | sys.exit(1) |
| 150 | 159 | |
| 151 | 160 | if debug: |
| … |
… |
def find_coverart(release):
|
| 161 | 170 | etree.SubElement(imageNode, "thumb-small").text = image["thumbnails"]["small"] |
| 162 | 171 | etree.SubElement(imageNode, "thumb-large").text = image["thumbnails"]["large"] |
| 163 | 172 | |
| 164 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 173 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 165 | 174 | sys.exit(0) |
| 166 | 175 | |
| 167 | 176 | def find_coverart_releasegroup(releaseGroup): |
| … |
… |
def find_coverart_releasegroup(releaseGroup):
|
| 174 | 183 | except musicbrainzngs.ResponseError as err: |
| 175 | 184 | if err.cause.code == 404: |
| 176 | 185 | etree.SubElement(root, "error").text = "Release ID not found" |
| 177 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 186 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 178 | 187 | sys.exit(1) |
| 179 | 188 | else: |
| 180 | 189 | etree.SubElement(root, "error").text = "Received bad response from the MB server" |
| 181 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 190 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 182 | 191 | sys.exit(1) |
| 183 | 192 | |
| 184 | 193 | if debug: |
| … |
… |
def find_coverart_releasegroup(releaseGroup):
|
| 194 | 203 | etree.SubElement(imageNode, "thumb-small").text = image["thumbnails"]["small"] |
| 195 | 204 | etree.SubElement(imageNode, "thumb-large").text = image["thumbnails"]["large"] |
| 196 | 205 | |
| 197 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 206 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 198 | 207 | sys.exit(0) |
| 199 | 208 | |
| 200 | 209 | def find_disc(cddrive): |
| … |
… |
def find_disc(cddrive):
|
| 209 | 218 | toc = disc.toc_string |
| 210 | 219 | except discid.DiscError as err: |
| 211 | 220 | etree.SubElement(root, "error").text = "Failed to get discid ({})".format(str(err)) |
| 212 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 221 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 213 | 222 | sys.exit(1) |
| 214 | 223 | |
| 215 | 224 | etree.SubElement(root, "discid").text = id |
| … |
… |
def find_disc(cddrive):
|
| 221 | 230 | except musicbrainzngs.ResponseError as err: |
| 222 | 231 | if err.cause.code == 404: |
| 223 | 232 | etree.SubElement(root, "error").text = "Disc not found" |
| 224 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 233 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 225 | 234 | sys.exit(1) |
| 226 | 235 | else: |
| 227 | 236 | etree.SubElement(root, "error").text = "Received bad response from the MB server" |
| 228 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 237 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 229 | 238 | sys.exit(1) |
| 230 | 239 | |
| 231 | 240 | # The result can either be a "disc" or a "cdstub" |
| … |
… |
def find_disc(cddrive):
|
| 266 | 275 | etree.SubElement(stubnode, "barcode").text = result['cdstub']['barcode'] |
| 267 | 276 | else: |
| 268 | 277 | etree.SubElement(root, "error").text = "No valid results" |
| 269 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 278 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 270 | 279 | sys.exit(1) |
| 271 | 280 | |
| 272 | | log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True)) |
| | 281 | log(True, convert_etree(etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))) |
| 273 | 282 | sys.exit(0) |
| 274 | 283 | |
| 275 | 284 | def buildVersion(): |
| … |
… |
def buildVersion():
|
| 281 | 290 | etree.SubElement(version, "description").text = __description__ |
| 282 | 291 | etree.SubElement(version, "version").text = __version__ |
| 283 | 292 | |
| 284 | | log(True, etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| 285 | | xml_declaration=True)) |
| | 293 | log(True, convert_etree(etree.tostring(version, encoding='UTF-8', pretty_print=True, |
| | 294 | xml_declaration=True))) |
| 286 | 295 | sys.exit(0) |
| 287 | 296 | |
| 288 | 297 | def performSelfTest(): |