mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-01-09 09:32:44 +01:00
Consolidate URL chapter range code and apply to CLI for #302.
This commit is contained in:
parent
5dfb2242b3
commit
d521cfdcf0
4 changed files with 30 additions and 20 deletions
|
|
@ -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<url>.*?)(?:\[(?P<begin>\d+)?(?P<comma>[,-])?(?P<end>\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.
|
||||
|
|
|
|||
|
|
@ -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<url>.*?)(?:\[(?P<begin>\d+)?(?P<comma>[,-])?(?P<end>\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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -353,14 +353,8 @@ class FanfictionDownloader(UserConfigServer):
|
|||
return
|
||||
|
||||
# Allow chapter range with URL.
|
||||
# test1.com?sid=5[4-6]
|
||||
mc = re.match(r"^(?P<url>.*?)(?:\[(?P<begin>\d+)?(?P<comma>[,-])?(?P<end>\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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue