/
controllers.rb
154 lines (125 loc) · 4.21 KB
/
controllers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
###########################################################################
# Copyright (C) 2008 by Paul Betts #
# paul.betts@gmail.com #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
###########################################################################
require File.join(File.dirname(__FILE__), 'config')
path_add File.join(File.dirname(__FILE__))
# Standard library
require 'rubygems'
require 'logger'
require 'gettext'
require 'yaml'
require 'ramaze'
require 'builder'
require 'builder/xmlmarkup'
require 'fileutils'
require 'uri'
# Yikes
require 'config'
require 'platform'
require 'utility'
require 'state'
include GetText
Ramaze::Global.public_root = File.join File.dirname(__FILE__), 'public'
Ramaze::Global.template_root = File.join File.dirname(__FILE__), 'views'
### Helper Classes
# FIXME: This creates a broken mapping to /static_file
class StaticFileControllerBase < Ramaze::Controller
def index(*paths)
do_send_file File.join(paths)
end
protected
def do_send_file(subpath)
target = get_file_path
mimetype = get_mime_type
p = Pathname.new(File.join(target, subpath))
begin
return nil unless p.realpath.to_s.index(target) == 0
rescue
return nil
end
logger.debug p.to_s
send_file(p.to_s, mimetype)
end
def get_mime_type; 'video/mp4'; end
end
class EncodingItem
def source_url
URI.escape("#{Yikes.url_base}/files/#{subpath_target}")
end
def screenshot_url
URI.escape("#{Yikes.url_base}/preview/#{screenshot_subpath}")
end
end
### Controllers
class MainController < Ramaze::Controller
engine :Erubis
def index
@items = Yikes.instance.engine.state.get_finished_items
end
end
class PodcastController < Ramaze::Controller
map '/podcast'
def index
return podcast_xml
end
private
def podcast_xml
app = Yikes.instance.engine.state
xml = Builder::XmlMarkup.new
xml.instruct!
xml.rss("xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", "xmlns:media" => "http://search.yahoo.com/mrss/", "version" => "2.0") do
xml.channel do
xml.title "Yikes video feed of #{Pathname.new(app.library).basename.to_s}"
xml.link Yikes.url_base
xml.language "en-us"
xml.copyright "Copyright 2008 Paul Betts"
xml.tag! "itunes:summary", "Converted videos, from #{app.library}"
xml.description "Converted videos, from #{app.library}"
xml.tag! "itunes:image", "#{Yikes.url_base}/FILLMEIN.png"
xml.tag! "itunes:category", "Videos"
app.get_finished_items.each do |x|
xml.item do
next unless x.succeeded
xml.title x.subpath
xml.tag! "itunes:subtitle", x.source_path
xml.enclosure(:url => x.source_url, :length => "100000", :type => "video/mp4")
xml.guid x.source_url
xml.pubDate x.finished_at.to_s
xml.tag! "itunes:duration", "3:00"
end
end
end ; end
xml.target!
end
end
class FilesController < StaticFileControllerBase
map '/files'
protected
def get_file_path
Yikes.instance.state.target
end
end
class PreviewController < StaticFileControllerBase
map '/preview'
protected
def get_file_path
Platform.screenshot_dir
end
def get_mime_type; 'image/jpeg'; end
end