kamishibai 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/LICENSE +29 -0
  4. data/README.md +91 -0
  5. data/bin/kamishibai +59 -0
  6. data/changelogs.txt +6 -0
  7. data/images/reading.jpg +0 -0
  8. data/images/settings.jpg +0 -0
  9. data/images/view_browse.jpg +0 -0
  10. data/images/view_dir.jpg +0 -0
  11. data/kamishibai.gemspec +31 -0
  12. data/lib/kamishibai.rb +35 -0
  13. data/lib/kamishibai/book.rb +97 -0
  14. data/lib/kamishibai/config.rb +90 -0
  15. data/lib/kamishibai/database.rb +330 -0
  16. data/lib/kamishibai/functions.rb +332 -0
  17. data/lib/kamishibai/patches.rb +58 -0
  18. data/lib/kamishibai/version.rb +7 -0
  19. data/lib/kamishibai/webserver.rb +502 -0
  20. data/lib/kamishibai/webserver_cmds.rb +26 -0
  21. data/lib/kamishibai/webserver_config.rb +91 -0
  22. data/lib/kamishibai/webserver_filemanager.rb +29 -0
  23. data/lib/kamishibai/webserver_tablet.rb +259 -0
  24. data/lib/kamishibai/workers.rb +39 -0
  25. data/public/css/browse.css +390 -0
  26. data/public/css/config.css +3 -0
  27. data/public/css/reader.css +119 -0
  28. data/public/css/styles.css +30 -0
  29. data/public/css/tablet_browse.css +247 -0
  30. data/public/css/tablet_reader.css +323 -0
  31. data/public/css/tablet_reader_input.css +191 -0
  32. data/public/images/ajax-loader.gif +0 -0
  33. data/public/images/delete.png +0 -0
  34. data/public/images/folder-mini-up.png +0 -0
  35. data/public/images/folder-mini.png +0 -0
  36. data/public/images/spinner.gif +0 -0
  37. data/public/images/trash-empty-mini.png +0 -0
  38. data/public/images/trash-full-mini.png +0 -0
  39. data/public/js/browse.js +391 -0
  40. data/public/js/config.js +190 -0
  41. data/public/js/reader.js +497 -0
  42. data/public/js/swipeview-k.js +478 -0
  43. data/public/js/tablet3.js +241 -0
  44. data/public/js/tablet3_browse.js +173 -0
  45. data/public/js/tablet3_reader.js +534 -0
  46. data/public/js/utilities.js +170 -0
  47. data/public/lang/k-cn.json +82 -0
  48. data/public/lang/k-en.json +82 -0
  49. data/public/lang/k-ja.json +82 -0
  50. data/public/vendor/css/bootstrap-slider.css +252 -0
  51. data/public/vendor/css/bootstrap-theme.css +476 -0
  52. data/public/vendor/css/bootstrap-theme.css.map +1 -0
  53. data/public/vendor/css/bootstrap-theme.min.css +5 -0
  54. data/public/vendor/css/bootstrap.css +6584 -0
  55. data/public/vendor/css/bootstrap.css.map +1 -0
  56. data/public/vendor/css/bootstrap.min.css +5 -0
  57. data/public/vendor/css/jquery-ui-1.10.0.custom.css +1614 -0
  58. data/public/vendor/css/jquery.mobile-1.3.1.min.css +3 -0
  59. data/public/vendor/css/jqueryFileTree.css +91 -0
  60. data/public/vendor/fonts/glyphicons-halflings-regular.eot +0 -0
  61. data/public/vendor/fonts/glyphicons-halflings-regular.svg +288 -0
  62. data/public/vendor/fonts/glyphicons-halflings-regular.ttf +0 -0
  63. data/public/vendor/fonts/glyphicons-halflings-regular.woff +0 -0
  64. data/public/vendor/fonts/glyphicons-halflings-regular.woff2 +0 -0
  65. data/public/vendor/images/application.png +0 -0
  66. data/public/vendor/images/code.png +0 -0
  67. data/public/vendor/images/css.png +0 -0
  68. data/public/vendor/images/db.png +0 -0
  69. data/public/vendor/images/dim.png +0 -0
  70. data/public/vendor/images/directory.png +0 -0
  71. data/public/vendor/images/doc.png +0 -0
  72. data/public/vendor/images/file.png +0 -0
  73. data/public/vendor/images/film.png +0 -0
  74. data/public/vendor/images/flash.png +0 -0
  75. data/public/vendor/images/folder_open.png +0 -0
  76. data/public/vendor/images/grey.png +0 -0
  77. data/public/vendor/images/html.png +0 -0
  78. data/public/vendor/images/icons-18-black.png +0 -0
  79. data/public/vendor/images/icons-18-white.png +0 -0
  80. data/public/vendor/images/icons-36-black.png +0 -0
  81. data/public/vendor/images/icons-36-white.png +0 -0
  82. data/public/vendor/images/java.png +0 -0
  83. data/public/vendor/images/linux.png +0 -0
  84. data/public/vendor/images/music.png +0 -0
  85. data/public/vendor/images/pdf.png +0 -0
  86. data/public/vendor/images/php.png +0 -0
  87. data/public/vendor/images/picture.png +0 -0
  88. data/public/vendor/images/ppt.png +0 -0
  89. data/public/vendor/images/psd.png +0 -0
  90. data/public/vendor/images/ruby.png +0 -0
  91. data/public/vendor/images/script.png +0 -0
  92. data/public/vendor/images/spinner.gif +0 -0
  93. data/public/vendor/images/txt.png +0 -0
  94. data/public/vendor/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  95. data/public/vendor/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  96. data/public/vendor/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  97. data/public/vendor/images/ui-bg_flat_10_000000_40x100.png +0 -0
  98. data/public/vendor/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
  99. data/public/vendor/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
  100. data/public/vendor/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
  101. data/public/vendor/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  102. data/public/vendor/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  103. data/public/vendor/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  104. data/public/vendor/images/ui-bg_glass_20_555555_1x400.png +0 -0
  105. data/public/vendor/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
  106. data/public/vendor/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
  107. data/public/vendor/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  108. data/public/vendor/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  109. data/public/vendor/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  110. data/public/vendor/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  111. data/public/vendor/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  112. data/public/vendor/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  113. data/public/vendor/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  114. data/public/vendor/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
  115. data/public/vendor/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  116. data/public/vendor/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  117. data/public/vendor/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  118. data/public/vendor/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  119. data/public/vendor/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  120. data/public/vendor/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
  121. data/public/vendor/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  122. data/public/vendor/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  123. data/public/vendor/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
  124. data/public/vendor/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
  125. data/public/vendor/images/ui-icons_217bc0_256x240.png +0 -0
  126. data/public/vendor/images/ui-icons_222222_256x240.png +0 -0
  127. data/public/vendor/images/ui-icons_228ef1_256x240.png +0 -0
  128. data/public/vendor/images/ui-icons_2e83ff_256x240.png +0 -0
  129. data/public/vendor/images/ui-icons_454545_256x240.png +0 -0
  130. data/public/vendor/images/ui-icons_469bdd_256x240.png +0 -0
  131. data/public/vendor/images/ui-icons_4b8e0b_256x240.png +0 -0
  132. data/public/vendor/images/ui-icons_6da8d5_256x240.png +0 -0
  133. data/public/vendor/images/ui-icons_888888_256x240.png +0 -0
  134. data/public/vendor/images/ui-icons_a83300_256x240.png +0 -0
  135. data/public/vendor/images/ui-icons_cccccc_256x240.png +0 -0
  136. data/public/vendor/images/ui-icons_cd0a0a_256x240.png +0 -0
  137. data/public/vendor/images/ui-icons_d8e7f3_256x240.png +0 -0
  138. data/public/vendor/images/ui-icons_ef8c08_256x240.png +0 -0
  139. data/public/vendor/images/ui-icons_f9bd01_256x240.png +0 -0
  140. data/public/vendor/images/ui-icons_ffd27a_256x240.png +0 -0
  141. data/public/vendor/images/ui-icons_ffffff_256x240.png +0 -0
  142. data/public/vendor/images/xls.png +0 -0
  143. data/public/vendor/images/zip.png +0 -0
  144. data/public/vendor/js/bootstrap-slider.js +1550 -0
  145. data/public/vendor/js/bootstrap.js +2317 -0
  146. data/public/vendor/js/bootstrap.min.js +7 -0
  147. data/public/vendor/js/jquery-2.1.4.js +9210 -0
  148. data/public/vendor/js/jquery-2.1.4.min.js +4 -0
  149. data/public/vendor/js/jquery-2.1.4.min.map +1 -0
  150. data/public/vendor/js/jquery-ui-1.10.2.custom.min.js +7 -0
  151. data/public/vendor/js/jquery.cookie.js +72 -0
  152. data/public/vendor/js/jquery.hammer.min.js +7 -0
  153. data/public/vendor/js/jquery.lazyload.min.js +15 -0
  154. data/public/vendor/js/jquery.localize.js +180 -0
  155. data/public/vendor/js/jquery.mobile-1.3.1.min.js +7 -0
  156. data/public/vendor/js/jquery.scrollTo-1.4.3.1.js +218 -0
  157. data/public/vendor/js/jqueryFileTree.js +95 -0
  158. data/public/vendor/js/swipeview.js +471 -0
  159. data/views/browse.haml +97 -0
  160. data/views/config.haml +115 -0
  161. data/views/layout.haml +12 -0
  162. data/views/login.haml +51 -0
  163. data/views/reader.haml +70 -0
  164. data/views/statistics.haml +108 -0
  165. data/views/tablet3.haml +80 -0
  166. metadata +334 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 989fed21e0f1b3aa868e8d7e3ddb847764941731
