pig-media-server 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/bin/pig-media-server +4 -0
  8. data/lib/pig-media-server.rb +10 -0
  9. data/lib/pig-media-server/book2.erb +59 -0
  10. data/lib/pig-media-server/cli.rb +21 -0
  11. data/lib/pig-media-server/crawl.rb +23 -0
  12. data/lib/pig-media-server/model/comic.rb +64 -0
  13. data/lib/pig-media-server/model/migrate.rb +26 -0
  14. data/lib/pig-media-server/model/pig.rb +98 -0
  15. data/lib/pig-media-server/script.rb +4 -0
  16. data/lib/pig-media-server/version.rb +3 -0
  17. data/lib/pig-media-server/views/_ft_other.haml +0 -0
  18. data/lib/pig-media-server/views/_ft_read.haml +9 -0
  19. data/lib/pig-media-server/views/_ft_txt.haml +1 -0
  20. data/lib/pig-media-server/views/_ft_video.haml +6 -0
  21. data/lib/pig-media-server/views/_link.haml +14 -0
  22. data/lib/pig-media-server/views/_new_flag.haml +4 -0
  23. data/lib/pig-media-server/views/app.scss +85 -0
  24. data/lib/pig-media-server/views/book.coffee +236 -0
  25. data/lib/pig-media-server/views/book2.erb +59 -0
  26. data/lib/pig-media-server/views/config.coffee +8 -0
  27. data/lib/pig-media-server/views/config.haml +29 -0
  28. data/lib/pig-media-server/views/index.haml +45 -0
  29. data/lib/pig-media-server/views/movie.coffee +159 -0
  30. data/lib/pig-media-server/views/read.haml +34 -0
  31. data/lib/pig-media-server/views/remote.coffee +25 -0
  32. data/lib/pig-media-server/views/remote.haml +14 -0
  33. data/lib/pig-media-server/views/session.coffee +6 -0
  34. data/lib/pig-media-server/views/sessions.haml +11 -0
  35. data/lib/pig-media-server/views/storage.coffee +32 -0
  36. data/lib/pig-media-server/views/swipe.erb +433 -0
  37. data/lib/pig-media-server/views/unread.coffee +14 -0
  38. data/lib/pig-media-server/web.rb +201 -0
  39. data/pig-media-server.gemspec +32 -0
  40. metadata +250 -0
