From b337c9aa7906160a2eddcbdfc67fec50c18b5326 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 25 May 2012 17:03:46 -0500 Subject: [PATCH] Integrate new adapter for thehexfiles.net, new inject series plugin feature. --- app.yaml | 2 +- calibre-plugin/__init__.py | 2 +- calibre-plugin/config.py | 8 ++++++++ calibre-plugin/ffdl_plugin.py | 11 +++++++--- calibre-plugin/jobs.py | 5 +++++ defaults.ini | 2 ++ fanficdownloader/adapters/__init__.py | 1 + fanficdownloader/adapters/adapter_test1.py | 24 ++++++++++------------ fanficdownloader/adapters/base_adapter.py | 2 +- index.html | 21 ++++++++----------- plugin-defaults.ini | 2 ++ 11 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app.yaml b/app.yaml index 5ffbce4..7f3f3ad 100644 --- a/app.yaml +++ b/app.yaml @@ -1,6 +1,6 @@ # ffd-retief-hrd fanfictiondownloader application: fanfictiondownloader -version: 4-4-11 +version: 4-4-12 runtime: python27 api_version: 1 threadsafe: true diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 8d7c4f7..bdc4f3b 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -27,7 +27,7 @@ class FanFictionDownLoaderBase(InterfaceActionBase): description = 'UI plugin to download FanFiction stories from various sites.' supported_platforms = ['windows', 'osx', 'linux'] author = 'Jim Miller' - version = (1, 5, 23) + version = (1, 5, 24) minimum_calibre_version = (0, 8, 30) #: This field defines the GUI plugin class that contains all the code diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 6f97fb3..ad68bf8 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -48,6 +48,7 @@ all_prefs.defaults['deleteotherforms'] = False all_prefs.defaults['adddialogstaysontop'] = False all_prefs.defaults['includeimages'] = False all_prefs.defaults['lookforurlinhtml'] = False +all_prefs.defaults['injectseries'] = False all_prefs.defaults['send_lists'] = '' all_prefs.defaults['read_lists'] = '' @@ -75,6 +76,7 @@ copylist = ['personal.ini', 'adddialogstaysontop', 'includeimages', 'lookforurlinhtml', + 'injectseries', 'gcnewonly', 'gc_site_settings', 'allow_gc_from_ini'] @@ -181,6 +183,7 @@ class ConfigWidget(QWidget): prefs['adddialogstaysontop'] = self.basic_tab.adddialogstaysontop.isChecked() prefs['includeimages'] = self.basic_tab.includeimages.isChecked() prefs['lookforurlinhtml'] = self.basic_tab.lookforurlinhtml.isChecked() + prefs['injectseries'] = self.basic_tab.injectseries.isChecked() if self.readinglist_tab: # lists @@ -320,6 +323,11 @@ class BasicTab(QWidget): self.lookforurlinhtml.setChecked(prefs['lookforurlinhtml']) self.l.addWidget(self.lookforurlinhtml) + self.injectseries = QCheckBox("Inject calibre Series when none found?",self) + self.injectseries.setToolTip("If no series is found, inject the calibre series (if there is one) so it appears on the FFDL title page(not cover).") + self.injectseries.setChecked(prefs['injectseries']) + self.l.addWidget(self.injectseries) + self.l.insertStretch(-1) def set_collisions(self): diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index c142f0a..1a72a6e 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -572,7 +572,13 @@ make_firstimage_cover:true # this behavior matches how epubs come out when imported # dateCreated == packaged--epub/etc created. book['timestamp'] = story.getMetadataRaw('dateCreated').replace(tzinfo=local_tz) - + + if book_id != None and prefs['injectseries']: + mi = db.get_metadata(book_id,index_is_id=True) + if not book['series'] and mi.series != None: + book['calibre_series'] = (mi.series,mi.series_index) + print("calibre_series:%s [%s]"%book['calibre_series']) + if book['good']: # there shouldn't be any !'good' books at this point. # if still 'good', make a temp file to write the output to. tmp = PersistentTemporaryFile(prefix='new-%s-'%book['calibre_id'], @@ -795,7 +801,7 @@ make_firstimage_cover:true coldef = custom_columns[col] if not meta.startswith('status-') and meta not in book['all_metadata'] or \ meta.startswith('status-') and 'status' not in book['all_metadata']: - print("No value for %s, skipping."%meta) + print("No value for %s, skipping custom column(%s) update."%(meta,coldef['name'])) continue if meta not in permitted_values[coldef['datatype']]: print("%s not a valid column type for %s, skipping."%(col,meta)) @@ -815,7 +821,6 @@ make_firstimage_cover:true db.commit() - print("book['added']:%s"%book['added']) if 'Generate Cover' in self.gui.iactions and (book['added'] or not prefs['gcnewonly']): gc_plugin = self.gui.iactions['Generate Cover'] setting_name = None diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index 55c9853..39156ba 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -113,6 +113,11 @@ def do_download_for_worker(book,options): adapter.password = book['password'] story = adapter.getStoryMetadataOnly() + if 'calibre_series' in book: + print("calibre_series:%s [%d]"%book['calibre_series']) + adapter.setSeries(book['calibre_series'][0],book['calibre_series'][1]) + else: + print("no calibre_series") writer = writers.getWriter(options['fileform'],adapter.config,adapter) outfile = book['outfile'] diff --git a/defaults.ini b/defaults.ini index 33a621b..f863361 100644 --- a/defaults.ini +++ b/defaults.ini @@ -409,6 +409,8 @@ cover_exclusion_regexp:/images/.*?ribbon.gif #username:YourName #password:yourpassword +[thehexfiles.net] + [thequidditchpitch.org] ## Some sites require login (or login for some rated stories) The ## program can prompt you, or you can save it in config. In diff --git a/fanficdownloader/adapters/__init__.py b/fanficdownloader/adapters/__init__.py index 871a0b0..a879e2f 100644 --- a/fanficdownloader/adapters/__init__.py +++ b/fanficdownloader/adapters/__init__.py @@ -64,6 +64,7 @@ import adapter_occlumencysycophanthexcom import adapter_phoenixsongnet import adapter_walkingtheplankorg import adapter_ashwindersycophanthexcom +import adapter_thehexfilesnet ## This bit of complexity allows adapters to be added by just adding ## importing. It eliminates the long if/else clauses we used to need diff --git a/fanficdownloader/adapters/adapter_test1.py b/fanficdownloader/adapters/adapter_test1.py index c655737..c85a673 100644 --- a/fanficdownloader/adapters/adapter_test1.py +++ b/fanficdownloader/adapters/adapter_test1.py @@ -90,17 +90,16 @@ Some more longer description. "I suck at summaries!" "Better than it sounds!" else: self.story.setMetadata('status','Completed') - langs = { - 0:"English", - 1:"Russian", - 2:"French", - 3:"German", - } + # greater than 10, no language or series. if idnum < 10: + langs = { + 0:"English", + 1:"Russian", + 2:"French", + 3:"German", + } self.story.setMetadata('language',langs[idnum%len(langs)]) - # greater than 10, no language. - - self.setSeries('The Great Test',idnum) + self.setSeries('The Great Test',idnum) self.story.setMetadata('rating','Tweenie') @@ -161,7 +160,7 @@ Some more longer description. "I suck at summaries!" "Better than it sounds!" text=u'''