4
+ data.tar.gz: 9a5df75a8f7c271101ae73e96182dca1cdd7b6c8
5
+ SHA512:
6
+ metadata.gz: 76e19f834f866ee87a3ff77f94779a3042ff159311b10a787470a805faf56c0898b33605a9cf9b07648ec9852d255d3fb4d2a9ea5628ee2d8aa45e61523c5035
7
+ data.tar.gz: 222aa7bc8838901953ef419fc68876580a7721db6dc0f95973a0bf0a4d90297919d15d0d69cb8f76d7966ad7c3b87f8a4244c78a8e66d244758a798bdd3dd025
@@ -0,0 +1 @@
1
+ .idea/*
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2013,
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,91 @@
1
+ Kamishibai
2
+ =========================
3
+ > pronounce kami-shi-bye
4
+
5
+ Remote manga reader. Read manga anywhere using a web browser.
6
+
7
+ It remember where the manga is read upto, so you can resume reading with ease.
8
+
9
+ Support basic tagging in filenaming, please read file naming convention below.
10
+
11
+ Settings can change image quality to conserve bandwidth.
12
+
13
+ Zipped (CBZ) books are supported.
14
+
15
+ Screenshots:
16
+ --------------------------
17
+ Directory view
18
+ ![Directory view](/images/view_browse.jpg)
19
+
20
+ Tablet Browse view
21
+ ![Tablet Browse view](/images/view_browse.jpg)
22
+
23
+ Reading
24
+ ![Reading](/images/reading.jpg)
25
+
26
+ Settings
27
+ ![Settings](/images/settings.jpg)
28
+
29
+ Update:
30
+ --------------------------
31
+ Didn't touch the code for years, had a quick touchup to make sure it works. Found lots of old/bad code, but that was written in 2013, so please don't judge too harshly.
32
+
33
+ Installation:
34
+ --------------------------
35
+ gem install kamishibai
36
+
37
+
38
+ Installation (extra info):
39
+ --------------------------
40
+
41
+ Mac OS X:
42
+ 1. Install [MacPorts](http://www.macports.org/)
43
+ 2. sudo port install ruby25 rb-rubygems gd2
44
+ 3. sudo gem install kamishibai
45
+
46
+ Linux (Ubuntu/Debian):
47
+ 1. sudo apt-get install ruby ruby-dev
48
+ 2. sudo gem install kamishibai
49
+
50
+ Windows:
51
+ 1. Install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
52
+ 2. Choose Ubuntu install
53
+ 2. Follow instruction for Linux above
54
+
55
+ Access:
56
+ --------------------------
57
+ Run program kamishibai
58
+ Open browser and type http://127.0.0.1:9999
59
+ Default username and password is admin/admin, please change it for security purpose.
60
+
61
+ Configuration:
62
+ --------------------------
63
+ Config file is written in JSON format. The config file will be located at ~/etc/kamishibai.conf. The config file can also manually selected by appending the config path after the program.
64
+
65
+ There is also web configuration panel, goto http://host_ip:host_port/config to configure.
66
+
67
+
68
+
69
+ Start:
70
+ --------------------------
71
+ kamishibai [config_file.conf]
72
+
73
+ File Format:
74
+ --------------------------
75
+ Only CBZ is supported and it should be zero compressed zip file. This will reduce the burden on the system when reading as well as making the experience more responsive. The file name will determind how it will be organized by the program.
76
+
77
+ File naming convention:
78
+ --------------------------
79
+ Ideally, the CBZ file name should be in such format.
80
+
81
+ (genre|meta data) [Author] Book Title Volume|chapter|v|ch 1.
82
+
83
+ For example
84
+ (Manga) [Yamada Taro] World of Sakura Volume 01.cbz
85
+ (一般コミック) [山田太郎] 桜の世界 第01巻.cbz
86
+
87
+
88
+ License:
89
+ --------------------------
90
+ BSD 3-clause
91
+ Mac Ma gitmac at runbox.com (C) 2013-2018 Copyright
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # License: refer to LICENSE file
5
+
6
+ # making sure program runs in UTF-8 encoding in any environment
7
+ Encoding.default_external = Encoding::UTF_8
8
+ Encoding.default_internal = Encoding::UTF_8
9
+
10
+ require 'rbconfig'
11
+ require 'getoptlong'
12
+ require 'json/ext' # load early to use good quality json library instead of crappy one
13
+
14
+ opts = GetoptLong.new(
15
+ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
16
+ )
17
+
18
+ $debug = false
19
+ opts.each do |opt, arg|
20
+ if opt == '--debug'
21
+ $debug = true
22
+ end
23
+ end
24
+ $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
25
+
26
+
27
+
28
+
29
+ require 'kamishibai/config'
30
+
31
+ # load config file, auto create if it doesn't exists
32
+ if ARGV[0]
33
+ $settings = Kamishibai::Config.new( ARGV[0] )
34
+ else
35
+ $settings = Kamishibai::Config.new
36
+ end
37
+
38
+
39
+
40
+ require 'kamishibai'
41
+
42
+ # flag to restart the webserver if shutdown
43
+ $RERUN = false
44
+
45
+ at_exit do
46
+ if $RERUN
47
+ puts 'restarting...'
48
+ opt_d = $debug ? '--debug' : ''
49
+
50
+ if RbConfig::CONFIG['host_os'] =~ /ming/
51
+ exe = "ruby #{__FILE__}"
52
+ else
53
+ exe = __FILE__
54
+ end
55
+ `#{exe} #{opt_d} "#{$KAMISHIBAI_CONFIG_PATH}"`
56
+ end
57
+ end
58
+
59
+ Kamishibai::Webserver.run!
@@ -0,0 +1,6 @@
1
+ Change log:
2
+
3
+ 0.6.2
4
+ Updated year for copyright
5
+ Update documentation
6
+ Add screenshots
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../lib/kamishibai/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'kamishibai'
7
+ s.version = Kamishibai::VERSION
8
+ s.description = "Remote manga reader. Read manga anywhere using a web browser."
9
+ s.summary = s.description
10
+ s.authors = ["Mac Ma"]
11
+ s.email = 'gitmac@etneko.info'
12
+ s.homepage = 'http://rubygems.org/gems/kamishibai'
13
+ s.license = 'BSD 3-clause'
14
+
15
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
16
+ s.rubyforge_project = 'kamishibai'
17
+
18
+ s.add_dependency 'addressable', '>= 2.3.5'
19
+ s.add_dependency 'haml', '>= 4.0.3'
20
+ s.add_dependency 'thin', '>= 1.6.0'
21
+ s.add_dependency 'ffi', '>= 1.9.0'
22
+ s.add_dependency 'gd2-ffij', '>= 0.1.1'
23
+ s.add_dependency 'json', '>= 1.7.7'
24
+ s.add_dependency 'rubyzip', '>= 1.0.0'
25
+ s.add_dependency 'sinatra', '>= 1.4.4'
26
+ s.add_dependency 'sinatra-reloader', '>= 1.0'
27
+
28
+ s.require_paths = ['lib']
29
+ s.files = `git ls-files`.split($\)
30
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
31
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ # License: refer to LICENSE file
4
+
5
+ require 'kamishibai/book'
6
+ require 'kamishibai/functions'
7
+ require 'kamishibai/database'
8
+ require 'kamishibai/webserver'
9
+ require 'kamishibai/workers'
10
+ require 'kamishibai/patches'
11
+
12
+
13
+ if $settings.srcs.length <= 0
14
+ puts "No directory source loaded, please configure at (user/pass is user/pass) http://127.0.0.1:#{$settings.port}/config"
15
+ end
16
+
17
+ # function for initialize database
18
+ def init_database(extra_dirs=[])
19
+ puts 'initializing database... this may take some time to run on first time...'
20
+
21
+ # load or create new db
22
+ $db = Kamishibai::Database.new( $settings.db_path, $settings.bookmarks_path )
23
+
24
+ # add new files to db
25
+ $db.add_books( $settings.srcs )
26
+ end
27
+
28
+ # initialize whole database and bookmarks
29
+ init_database
30
+
31
+ # worker thread for saving bookmarks
32
+ start_auto_save
33
+
34
+ # worker thread for generating thumbnails
35
+ start_auto_gen_thumbnail
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ # License: refer to LICENSE file
4
+
5
+ # book class
6
+ module Kamishibai
7
+ module CBZFilename
8
+ def self.author(s)
9
+ parse(s)[0]
10
+ end
11
+
12
+ def self.title(s)
13
+ parse(s)[1]
14
+ end
15
+
16
+ def self.parse(s)
17
+ s = File.basename(s)
18
+ s.gsub!(/_/,' ')
19
+ s.gsub!(/ /u,' ')
20
+ s.gsub!(/\(.+?\)/,'')
21
+ author = s.scan(/\[(.+?)\]/)[0][0] if s.scan(/\[(.+?)\]/)[0] and s.scan(/\[(.+?)\]/)[0][0]
22
+ s.gsub!(/\[.+?\]/,'')
23
+ #s.gsub!(/ \S\d+.*/,'')
24
+ s.gsub!(/ \d{4}\S[\d\.]+.+/,'')
25
+ s.gsub!(/ (v|c|第)[\d\.]+.*/iu,'')
26
+ s.gsub!(/ vol.{0,2}[\d\.]+.*/i,'')
27
+ s.gsub!(/ (上|中|下)\.cbz/iu,'.cbz')
28
+ s.gsub!(/ \#[\d\.]+.*/i,'')
29
+ s.gsub!(/ ch.{0,2}[\d\.]+.*/i,'')
30
+ s.gsub!(/ +/,' ')
31
+ s.gsub!(/^ /,'')
32
+ s.gsub!(/\.cbz$/,'')
33
+ s.gsub!(/ $/,'')
34
+ s.gsub!(/ [\d\.]+$/,'')
35
+ title = s
36
+
37
+ [author, title]
38
+ end
39
+
40
+ private_class_method :parse
41
+ end
42
+
43
+ class Book
44
+ attr_reader :bookcode, :title, :author, :fullpath, :mtime, :itime, :rtime, :size, :inode, :page, :pages, :fullpath_valid
45
+ attr_writer :bookcode, :title, :author, :mtime, :itime, :rtime, :size, :inode, :page, :pages, :fullpath_valid
46
+
47
+ def initialize(bookcode=nil, fullpath=nil)
48
+ if bookcode and fullpath
49
+ @bookcode = bookcode
50
+ @fullpath = fullpath
51
+ if File.exists?( fullpath )
52
+ fs = File.stat( fullpath )
53
+ @mtime = fs.mtime.to_i
54
+
55
+ # mark the path as valid, aka book exists in path
56
+ @fullpath_valid = true
57
+ end
58
+
59
+ # create book title
60
+ title = File.basename( fullpath )
61
+ title.gsub!(/_/,' ')
62
+ title.gsub!(/ /u,' ')
63
+ title.gsub!(/\(.+?\)/,'')
64
+ @author = title.scan(/\[(.+?)\]/)[0][0] if title.scan(/\[(.+?)\]/)[0] and title.scan(/\[(.+?)\]/)[0][0]
65
+ title.gsub!(/\[.+?\]/,'')
66
+ #title.gsub!(/ \S\d+.*/,'')
67
+ title.gsub!(/ \d{4}\S[\d\.]+.+/,'')
68
+ title.gsub!(/ (v|c|第)[\d\.]+.*/iu,'')
69
+ title.gsub!(/ vol.{0,2}[\d\.]+.*/i,'')
70
+ title.gsub!(/ (上|中|下)\.cbz/iu,'.cbz')
71
+ title.gsub!(/ \#[\d\.]+.*/i,'')
72
+ title.gsub!(/ ch.{0,2}[\d\.]+.*/i,'')
73
+ title.gsub!(/ +/,' ')
74
+ title.gsub!(/^ /,'')
75
+ title.gsub!(/\.cbz$/,'')
76
+ title.gsub!(/ $/,'')
77
+ title.gsub!(/ [\d\.]+$/,'')
78
+ @title = title
79
+
80
+ @itime = Time.now.to_i
81
+ @pages = cbz_pages?( @fullpath )
82
+
83
+ unless @pages
84
+ puts "Book contain no images! #{fullpath}"
85
+ end
86
+ end
87
+ end
88
+
89
+ def fullpath=(newfullpath)
90
+ @fullpath = newfullpath
91
+
92
+ if File.exists?(newfullpath)
93
+ @fullpath_valid = true
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ # License: refer to LICENSE file
4
+
5
+ require 'json'
6
+
7
+ #
8
+ # Handle global Kamishibal configuration
9
+ #
10
+ module Kamishibai
11
+ class Config
12
+ attr_reader :config_path, :srcs, :image_resize, :default_image_quality, :username, :password, :bind, :port, :db_path, :bookmarks_path, :cache_path, :new_book_days
13
+ attr_writer :config_path, :srcs, :image_resize, :default_image_quality, :username, :password, :bind, :port, :db_path, :bookmarks_path, :cache_path, :new_book_days
14
+
15
+ def initialize( path = '~/etc/kamishibai.conf' )
16
+ @config_path = File.expand_path( path )
17
+
18
+ if File.exists?( @config_path )
19
+ load
20
+ else
21
+ # settings template
22
+ @srcs = []
23
+ @image_resize = true
24
+ @default_image_quality = 60
25
+ @username = 'admin'
26
+ @password = 'admin'
27
+ @bind = '0.0.0.0'
28
+ @port = 9999
29
+
30
+ @db_path = '~/var/kamishibai/db.json'
31
+ @bookmarks_path = '~/var/kamishibai/bookmarks.json'
32
+ @cache_path = '~/var/kamishibai/cache/'
33
+
34
+ @new_book_days = 7
35
+
36
+ save_config
37
+ end
38
+ end
39
+
40
+ def save
41
+ unless FileTest.exists?( File.dirname( @config_path ) )
42
+ FileUtils.mkdir_p( File.dirname( @config_path ) )
43
+ end
44
+
45
+ t = {}
46
+ t[:srcs] = @srcs.collect { |src| File.expand_path(src) }
47
+ t[:image_resize] = @image_resize
48
+ t[:default_image_quality] = @default_image_quality
49
+ t[:username] = @username
50
+ t[:password] = @password
51
+ t[:bind] = @bind
52
+ t[:port] = @port
53
+
54
+ t[:db_path] = File.expand_path( @db_path )
55
+ t[:bookmarks_path] = File.expand_path( @bookmarks_path )
56
+ t[:cache_path] = File.expand_path( @cache_path )
57
+
58
+ t[:new_book_days] = @new_book_days
59
+
60
+ File.binwrite( @config_path, JSON.pretty_generate( t ) )
61
+
62
+ puts "config created at #{@config_path}" if $debug
63
+ end
64
+
65
+ alias_method :save_config, :save
66
+
67
+ private
68
+
69
+ # load settings from json config file
70
+ def load
71
+ json = JSON.parse( File.binread( @config_path ) )
72
+
73
+ @srcs = json['srcs'].collect { |src| File.expand_path(src) }
74
+ @image_resize = json['image_resize']
75
+ @default_image_quality = json['default_image_quality']
76
+ @username = json['username']
77
+ @password = json['password']
78
+ @bind = json['bind']
79
+ @port = json['port']
80
+
81
+ @db_path = File.expand_path( json['db_path'] )
82
+ @bookmarks_path = File.expand_path( json['bookmarks_path'] )
83
+ @cache_path = File.expand_path( json['cache_path'] )
84
+
85
+ @new_book_days = json['new_book_days']
86
+
87
+ puts "config loaded at #{@config_path}" if $debug
88
+ end
89
+ end
90
+ end