@@ -0,0 +1,14 @@
1
+ %span.main_span{id: l.key}
2
+ !=partial :"_new_flag", locals: {record: l}
3
+ %a.main_link{key: l.key, href: l.url}=h(l.name)
4
+ !=partial :"_ft_#{l.type}", locals: {record: l}
5
+ %span.mtime=l.mtime.to_s.sub(/\ \+0900$/, '')
6
+ %span.size=number_to_human_size(l.size).encode('UTF-8', 'UTF-8')
7
+ %a.meta{href: "/meta/#{l.key}"} Meta
8
+ -if l.srt
9
+ %a.sub.meta{href: "/sub/#{l.key}"} Sub
10
+ -if l.type == 'txt' or l.type == 'read'
11
+ %a.ao.meta{href: "/ao/#{l.key}"} Aozora
12
+ %a.delete{href: 'javascript:void(0)', onclick: "var ok=confirm('Really?'); if (ok) location.href='/delete/#{l.key}?href=#{CGI.escape request.url}'; return false;"} Delete
13
+ %br
14
+
@@ -0,0 +1,4 @@
1
+ -if record.type == 'video'
2
+ %span.new_flag{key: "movie/#{record.record._key}", style: 'color:lime; font-size:large'}
3
+ -elsif record.type == 'read'
4
+ =''
@@ -0,0 +1,85 @@
1
+ body {
2
+ text-align:center;
3
+ background:black;
4
+ color:white;
5
+ }
6
+ #all, .all{
7
+ max-width:860px;
8
+ margin-left:auto;
9
+ margin-right:auto;
10
+ text-align:left;
11
+ }
12
+
13
+ #notice{ color:green; }
14
+ #error{ color:red; }
15
+ .small{ font-size:small;}
16
+
17
+ img{ max-width:100%; }
18
+
19
+ .lightgray{color:lightgray}
20
+
21
+ .none{display:none}
22
+ a{color:white}
23
+ .h1{font-size:7em}
24
+ .h2{font-size:3em}
25
+ .right{float:right}
26
+ .left{float:left}
27
+ .clear{clear:both}
28
+ nick{color:lightpink}
29
+ .mine{color:yellow}
30
+ .x-small{font-size:x-small}
31
+ span.link{font-size:x-large}
32
+
33
+ a.watch, a.read, a.txt, a.recent, a.kindle{
34
+ color:mistyrose;
35
+ }
36
+
37
+ a.meta{
38
+ color:lightgrey;
39
+ font-size:small;
40
+ }
41
+
42
+ .page{color:lightblue}
43
+
44
+ .mtime, .size{
45
+ font-size:small;color:lightgrey
46
+ }
47
+
48
+ .center{text-align:center;}
49
+ .none{display:none}
50
+
51
+ .control p span{font-size: 3em}
52
+ p.title{font-size: normal}
53
+
54
+ img.cache{height:1px; width:1px}
55
+ #control{height:200px;}
56
+
57
+ a.delete{
58
+ color:indianred;
59
+ font-size:small;
60
+ }
61
+
62
+ #all {
63
+ width:90% !important;
64
+ max-width:none !important;
65
+ margin:auto !important;
66
+ }
67
+ .main_span {
68
+ position:relative !important;
69
+ display:block !important;
70
+ margin:0 !important;
71
+ padding:5px 0 !important;
72
+ border-bottom:1px solid #666 !important;
73
+ }
74
+
75
+ .new_flag {
76
+ position:absolute !important;
77
+ display:inline-block !important;
78
+ width:3em !important;
79
+ text-align:center !important;
80
+ font-size:100% !important;
81
+ }
82
+ .main_link {
83
+ margin-left:3em;
84
+ text-decoration:none !important;
85
+ }
@@ -0,0 +1,236 @@
1
+ ## coffee -csb
2
+ portlait_db = {}
3
+ this.mobile = ->
4
+ true
5
+
6
+ this.mobile = ->
7
+ user_agent = navigator.userAgent
8
+ user_agent.indexOf('iPhone') > -1 or user_agent.indexOf('iPad') > -1 or user_agent.indexOf('MSIE') > -1
9
+
10
+ max_page = ->
11
+ parseInt($("#max_page").text())-1
12
+
13
+ left = ->
14
+ if is_left()
15
+ prev()
16
+ else
17
+ next()
18
+ right = ->
19
+ if is_left()
20
+ next()
21
+ else
22
+ prev()
23
+ plus1 = ->
24
+ open_page(now()+1)
25
+ next = ->
26
+ if is_portlait() and $("#area2 img").attr("class") == "portlait"
27
+ open_page(now()+2)
28
+ else
29
+ open_page(now()+1)
30
+ prev = ->
31
+ if is_portlait() and $("#area2 img").attr("class") == "portlait"
32
+ open_page(now()-2)
33
+ else
34
+ open_page(now()-1)
35
+
36
+ remover= (i)->
37
+ if i >= 0
38
+ $('#page_area_'+(i)).remove()
39
+ remover(i-1)
40
+ open_page = (page)->
41
+ page = 1 if is_NaN(page) or page < 1
42
+
43
+ try
44
+ recents = JSON.parse window.localStorage['recents']
45
+ catch error
46
+ recents = {}
47
+ delete recents['aozora/'+_id()]
48
+ recents['read/'+_id()] = {page: page, time: parseInt((new Date)/1000), type: 'read'}
49
+ window.localStorage['recents'] = JSON.stringify recents
50
+
51
+ if $('#action').text() == 'read'
52
+ $("#page_jump").val(page)
53
+ if page > max_page()
54
+ page = max_page()
55
+ _now(page)
56
+ remover(page-1)
57
+ for i in [0,1,2,3,4,5,6,7]
58
+ unless document.querySelector('#page_area_'+(page+i))
59
+ landscape(page+i) unless is_portlait()
60
+ portlait(page+i) if is_portlait()
61
+
62
+ img_style = (mode)->
63
+ if mode == "portlait"
64
+ "max-height:"+(height()-5)+"px; max-width:"+((width()/2)-10)+"px"
65
+ else
66
+ "max-height:"+(height()-5)+"px; max-width:"+(width()-10)+"px"
67
+
68
+
69
+ landscape = (page)->
70
+ $("#area2").html("<div id='page_insert'/>")
71
+ img = "<img src='/book/image?id="+_id()+"&page="+page+"' class='landscape' style='"+img_style("")+"'/>"
72
+ $("#page_insert").after(img)
73
+ $("#area2 img").click(-> next())
74
+
75
+ portlait = (page)->
76
+ if localStorage["portlait/"+_id()+"/"+page] != undefined and localStorage["portlait/"+_id()+"/"+(page+1)] != undefined
77
+ portlait_real(page)
78
+ else
79
+ $.get("/book/info/"+_id()+"?page="+page).success((data)->
80
+ localStorage["portlait/"+_id()+"/"+(page)] = data.portlait
81
+ $.get("/book/info/"+_id()+"?page="+(page+1)).success((data)->
82
+ localStorage["portlait/"+_id()+"/"+(page+1)] = data.portlait
83
+ portlait_real(page)
84
+ )
85
+ )
86
+
87
+ portlait_real = (page) ->
88
+ if localStorage["portlait/"+_id()+"/"+page] == 'true' or localStorage["portlait/"+_id()+"/"+(page+1)] == 'true'
89
+ img = "<img src='/book/image?id="+_id()+"&page="+page+"' class='landscape' style='"+img_style("")+"'/>"
90
+ else
91
+ if is_left()
92
+ img = "<img src='/book/image?id="+_id()+"&page="+page+"' class='portlait' style='"+img_style("portlait")+"'/>"
93
+ img += "<img src='/book/image?id="+_id()+"&page="+(page+1)+"' class='portlait' style='"+img_style("portlait")+"'/>"
94
+ else
95
+ img = "<img src='/book/image?id="+_id()+"&page="+(page+1)+"' class='portlait' style='"+img_style("portlait")+"'/>"
96
+ img += "<img src='/book/image?id="+_id()+"&page="+page+"' class='portlait' style='"+img_style("portlait")+"'/>"
97
+
98
+ $('#area2').height(height()-5)
99
+ img = $('<div class="img_area" id="page_area_'+page+'">'+img+'</div>')
100
+ img.css {'z-index': 100000000-page, position: 'absolute'}
101
+ $("#page_insert").after(img)
102
+
103
+
104
+ size_loop = (size)->
105
+ setTimeout ->
106
+ unless size == undefined or window_size() == undefined
107
+ if size.width != window_size().width or size.height != window_size().height
108
+ size = window_size()
109
+ $('.portlait').attr 'style', img_style('portlait')
110
+ $('.landscape').attr 'style', img_style('landscape')
111
+ $('#area').height(height()-5)
112
+ size_loop(size)
113
+ ,500
114
+
115
+ area_width_loop = (size) ->
116
+ setTimeout ->
117
+ unless document.querySelector('.img_area')
118
+ area_width_loop(0)
119
+ else
120
+ count = $('.img_area').last().width()
121
+ count = ($('#area2').width()-count)/2
122
+ if size != count
123
+ $('.img_area').css('left', count)
124
+ area_width_loop(count)
125
+ else
126
+ $('.img_area').css('left', size)
127
+ area_width_loop(size)
128
+ , 100
129
+
130
+ portlait_loop = (i)->
131
+ $.get("/book/info/#{_id()}", all: true).success((data)->
132
+ for n in data
133
+ localStorage["portlait/#{_id()}/#{i}"] = n
134
+ i += 1
135
+ )
136
+
137
+ change_bound = ->
138
+ $.get("/page/change_bound/"+_id()).success(->
139
+ if is_left()
140
+ $("#is_left").text("")
141
+ open_page(now())
142
+ else
143
+ $("#is_left").text("true")
144
+ open_page(now())
145
+ if is_left()
146
+ $("#bound").text("Left Side")
147
+ else
148
+ $("#bound").text("Right Side")
149
+ )
150
+
151
+ swipe_left = ->
152
+ right()
153
+ swipe_right = ->
154
+ left()
155
+
156
+ read = (link)->
157
+ key = link.getAttribute 'key'
158
+ $(link).click ->
159
+ $('#area').html('')
160
+ $('#area').css 'min-height', 0
161
+ $.get('/read/'+key).success((data)->
162
+ c = $('<a>close book</a>')
163
+ c.attr('href', 'javascript:void(0)')
164
+ c.click ->
165
+ $('#area').html('')
166
+ $('#area').css 'min-height', 0
167
+ $(data).appendTo('#area')
168
+ c.appendTo('#area')
169
+ $('body').animate(0)
170
+ if is_left()
171
+ $("#bound").text("Left Side")
172
+ else
173
+ $("#bound").text("Right Side")
174
+ $("#bound").click(-> change_bound())
175
+ size = window_size()
176
+ open_page(parseInt $("#page_initial").text())
177
+ size_loop(window_size())
178
+ area_width_loop(0)
179
+ $("#left").click(-> left())
180
+ $("#right").click(-> right())
181
+ $("#plus1").click(-> plus1())
182
+ $('#area2').css('-ms-touch-action': 'none', '-ms-user-select': 'none')
183
+ if window.navigator.msPointerEnabled
184
+ area_pointer = {x: 0, y: 0}
185
+ $('#area2').get(0).addEventListener('MSPointerDown', (e)->
186
+ area_pointer.x = e.clientX
187
+ area_pointer.y = e.clientY
188
+ )
189
+ $('#area2').get(0).addEventListener('MSPointerUp', (e)->
190
+ if area_pointer.y - e.clientY < 300
191
+ if area_pointer.x - e.clientX > 50
192
+ swipe_left()
193
+ if e.clientX - area_pointer.x > 50
194
+ swipe_right()
195
+
196
+ area_pointer.x = 0
197
+ area_pointer.y = 0
198
+ )
199
+ else
200
+ $("#area2").swipe({swipeLeft:swipe_left, swipeRight:swipe_right, threshold:0})
201
+
202
+ $('#area2').click -> next() #unless window.navigator.msPointerEnabled
203
+ $("#book_list").off()
204
+ $("#book_list").click -> open_index()
205
+ $("#jump").click ->
206
+ open_page(parseInt($("#page_jump").val()))
207
+ $("#to_aozora").click ->
208
+ id = $('#id').text()
209
+ $.get('/aozora/'+id+"?remote=remote").success (data)->
210
+ $('#area2').html data
211
+ $('.control').html ''
212
+ initialize_aozora()
213
+ portlait_loop(1)
214
+ ).error(-> alert('you cannot this book'))
215
+
216
+ key_queue = []
217
+
218
+ key_loop = ->
219
+ setTimeout ->
220
+ if key_queue.length > 0
221
+ key = key_queue.shift()
222
+ if $("#action").text() == "read"
223
+ if key == 74
224
+ next()
225
+ else if key == 75
226
+ prev()
227
+ key_loop()
228
+ ,50
229
+
230
+ initialize_read = ->
231
+ $.each $('a.read'), -> read(this)
232
+ $ ->
233
+ initialize_read()
234
+ $(document).keyup((e)-> key_queue.push e.keyCode)
235
+ key_loop()
236
+ ## vim: set ft=coffee :
@@ -0,0 +1,59 @@
1
+ var mode = "landscape"
2
+ var cached = {}
3
+ var size = window_size()
4
+
5
+ function is_NaN($value){
6
+ return (typeof $value == 'number' && $value.toString() == 'NaN');
7
+ }
8
+
9
+ function _id(){
10
+ return $("#id").text()
11
+ }
12
+
13
+ function now(){
14
+ var count = parseInt($("#now").text())
15
+ if(is_NaN(count)){
16
+ return 0
17
+ }else{
18
+ return count
19
+ }
20
+ }
21
+ function _now(str){
22
+ return $("#now").text(str)
23
+ }
24
+ function is_left(){
25
+ return $("#is_left").text() === "true"
26
+ }
27
+
28
+ function width() {
29
+ if ( window.innerWidth ) {
30
+ return window.innerWidth;
31
+ }
32
+ else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
33
+ return document.documentElement.clientWidth;
34
+ }
35
+ else if ( document.body ) {
36
+ return document.body.clientWidth;
37
+ }
38
+ return 0;
39
+ }
40
+
41
+ function height() {
42
+ if ( window.innerHeight ) {
43
+ return window.innerHeight;
44
+ }
45
+ else if ( document.documentElement && document.documentElement.clientHeight != 0 ) {
46
+ return document.documentElement.clientHeight;
47
+ }
48
+ else if ( document.body ) {
49
+ return document.body.clientHeight;
50
+ }
51
+ return 0;
52
+ }
53
+
54
+ function is_portlait(){
55
+ return (height()/width())<1
56
+ }
57
+ function window_size(){
58
+ return {height: height(), width: width()}
59
+ }
@@ -0,0 +1,8 @@
1
+ save = -> localStorage.gyazo = $('#gyazo').val()
2
+
3
+ $ ->
4
+ if localStorage.gyazo == undefined
5
+ localStorage.gyazo = 'http://gyazo.com/upload.cgi'
6
+ $('#gyazo').val(localStorage.gyazo)
7
+
8
+ $('#save').click -> save()
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ %meta{charset: 'UTF-8'}
3
+ %title Config - Pig Media Server
4
+ %script{src: 'http://code.jquery.com/jquery.min.js'}
5
+ %script{src: '/config.js'}
6
+ %link{href: '/app.css', rel: 'stylesheet', type: 'text/css'}
7
+ %meta(content='width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' name='viewport')
8
+ #all
9
+ -unless session[:user_id]
10
+ %a{href: '/sessions'} Login
11
+ -else
12
+ Login as
13
+ %span#user_id=session[:user_id]
14
+ %a{href: '/sessions'} Logout
15
+ %h1 Pig Media Server
16
+ %form{method: 'GET', action: '/'}
17
+ %input{name: 'query', value: params[:query]}
18
+ %button Search
19
+ %a{href: '/latest'} Latest
20
+ %a{href: '/config'} Config
21
+ %h2 Config
22
+ %table
23
+ %tr
24
+ %th Gyazo
25
+ %td
26
+ %input#gyazo{size: 60}
27
+ %tr
28
+ %td
29
+ %button#save Save
@@ -0,0 +1,45 @@
1
+ !!!
2
+ %title Pig Media Server
3
+ %meta(content='width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' name='viewport')
4
+ %script{src: 'http://code.jquery.com/jquery.min.js'}
5
+ -%w{storage session movie unread book book2 swipe}.each do |js|
6
+ %script{src: "/#{js}.js"}
7
+
8
+ %link{href: '/app.css', rel: 'stylesheet', type: 'text/css'}
9
+ :css
10
+ .none{display:none}
11
+ #area=''
12
+ #all
13
+ -unless session[:user_id]
14
+ %a{href: '/sessions'} Login
15
+ -else
16
+ Login as
17
+ %span#user_id=session[:user_id]
18
+ %a{href: '/sessions'} Logout
19
+ %p=flash[:notice]
20
+ %h1 Pig Media Server
21
+ %form{method: 'GET', action: '/'}
22
+ %input{name: 'query', value: params[:query]}
23
+ %button Search
24
+ %a{href: '/latest'} Latest
25
+ %a{href: '/config'} Config
26
+ -if config['custom_list'].class == Hash
27
+ -config['custom_list'].each do |k,v|
28
+ %a{href: "/custom?name=#{CGI.escape k}"}=k
29
+ -if @page
30
+ %p.autopagerize_page_element
31
+ -@list.each do |l|
32
+ -next unless l.record
33
+ !=partial :_link, locals: {l: l}
34
+ %p.pager
35
+ -if params[:query] and params[:query].empty? == false
36
+ %a{href: "/?query=#{CGI.escape params[:query]}&page=#{@page+1}"} Next
37
+ %a{href: "/edit?query=#{CGI.escape params[:query]}"} Edit
38
+ -elsif params[:sub]
39
+ %a{href: "/?sub=true&page=#{@page+1}"} Next
40
+ -else
41
+ %a{href: "/latest?page=#{@page+1}"} Next
42
+
43
+ .none
44
+ %span#action=@action
45
+ %canvas#canvas