-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub
executable file
·60 lines (41 loc) · 1.36 KB
/
sub
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
#!/usr/bin/env ruby
require "net/http"
filename = ARGV[0]
if filename.nil?
puts 'Usage: sub your_media_file_name [-r]'
puts '-r starts VLC after downloading subtitles'
abort
end
uri = URI("http://www.podnapisi.net/en/ppodnapisi/search/sK/#{filename}/sS/downloads/sO/desc")
matches = /<tr class=" ">.*<a class="subtitle_page_link" href="([^"]*)">.*English subtitles/m.match(Net::HTTP.get(uri))
if matches.nil?
puts "No subtitle found, for debugging, visit #{uri.to_s}"
abort
end
download_page_path = matches[1]
uri = URI("http://www.podnapisi.net/#{download_page_path}")
matches = /<a rel="nofollow" class="button big download" href="([^"]*)".*>Download subtitle</m.match(Net::HTTP.get(uri))
if matches.nil?
puts "No download button found, for debugging, visit #{uri.to_s}"
abort
end
`wget http://www.podnapisi.net#{matches[1]}`
file = matches[1].split('/').last
zipped_file = "#{file}.zip"
`mv #{file} #{zipped_file}`
filename = `unzip -Z -1 #{zipped_file}`
`unzip #{zipped_file}`
filename.gsub!(/ /,"\\ ")
';\'"`#$&*?<>{}'.split('').each do |x|
filename.gsub!(/[#{x}]/, "\\\\#{x}")
end
filename.gsub!("\n", "")
filename_suffix = filename.split('.').last
new_filename = ARGV[0].split('.')
new_filename[-1] = filename_suffix
new_filename = new_filename.join('.')
`mv #{filename} #{new_filename}`
`rm #{zipped_file}`
if ARGV[1] == '-r'
`vlc #{ARGV[0]}`
end