Prologue

-

This is a fake adapter for testing purposes. Different storyId's will give different errors:

+

This is a fake adapter for testing purposes. Different sid's will give different errors:

http://test1.com?sid=664 - Crazy string title

http://test1.com?sid=665 - raises AdultCheckRequired

http://test1.com?sid=666 - raises StoryDoesNotExist

@@ -171,18 +170,17 @@ Some more longer description. "I suck at summaries!" "Better than it sounds!"

http://test1.com?sid=670 - Succeeds, but sleeps 2sec on each chapter

http://test1.com?sid=671 - Succeeds, but sleeps 2sec metadata only

http://test1.com?sid=672 - Succeeds, quick meta, sleeps 2sec chapters only

-

And other storyId will succeed with the same output.

+

Odd sid's will be In-Progress, evens complete. sid<10 will be assigned one of four languages and included in a series.

''' else: text=u'''

Chapter title from site

-

Centered text

Lorem '''+self.crazystring+u''' italics, bold, underline consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

br breaks

Puella Magi Madoka Magica/魔法少女まどか★マギカ -
+
br breaks

Don't—e;ver—d;o—that—a;gain, 法 é
diff --git a/fanficdownloader/adapters/base_adapter.py b/fanficdownloader/adapters/base_adapter.py index f9f977c..b1d41f3 100644 --- a/fanficdownloader/adapters/base_adapter.py +++ b/fanficdownloader/adapters/base_adapter.py @@ -265,7 +265,7 @@ class BaseSiteAdapter(Configurable): # Just for series, in case we choose to change how it's stored or represented later. def setSeries(self,name,num): if self.getConfig('collect_series'): - self.story.setMetadata('series','%s [%s]'%(name, num)) + self.story.setMetadata('series','%s [%s]'%(name, int(num))) def setDescription(self,url,svalue): #print("\n\nsvalue:\n%s\n"%svalue) diff --git a/index.html b/index.html index 3f4bf5f..41e9a9e 100644 --- a/index.html +++ b/index.html @@ -54,19 +54,9 @@ much easier.

-

More New Sites

+

New Site

- Ida's been busy! We now have support for an additional 8 new sites: -

+ Now supporting thehexfiles.net, that brings us up to an even 40 supported sites. Thanks again, Ida.

Questions? Check out our @@ -76,7 +66,7 @@ If you have any problems with this application, please report them in the FanFictionDownLoader Google Group. The - Previous Version is also available for you to use if necessary. + Previous Version is also available for you to use if necessary.

{{ error_message }} @@ -363,6 +353,11 @@ Use the URL of the story's first chapter, such as
http://www.walkingtheplank.org/archive/viewstory.php?sid=1234 +
thehexfiles.net
+
+ Use the URL of the story's chapter list, such as +
http://thehexfiles.net/viewstory.php?sid=1234 +

A few additional things to know, which will make your life substantially easier: diff --git a/plugin-defaults.ini b/plugin-defaults.ini index 9788dca..dc5d3da 100644 --- a/plugin-defaults.ini +++ b/plugin-defaults.ini @@ -395,6 +395,8 @@ cover_exclusion_regexp:/images/.*?ribbon.gif #username:YourName #password:yourpassword +[thehexfiles.net] + [thequidditchpitch.org] ## Some sites require login (or login for some rated stories) The ## program can prompt you, or you can save it in config. In