From 1be9804d51e12cf70e334416dbb139bf85d1f04d Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 25 Mar 2011 21:08:38 -0400 Subject: [PATCH] FB2 Output: Allow user to set genre from FB2 2.1 Genres. --- src/calibre/ebooks/fb2/fb2ml.py | 3 +- src/calibre/ebooks/fb2/output.py | 132 +++++++++++++++++++++++++ src/calibre/gui2/convert/fb2_output.py | 4 +- src/calibre/gui2/convert/fb2_output.ui | 36 ++++--- 4 files changed, 160 insertions(+), 15 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index d86a83e9b0..8d1164e026 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -111,6 +111,7 @@ class FB2MLizer(object): metadata['lang'] = u'en' metadata['id'] = None metadata['cover'] = self.get_cover() + metadata['genre'] = self.opts.fb2_genre metadata['author'] = u'' for auth in self.oeb_book.metadata.creator: @@ -159,7 +160,7 @@ class FB2MLizer(object): return u'' \ '' \ '' \ - 'antique' \ + '%(genre)s' \ '%(author)s' \ '%(title)s' \ '%(cover)s' \ diff --git a/src/calibre/ebooks/fb2/output.py b/src/calibre/ebooks/fb2/output.py index bce0a00029..bccc665d35 100644 --- a/src/calibre/ebooks/fb2/output.py +++ b/src/calibre/ebooks/fb2/output.py @@ -15,6 +15,133 @@ class FB2Output(OutputFormatPlugin): author = 'John Schember' file_type = 'fb2' + FB2_GENRES = [ + # Science Fiction & Fantasy + 'sf_history', # Alternative history + 'sf_action', # Action + 'sf_epic', # Epic + 'sf_heroic', # Heroic + 'sf_detective', # Detective + 'sf_cyberpunk', # Cyberpunk + 'sf_space', # Space + 'sf_social', # Social#philosophical + 'sf_horror', # Horror & mystic + 'sf_humor', # Humor + 'sf_fantasy', # Fantasy + 'sf', # Science Fiction + # Detectives & Thrillers + 'det_classic', # Classical detectives + 'det_police', # Police Stories + 'det_action', # Action + 'det_irony', # Ironical detectives + 'det_history', # Historical detectives + 'det_espionage', # Espionage detectives + 'det_crime', # Crime detectives + 'det_political', # Political detectives + 'det_maniac', # Maniacs + 'det_hard', # Hard#boiled + 'thriller', # Thrillers + 'detective', # Detectives + # Prose + 'prose_classic', # Classics prose + 'prose_history', # Historical prose + 'prose_contemporary', # Contemporary prose + 'prose_counter', # Counterculture + 'prose_rus_classic', # Russial classics prose + 'prose_su_classics', # Soviet classics prose + # Romance + 'love_contemporary', # Contemporary Romance + 'love_history', # Historical Romance + 'love_detective', # Detective Romance + 'love_short', # Short Romance + 'love_erotica', # Erotica + # Adventure + 'adv_western', # Western + 'adv_history', # History + 'adv_indian', # Indians + 'adv_maritime', # Maritime Fiction + 'adv_geo', # Travel & geography + 'adv_animal', # Nature & animals + 'adventure', # Other + # Children's + 'child_tale', # Fairy Tales + 'child_verse', # Verses + 'child_prose', # Prose + 'child_sf', # Science Fiction + 'child_det', # Detectives & Thrillers + 'child_adv', # Adventures + 'child_education', # Educational + 'children', # Other + # Poetry & Dramaturgy + 'poetry', # Poetry + 'dramaturgy', # Dramaturgy + # Antique literature + 'antique_ant', # Antique + 'antique_european', # European + 'antique_russian', # Old russian + 'antique_east', # Old east + 'antique_myths', # Myths. Legends. Epos + 'antique', # Other + # Scientific#educational + 'sci_history', # History + 'sci_psychology', # Psychology + 'sci_culture', # Cultural science + 'sci_religion', # Religious studies + 'sci_philosophy', # Philosophy + 'sci_politics', # Politics + 'sci_business', # Business literature + 'sci_juris', # Jurisprudence + 'sci_linguistic', # Linguistics + 'sci_medicine', # Medicine + 'sci_phys', # Physics + 'sci_math', # Mathematics + 'sci_chem', # Chemistry + 'sci_biology', # Biology + 'sci_tech', # Technical + 'science', # Other + # Computers & Internet + 'comp_www', # Internet + 'comp_programming', # Programming + 'comp_hard', # Hardware + 'comp_soft', # Software + 'comp_db', # Databases + 'comp_osnet', # OS & Networking + 'computers', # Other + # Reference + 'ref_encyc', # Encyclopedias + 'ref_dict', # Dictionaries + 'ref_ref', # Reference + 'ref_guide', # Guidebooks + 'reference', # Other + # Nonfiction + 'nonf_biography', # Biography & Memoirs + 'nonf_publicism', # Publicism + 'nonf_criticism', # Criticism + 'design', # Art & design + 'nonfiction', # Other + # Religion & Inspiration + 'religion_rel', # Religion + 'religion_esoterics', # Esoterics + 'religion_self', # Self#improvement + 'religion', # Other + # Humor + 'humor_anecdote', # Anecdote (funny stories) + 'humor_prose', # Prose + 'humor_verse', # Verses + 'humor', # Other + # Home & Family + 'home_cooking', # Cooking + 'home_pets', # Pets + 'home_crafts', # Hobbies & Crafts + 'home_entertain', # Entertaining + 'home_health', # Health + 'home_garden', # Garden + 'home_diy', # Do it yourself + 'home_sport', # Sports + 'home_sex', # Erotica & sex + 'home', # Other + ] + options = set([ OptionRecommendation(name='sectionize', recommended_value='files', level=OptionRecommendation.LOW, @@ -25,6 +152,11 @@ class FB2Output(OutputFormatPlugin): 'A value of "Table of Contents" turns the entries in the Table of Contents into titles and creates sections; ' 'if it fails, adjust the "Structure Detection" and/or "Table of Contents" settings ' '(turn on "Force use of auto-generated Table of Contents).')), + OptionRecommendation(name='fb2_genre', + recommended_value='antique', level=OptionRecommendation.LOW, + choices=FB2_GENRES, + help=_('Genre for the book. Choices: %s\n\n See: ' % FB2_GENRES) + 'http://www.fictionbook.org/index.php/Eng:FictionBook_2.1_genres ' \ + + _('for a complete list with descriptions.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): diff --git a/src/calibre/gui2/convert/fb2_output.py b/src/calibre/gui2/convert/fb2_output.py index 66296ee666..19d0995fc1 100644 --- a/src/calibre/gui2/convert/fb2_output.py +++ b/src/calibre/gui2/convert/fb2_output.py @@ -17,8 +17,10 @@ class PluginWidget(Widget, Ui_Form): ICON = I('mimetypes/fb2.png') def __init__(self, parent, get_option, get_help, db=None, book_id=None): - Widget.__init__(self, parent, ['sectionize']) + Widget.__init__(self, parent, ['sectionize', 'fb2_genre']) self.db, self.book_id = db, book_id for x in ('toc', 'files', 'nothing'): self.opt_sectionize.addItem(x) + for x in get_option('fb2_genre').option.choices: + self.opt_fb2_genre.addItem(x) self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/fb2_output.ui b/src/calibre/gui2/convert/fb2_output.ui index 891aa29857..c8d4230a99 100644 --- a/src/calibre/gui2/convert/fb2_output.ui +++ b/src/calibre/gui2/convert/fb2_output.ui @@ -14,7 +14,7 @@ Form - + Qt::Vertical @@ -29,21 +29,31 @@ - - Sectionize: - - - opt_sectionize - - - - - - - 20 + + Sectionize: + + + opt_sectionize + + + + 20 + + + + + + + Genre + + + + + +