diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 5f97f136..787430b7 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -2382,14 +2382,9 @@ class FanFicFarePlugin(InterfaceAction): def convert_url_to_book(self, url): book = self.make_book() - # look here for [\d,\d] at end of url, and remove? - mc = re.match(r"^(?P.*?)(?:\[(?P\d+)?(?P[,-])?(?P\d+)?\])?$",url) - #print("url:(%s) begin:(%s) end:(%s)"%(mc.group('url'),mc.group('begin'),mc.group('end'))) - url = mc.group('url') - book['begin'] = mc.group('begin') - book['end'] = mc.group('end') - if book['begin'] and not mc.group('comma'): - book['end'] = book['begin'] + # Allow chapter range with URL. + # like test1.com?sid=5[4-6] or [4,6] + url,book['begin'],book['end'] = adapters.get_url_chapter_range(url) self.set_book_url_and_comment(book,url) # normalizes book[url] # for case of trying to download book by sections. url[1-5], url[6-10], etc. diff --git a/fanficfare/adapters/__init__.py b/fanficfare/adapters/__init__.py index 89c53fbc..89375ba1 100644 --- a/fanficfare/adapters/__init__.py +++ b/fanficfare/adapters/__init__.py @@ -200,6 +200,18 @@ for x in imports(): l.append(cls) __domain_map[site]=l +def get_url_chapter_range(url_in): + # Allow chapter range with URL. + # like test1.com?sid=5[4-6] or [4,6] + mc = re.match(r"^(?P.*?)(?:\[(?P\d+)?(?P[,-])?(?P\d+)?\])?$",url_in) + #print("url:(%s) begin:(%s) end:(%s)"%(mc.group('url'),mc.group('begin'),mc.group('end'))) + url = mc.group('url') + ch_begin = mc.group('begin') + ch_end = mc.group('end') + if ch_begin and not mc.group('comma'): + ch_end = ch_begin + return url,ch_begin,ch_end + def getNormalStoryURL(url): r = getNormalStoryURLSite(url) if r: diff --git a/fanficfare/cli.py b/fanficfare/cli.py index af53d3f3..71ce1113 100644 --- a/fanficfare/cli.py +++ b/fanficfare/cli.py @@ -78,7 +78,6 @@ def main(argv=None, parser = OptionParser('usage: %prog [options] [STORYURL]...') parser.add_option('-f', '--format', dest='format', default='epub', help='write story as FORMAT, epub(default), mobi, txt or html', metavar='FORMAT') - if passed_defaultsini: config_help = 'read config from specified file(s) in addition to calibre plugin personal.ini, ~/.fanficfare/personal.ini, and ./personal.ini' else: @@ -86,10 +85,11 @@ def main(argv=None, parser.add_option('-c', '--config', action='append', dest='configfile', default=None, help=config_help, metavar='CONFIG') + range_help = ' --begin and --end will be overridden by a chapter range on the STORYURL like STORYURL[1-2], STORYURL[-3], STORYURL[3-] or STORYURL[3]' parser.add_option('-b', '--begin', dest='begin', default=None, - help='Begin with Chapter START', metavar='START') + help='Begin with Chapter START.'+range_help, metavar='START') parser.add_option('-e', '--end', dest='end', default=None, - help='End with Chapter END', metavar='END') + help='End with Chapter END.'+range_help, metavar='END') parser.add_option('-o', '--option', action='append', dest='options', help='set an option NAME=VALUE', metavar='NAME=VALUE') @@ -314,6 +314,11 @@ def do_download(arg, output_filename) try: + # Allow chapter range with URL. + # like test1.com?sid=5[4-6] or [4,6] + # Overrides CLI options if present. + url,ch_begin,ch_end = adapters.get_url_chapter_range(url) + adapter = adapters.getAdapter(configuration, url) ## Share pagecache and cookiejar between multiple downloads. @@ -324,7 +329,11 @@ def do_download(arg, configuration.set_pagecache(options.pagecache) configuration.set_cookiejar(options.cookiejar) - adapter.setChaptersRange(options.begin, options.end) + # url[begin-end] overrides CLI option if present. + if ch_begin or ch_end: + adapter.setChaptersRange(ch_begin, ch_end) + else: + adapter.setChaptersRange(options.begin, options.end) # check for updating from URL (vs from file) if options.update and not chaptercount: diff --git a/webservice/main.py b/webservice/main.py index 6c1b0275..a94b281c 100644 --- a/webservice/main.py +++ b/webservice/main.py @@ -353,14 +353,8 @@ class FanfictionDownloader(UserConfigServer): return # Allow chapter range with URL. - # test1.com?sid=5[4-6] - mc = re.match(r"^(?P.*?)(?:\[(?P\d+)?(?P[,-])?(?P\d+)?\])?$",url) - #print("url:(%s) begin:(%s) end:(%s)"%(mc.group('url'),mc.group('begin'),mc.group('end'))) - url = mc.group('url') - ch_begin = mc.group('begin') - ch_end = mc.group('end') - if ch_begin and not mc.group('comma'): - ch_end = ch_begin + # like test1.com?sid=5[4-6] or [4,6] + url,ch_begin,ch_end = adapters.get_url_chapter_range(url) logging.info("Queuing Download: %s" % url) login = self.request.get('login')