Top Level Namespace

Defined Under Namespace

Modules: Command, CommandLine, Helper, LoggerModule, Narou, WinAPI Classes: ConverterBase, Database, Device, Downloader, GlobalSetting, HTML, Illustration, Ini, Inspector, LocalSetting, Logger, LoggerError, Mailer, NovelConverter, NovelInfo, NovelSetting, ProgressBar, SectionStripper, SiteSetting, String, StripException, Template

Constant Summary collapse

Version =

Copyright 2013 whiteleaf. All rights reserved.

"1.5.7"
CommitVersion =
`git describe --always`.strip + "(develop)"
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



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

def converter(title, &block)
  $converter_container[title] = Class.new(ConverterBase, &block)
end

#error(str) ⇒ Object



91
92
93
# File 'lib/logger.rb', line 91

def error(str)
  warn "<red>[ERROR]</red> #{str}".termcolor
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



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

def load_converter(title, archive_path)
  converter_path = File.join(archive_path, "converter.rb")
  if File.exists?(converter_path)
    if Helper.os_windows?
      # TODO: RubyのバグでUTF-8なパスをrequireが見えてない。修正されたら消す
      unless $converter_load_once[archive_path]
        eval(File.read(converter_path, encoding: Encoding::UTF_8))
        $converter_load_once[archive_path] = true
      end
    else
      require converter_path
    end
  else
    return BlankConverter
  end
  conv = $converter_container[title]
  if conv
    return conv
  else
    error "converter.rbは見つかりましたが、`converter'で登録されていないようです。" +
          "変換処理は converter \"#{title.gsub('"', '\\"')}\" として登録する必要があります"
    return BlankConverter
  end
end

#original_warnObject Also known as: warn

github.com/termtter/termtter/blob/master/lib/termtter/system_extensions/windows.rb

(The MIT License)

Copyright © 2008-2012 The Termtter Development Team

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.



30
# File 'lib/color.rb', line 30

alias :original_warn :warn

#write_color(str, console = STDOUT) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/color.rb', line 69

def write_color(str, console = STDOUT)
  str.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
    case token
    when /\e\[(\d+)m/
      color = $1.to_i > 90 ? ($1.to_i % 60) : $1.to_i
      loop do
        error_code = WinAPI.SetConsoleTextAttribute $hStdOut, $colorMap[color].to_i
        if error_code == 0
          if WinAPI.GetLastError == 6
            $hStdOut = WinAPI.GetStdHandle(0xFFFFFFF5)
            redo
          end
        end
        break
      end
    when /\e\[\d*[a-zA-Z]/
      # do nothing
    else
      console.write token
    end
  end
  WinAPI.SetConsoleTextAttribute $hStdOut, $oldColor
end