forked from openlp/openlp
Make songselect import work on both python 3.3 and 3.5
This commit is contained in:
parent
568904a6cf
commit
7470205185
@ -23,11 +23,13 @@
|
||||
The :mod:`~openlp.plugins.songs.lib.songselect` module contains the SongSelect importer itself.
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
from http.cookiejar import CookieJar
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import HTTPCookieProcessor, URLError, build_opener
|
||||
from html.parser import HTMLParser
|
||||
from html import unescape
|
||||
if sys.version_info > (3,4):
|
||||
from html import unescape
|
||||
|
||||
|
||||
from bs4 import BeautifulSoup, NavigableString
|
||||
@ -130,11 +132,18 @@ class SongSelectImport(object):
|
||||
if not search_results:
|
||||
break
|
||||
for result in search_results:
|
||||
song = {
|
||||
'title': unescape(result.find('h3').string),
|
||||
'authors': [unescape(author.string) for author in result.find_all('li')],
|
||||
'link': BASE_URL + result.find('a')['href']
|
||||
}
|
||||
if sys.version_info > (3,4):
|
||||
song = {
|
||||
'title': unescape(result.find('h3').string),
|
||||
'authors': [unescape(author.string) for author in result.find_all('li')],
|
||||
'link': BASE_URL + result.find('a')['href']
|
||||
}
|
||||
else:
|
||||
song = {
|
||||
'title': self.html_parser.unescape(result.find('h3').string),
|
||||
'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')],
|
||||
'link': BASE_URL + result.find('a')['href']
|
||||
}
|
||||
if callback:
|
||||
callback(song)
|
||||
songs.append(song)
|
||||
@ -168,7 +177,10 @@ class SongSelectImport(object):
|
||||
if callback:
|
||||
callback()
|
||||
song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')])
|
||||
song['copyright'] = unescape(song['copyright'])
|
||||
if sys.version_info > (3,4):
|
||||
song['copyright'] = unescape(song['copyright'])
|
||||
else:
|
||||
song['copyright'] = self.html_parser.unescape(song['copyright'])
|
||||
song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip()
|
||||
song['verses'] = []
|
||||
verses = lyrics_page.find('section', 'lyrics').find_all('p')
|
||||
@ -181,9 +193,15 @@ class SongSelectImport(object):
|
||||
else:
|
||||
verse['lyrics'] += '\n'
|
||||
verse['lyrics'] = verse['lyrics'].strip(' \n\r\t')
|
||||
song['verses'].append(unescape(verse))
|
||||
if sys.version_info > (3,4):
|
||||
song['verses'].append(unescape(verse))
|
||||
else:
|
||||
song['verses'].append(self.html_parser.unescape(verse))
|
||||
for counter, author in enumerate(song['authors']):
|
||||
song['authors'][counter] = unescape(author)
|
||||
if sys.version_info > (3,4):
|
||||
song['authors'][counter] = unescape(author)
|
||||
else:
|
||||
song['authors'][counter] = self.html_parser.unescape(author)
|
||||
return song
|
||||
|
||||
def save_song(self, song):
|
||||
|
Loading…
Reference in New Issue
Block a user