diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 253c6cfbc..7a35508fc 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -32,24 +32,32 @@ import re log = logging.getLogger(__name__) -# English: -BIBLE_SEPARATORS = {u'sep_v': r'\s*:\s*', u'sep_r': r'\s*-\s*', u'sep_l': r','} -# German: -#BIBLE_SEPARATORS = {u'sep_v': r'\s*,\s*', u'sep_r': r'\s*-\s*', u'sep_l': r'\.'} +def get_reference_match(match_type): + local_separator = unicode(u':;;\s*[:vV]\s*;;-;;\s*-\s*;;,;;\s*,\s*;;end' + ).split(u';;') # English + # local_separator = unicode(u',;;\s*,\s*;;-;;\s*-\s*;;.;;\.;;[Ee]nde' + # ).split(u';;') # German + separators = { + u'sep_v_display': local_separator[0], u'sep_v': local_separator[1], + u'sep_r_display': local_separator[2], u'sep_r': local_separator[3], + u'sep_l_display': local_separator[4], u'sep_l': local_separator[5], + u'sep_e': local_separator[6]} -# RegEx for a verse span: (:)?(-(:)??)? -BIBLE_RANGE_REGEX = str(r'(?:(?P[0-9]+)%(sep_v)s)?' - r'(?P[0-9]+)(?P%(sep_r)s(?:(?:(?P[0-9]+)' - r'%(sep_v)s)?(?P[0-9]+))?)?' % BIBLE_SEPARATORS) - -BIBLE_RANGE = re.compile(r'^\s*' + BIBLE_RANGE_REGEX + r'\s*$', re.UNICODE) - -BIBLE_RANGE_SPLIT = re.compile(BIBLE_SEPARATORS[u'sep_l']) - -# RegEx for a reference ((,|(?=$)))+ -BIBLE_REFERENCE = re.compile(str(r'^\s*(?!\s)(?P[\d]*[^\d]+)(?(?:' + BIBLE_RANGE_REGEX + r'(?:%(sep_l)s|(?=\s*$)))+)\s*$') % - BIBLE_SEPARATORS, re.UNICODE) + # verse range match: (:)?(-(:)??)? + range_string = str(r'(?:(?P[0-9]+)%(sep_v)s)?(?P' + r'[0-9]+)(?P%(sep_r)s(?:(?:(?P[0-9]+)%(sep_v)s)?' + r'(?P[0-9]+)|%(sep_e)s)?)?' % separators) + if match_type == u'range': + return re.compile(r'^\s*' + range_string + r'\s*$', re.UNICODE) + elif match_type == u'range_separator': + return re.compile(separators[u'sep_l']) + elif match_type == u'full': + # full reference match: ((,|(?=$)))+ + return re.compile(str(r'^\s*(?!\s)(?P[\d]*[^\d]+)(?(?:' + range_string + r'(?:%(sep_l)s|(?=\s*$)))+)\s*$') + % separators, re.UNICODE) + else: + return separators[match_type] def parse_reference(reference): """ @@ -57,7 +65,6 @@ def parse_reference(reference): typed in string and converts it to a reference list, a list of references to be queried from the Bible database files. -##### This is a user manual like description, how the references are working. - Each reference starts with the book name. A chapter name is manditory. @@ -80,9 +87,8 @@ def parse_reference(reference): chapter 3 verse 1 - If there is a range separator without further verse declaration the last refered chapter is addressed until the end. -##### - The ``BIBLE_RANGE`` regular expression produces match groups for verse range + ``range_string`` is a regular expression which matches for verse range declarations: 1. ``(?:(?P[0-9]+)%(sep_v)s)?' @@ -90,28 +96,25 @@ def parse_reference(reference): a verse separator. 2. ``(?P[0-9]+)`` The verse reference ``from_verse`` is manditory - 3. ``(?P%(sep_r)s(?:`` ... ``)?)?`` + 3. ``(?P%(sep_r)s(?:`` ... ``|%(sep_e)s)?)?`` A ``range_to`` declaration is optional. It starts with a range seperator - and contains a optional chapter and verse declaration + and contains optional a chapter and verse declaration or a end + separator. 4. ``(?:(?P[0-9]+)%(sep_v)s)?`` The ``to_chapter`` reference with seperator is equivalent to group 1. - 5. ``(?P[0-9]+)?)?`` + 5. ``(?P[0-9]+)`` The ``to_verse`` reference is equivalent to group 2. - The ``BIBLE_REFERENCE`` regular expression produces matched groups for the - whole reference string: + The full reference is matched against get_reference_match(u'full'). This + regular expression looks like this: 1. ``^\s*(?!\s)(?P[\d]*[^\d]+)(?(?:`` + BIBLE_RANGE_REGEX + - ``(?:%(sep_l)s|(?=\s*$)))+)\s*$`` - The sechon group contains all ``ranges``. This can be multiple - declarations of a BIBLE_RANGE separated by a list separator. - - ``BIBLE_SEPARATORS`` is a dict which defines the separator formats. It might - be used to localize the bible references. + 2. ``(?P(?:`` + range_string + ``(?:%(sep_l)s|(?=\s*$)))+)\s*$`` + The second group contains all ``ranges``. This can be multiple + declarations of a range_string separated by a list separator. The reference list is a list of tuples, with each tuple structured like this:: @@ -125,20 +128,21 @@ def parse_reference(reference): """ log.debug('parse_reference("%s")', reference) - match = BIBLE_REFERENCE.match(reference) + match = get_reference_match(u'full').match(reference) if match: log.debug(u'Matched reference %s' % reference) book = match.group(u'book') - ranges = BIBLE_RANGE_SPLIT.split(match.group(u'ranges')) + ranges = match.group(u'ranges') + range_list = get_reference_match(u'range_separator').split(ranges) ref_list = [] chapter = 0 - for this_range in ranges: - range_match = BIBLE_RANGE.match(this_range) - from_chapter = range_match.group('from_chapter') - from_verse = range_match.group('from_verse') - has_range = range_match.group('range_to') - to_chapter = range_match.group('to_chapter') - to_verse = range_match.group('to_verse') + for this_range in range_list: + range_match = get_reference_match(u'range').match(this_range) + from_chapter = range_match.group(u'from_chapter') + from_verse = range_match.group(u'from_verse') + has_range = range_match.group(u'range_to') + to_chapter = range_match.group(u'to_chapter') + to_verse = range_match.group(u'to_verse') if from_chapter: from_chapter = int(from_chapter) if from_verse: @@ -147,7 +151,7 @@ def parse_reference(reference): to_chapter = int(to_chapter) if to_verse: to_verse = int(to_verse) - # Fill chapters with reasonable values. + # Fill chapter fields with reasonable values. if from_chapter: chapter = from_chapter elif chapter: @@ -173,10 +177,10 @@ def parse_reference(reference): to_verse = -1 if to_chapter > from_chapter: ref_list.append((book, from_chapter, from_verse, -1)) - for i in range(int(from_chapter) + 1, int(to_chapter) - 1): + for i in range(from_chapter + 1, to_chapter - 1): ref_list.append((book, i, 1, -1)) ref_list.append((book, to_chapter, 1, to_verse)) - elif to_verse >= from_verse: + elif to_verse >= from_verse or to_verse == -1: ref_list.append((book, from_chapter, from_verse, to_verse)) elif from_verse: ref_list.append((book, from_chapter, from_verse, from_verse)) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 8f36d33c5..4ed6e5394 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -273,7 +273,7 @@ class BSExtract(object): chapter_url = u'http://m.bibleserver.com/text/%s/%s%s000' % \ (version, bookindex, chapter_string) ''' - chapter_url = u'http://m.bibleserver.com/#/%s/%s%s' % \ + chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \ (version, bookname, chapter) log.debug(u'URL: %s', chapter_url) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 84505c991..cced544b9 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -32,6 +32,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, Receiver, BaseListWithDnD, \ ItemCapabilities, translate from openlp.plugins.bibles.forms import BibleImportForm +from openlp.plugins.bibles.lib import get_reference_match log = logging.getLogger(__name__) @@ -553,12 +554,15 @@ class BibleMediaItem(MediaManagerItem): bible = unicode(self.AdvancedVersionComboBox.currentText()) second_bible = unicode(self.AdvancedSecondBibleComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText()) - chapter_from = int(self.AdvancedFromChapter.currentText()) - chapter_to = int(self.AdvancedToChapter.currentText()) - verse_from = int(self.AdvancedFromVerse.currentText()) - verse_to = int(self.AdvancedToVerse.currentText()) - versetext = u'%s %s:%s-%s:%s' % (book, chapter_from, verse_from, - chapter_to, verse_to) + chapter_from = self.AdvancedFromChapter.currentText() + chapter_to = self.AdvancedToChapter.currentText() + verse_from = self.AdvancedFromVerse.currentText() + verse_to = self.AdvancedToVerse.currentText() + verse_separator = get_reference_match(u'sep_v_display') + range_separator = get_reference_match(u'sep_r_display') + verse_range = chapter_from + verse_separator + verse_from + \ + range_separator + chapter_to + verse_separator + verse_to + versetext = u'%s %s' % (book, verse_range) self.search_results = self.parent.manager.get_verses(bible, versetext) if second_bible: self.second_search_results = self.parent.manager.get_verses( @@ -709,7 +713,7 @@ class BibleMediaItem(MediaManagerItem): obj = reference[QtCore.QString(key)] if isinstance(obj, QtCore.QVariant): obj = obj.toPyObject() - return unicode(obj) + return unicode(obj).strip() def generateSlideData(self, service_item, item=None, xmlVersion=False): """ @@ -816,36 +820,31 @@ class BibleMediaItem(MediaManagerItem): ``old_item`` The last item of a range. """ + verse_separator = get_reference_match(u'sep_v_display') + range_separator = get_reference_match(u'sep_r_display') old_bitem = self.listView.item(old_item.row()) - old_chapter = int(self._decodeQtObject(old_bitem, 'chapter')) - old_verse = int(self._decodeQtObject(old_bitem, 'verse')) + old_chapter = self._decodeQtObject(old_bitem, 'chapter') + old_verse = self._decodeQtObject(old_bitem, 'verse') start_bitem = self.listView.item(start_item.row()) start_book = self._decodeQtObject(start_bitem, 'book') - start_chapter = int(self._decodeQtObject(start_bitem, 'chapter')) - start_verse = int(self._decodeQtObject(start_bitem, 'verse')) + start_chapter = self._decodeQtObject(start_bitem, 'chapter') + start_verse = self._decodeQtObject(start_bitem, 'verse') start_bible = self._decodeQtObject(start_bitem, 'bible') start_second_bible = self._decodeQtObject(start_bitem, 'second_bible') if start_second_bible: - if start_verse == old_verse and start_chapter == old_chapter: - title = u'%s %s:%s (%s, %s)' % (start_book, start_chapter, - start_verse, start_bible, start_second_bible) - elif start_chapter == old_chapter: - title = u'%s %s:%s-%s (%s, %s)' % (start_book, start_chapter, - start_verse, old_verse, start_bible, start_second_bible) - else: - title = u'%s %s:%s-%s:%s (%s, %s)' % (start_book, start_chapter, - start_verse, old_chapter, old_verse, start_bible, - start_second_bible) + bibles = u'%s, %s' % (start_bible, start_second_bible) else: - if start_verse == old_verse and start_chapter == old_chapter: - title = u'%s %s:%s (%s)' % (start_book, start_chapter, - start_verse, start_bible) - elif start_chapter == old_chapter: - title = u'%s %s:%s-%s (%s)' % (start_book, start_chapter, - start_verse, old_verse, start_bible) + bibles = start_bible + if start_chapter == old_chapter: + if start_verse == old_verse: + verse_range = start_chapter + verse_separator + start_verse else: - title = u'%s %s:%s-%s:%s (%s)' % (start_book, start_chapter, - start_verse, old_chapter, old_verse, start_bible) + verse_range = start_chapter + verse_separator + start_verse + \ + range_separator + old_verse + else: + verse_range = start_chapter + verse_separator + start_verse + \ + range_separator + old_chapter + verse_separator + old_verse + title = u'%s %s (%s)' % (start_book, verse_range, bibles) return title def checkTitle(self, item, old_item): @@ -907,9 +906,11 @@ class BibleMediaItem(MediaManagerItem): ``verse`` The verse number (int). """ + + verse_separator = get_reference_match(u'sep_v_display') if not self.parent.settings_tab.show_new_chapters or \ old_chapter != chapter: - verse_text = u'%s:%s' % (chapter, verse) + verse_text = unicode(chapter) + verse_separator + unicode(verse) else: verse_text = u'%s' % verse if self.parent.settings_tab.display_style == 1: diff --git a/openlp/plugins/bibles/resources/bibleserver.csv b/openlp/plugins/bibles/resources/bibleserver.csv index 0f2baa0cc..d73bf1678 100644 --- a/openlp/plugins/bibles/resources/bibleserver.csv +++ b/openlp/plugins/bibles/resources/bibleserver.csv @@ -23,7 +23,7 @@ Neue Genfer Übersetzung, NGÜ New International Readers Version, NIRV New International Version, NIV Neues Leben, NL -En Levende Bok, NOR +En Levende Bok (NOR), NOR Nádej pre kazdého, NPK Noua traducere în limba românã, NTR Nueva Versión Internacional, NVI @@ -33,7 +33,7 @@ O Livro, PRT Новый перевод на русский язык, RUS Slovo na cestu, SNC Schlachter 2000, SLT -En Levande Bok, SVL +En Levande Bok (SWE), SVL Today's New International Version, TNIV Türkçe, TR Vulgata, VUL