services_controller.rb
1.33 KB
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
class Slibras::ServicesController < Slibras::BaseController
respond_to :html, :json
def index
end
def data
output = %x[ip addr show eth0 | grep 'inet' | awk '{print $2}']
saida = output.split('/')
getIP = saida[0]
path = params[:subtitle]
file = File.new("public/"+path,"r")
array = []
test = ""
while (line = file.gets)
array << line.delete("\n")
end
file.close
new_array = []
count=0
pos = array.size / 4
0.upto(pos) do |name_pos|
new_array << {"id" => array[count], "time" => array[count+1].split("-->"), "title" => array[count+2]}
count+=4
end
render :json => new_array
end
def write
subtitle_updated = params[:payload].split(",")
subtitle = params[:subtitle]
private_params = subtitle.split("/")
id = private_params[4]
oldfile = File.new("public"+subtitle,"r")
array = []
while (line = oldfile.gets)
array << line.delete("\n")
end
count=0;
subtitle_updated.each do |sub|
array[2+count].replace(sub)
count+=4
end
oldfile.close
newfile = File.new("public"+subtitle,"w+")
array.each do |element|
newfile.write(element)
newfile.write("\n")
end
newfile.close
redirect_to generate_path(:id => id, :closed_caption => 0)
end
end