Class: Os

Inherits:
Object
  • Object
show all
Extended by:
FileUtils
Defined in:
lib/os.rb

Class Method Summary collapse

Class Method Details

.check_for_sub(path, lang) ⇒ Object



30
31
32
# File 'lib/os.rb', line 30

def check_for_sub(path, lang)
  File.exist?(path.sub(/#{File.extname(path)}$/i, ".#{lang}.srt"))
end

.default_movie_subtitle(path) ⇒ Object



6
7
8
# File 'lib/os.rb', line 6

def default_movie_subtitle(path)
  path.sub(/#{File.extname(path)}$/i, '.srt')
end

.delete_video_default_subtitle(path) ⇒ Object

Receives the path of a movie file and deletes its subtitle



11
12
13
14
# File 'lib/os.rb', line 11

def delete_video_default_subtitle(path)
  subtitle_file = default_movie_subtitle(path)
  rm(subtitle_file) if File.exist?(subtitle_file)
end

.download_subs(file) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/os.rb', line 34

def download_subs(file)
   delete_video_default_subtitle(file)
	Settings.langs.each do |lang|
		Sl.info "Language: #{lang}"
		se("getsub -aLl #{lang} \"#{file}\"")
     # Will to it just for the 1st time
     make_default_subtitle(file, lang)
	end
end

.make_default_subtitle(path, lang) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/os.rb', line 16

def make_default_subtitle(path, lang)
  # path = /tmp/a.avi
  # lang = por
  # /tmp/a.por.srt
  default_sub = default_movie_subtitle(path)
  specific_sub = path.sub(/#{File.extname(path)}$/i, ".#{lang}.srt")
  if File.exist?(specific_sub) and !File.exist?(default_sub)
    Sl.info "cp #{File.basename(specific_sub)} to #{File.basename(default_sub)}"
    cp specific_sub, default_sub
    return true
  end
  false
end

.se(command) ⇒ Object

Shell execute



46
47
48
49
50
51
# File 'lib/os.rb', line 46

def se(command)
		o = `#{command}`
		r = $?.to_i
		Sl.debug "#{o} #{r}"
		r
end