Top Level Namespace

Defined Under Namespace

Modules: Command, CommandLine, FileUtils, Helper, Inventory, Narou, WinAPI Classes: ConverterBase, Database, Device, DiffViewer, Downloader, File, HTML, HotentryManager, Illustration, Ini, Inspector, Mailer, NovelConverter, NovelInfo, NovelSetting, ProgressBar, SectionStripper, SiteSetting, String, StripException, Template, WebSocket, WebSocketServer

Constant Summary collapse

KINDLESTRIP_VERSION =

! ruby -*- coding: utf-8 -*-

It was translated into Ruby script by whiteleaf.

original source code: kindlestrip.py v.1.35 www.mobileread.com/forums/showthread.php?t=96903

This script strips the penultimate record from a Mobipocket file. This is useful because the current KindleGen add a compressed copy of the source files used in this record, making the ebook produced about twice as big as it needs to be.

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <unlicense.org/>

Written by Paul Durrant, 2010-2011, [email protected], pdurrant on mobileread.com With enhancements by Kevin Hendricks, KevinH on mobileread.com

Changelog

1.00 - Initial version
1.10 - Added an option to output the stripped data
1.20 - Added check for source files section (thanks Piquan)
1.30 - Added prelim Support for K8 style mobis
1.31 - removed the SRCS section but kept a 0 size entry for it
1.32 - removes the SRCS section and its entry, now updates metadata 121 if needed
1.33 - now uses and modifies mobiheader SRCS and CNT
1.34 - added credit for Kevin Hendricks
1.35 - fixed bug when more than one compilation (SRCS/CMET) records
'1.35'
BlankConverter =
Class.new(ConverterBase) {}

Instance Method Summary collapse

Instance Method Details

#converter(title, &block) ⇒ Object



13
14
15
# File 'lib/loadconverter.rb', line 13

def converter(title, &block)
  $latest_converter = Class.new(ConverterBase, &block)
end

#error(str) ⇒ Object



287
288
289
# File 'lib/narou_logger.rb', line 287

def error(str)
  $stdout.error str
end

#load_converter(title, archive_path) ⇒ Object

小説固有コンバーターのロード

ファイル名は converter.rb 固定で、変換処理のフックを定義できる。 基本の変換処理の実行前にはbeforeメソッド、変換処理後にafterメソッドが呼ばれる。 このファイルを必ず用意する必要はない。 converter は ConverterBase を継承したクラスを生成するものである。 converter “タイトル” {} は class CONVERTER < ConverterBase; end にほぼ等しい。

デフォルトの動作は ConverterBase#before 及び ConverterBase#aftert に定義されている。 super を呼ばなければ基本動作を抑制出来る。

引数の io は StringIO のオブジェクトであり、ファイル先頭に seek(rewind) してあることが保証される。 また、返却する IO オブジェクトはファイル先頭に seek しておく必要はない。 text_type は渡されるテキストがタイトルなのか、前書きなのか等の種別を判断する文字列が渡される。 渡される文字列と意味:

story         あらすじ
chapter       章のタイトル
subtitle      節のタイトル
introduction  前書き
body          本文
postscript    後書き
textfile      テキストファイル形式で変換をしようとした場合

e.g.) converter “書籍のタイトル” do

# 共通変換処理の前に呼ばれる
def before(io, text_type)
  io.string.gsub!("\n\n", "\n")   # WEB小説に多い無駄な空改行を削除する
  io                              # 返り値もStringIOで
end

# 共通変換処理の後に呼ばれる
def after(io, text_type)
  buffer = StringIO.new
  io.each do |line|
    ~何らかの処理~(共通変換処理で漢数字化されたものを特定部分だけアラビア数字に戻したり)
    buffer.write ~~
  end
  buffer
end

end



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/loadconverter.rb', line 61

def load_converter(title, archive_path)
  converter_path = File.join(archive_path, "converter.rb")
  if File.exist?(converter_path)
    $latest_converter = nil
    eval(File.read(converter_path, mode: "r:BOM|UTF-8"), binding, converter_path)
  else
    return BlankConverter
  end

  conv = $latest_converter
  if conv
    return conv
  else
    title_for_converter = (title =~ /.txt\z/ ? title : File.basename(archive_path))
    error "converter.rbは見つかりましたが、`converter'で登録されていないようです。" +
          "変換処理は converter \"#{title_for_converter.gsub('"', '\\"')}\" として登録する必要があります"
    return BlankConverter
  end
end

#make_open_uri_options(add) ⇒ Object

open-uri に渡すオプションを生成(必要に応じて extensions/*.rb でオーバーライドする)



14
15
16
# File 'lib/extension.rb', line 14

def make_open_uri_options(add)
  add.merge(ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE)
end

#warn(str, trace = nil) ⇒ Object



282
283
284
285
# File 'lib/narou_logger.rb', line 282

def warn(str, trace = nil)
  $stdout.warn str
  $stdout.warn trace if trace
end

#write_color(str, console = STDOUT) ⇒ Object

Copyright 2013 whiteleaf. All rights reserved.



7
8
9
# File 'lib/color.rb', line 7

def write_color(str, console = STDOUT)
  console.write str
end