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



32
33
34
# File 'lib/os.rb', line 32

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

.default_movie_subtitle(path) ⇒ Object



8
9
10
# File 'lib/os.rb', line 8

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



13
14
15
16
# File 'lib/os.rb', line 13

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



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/os.rb', line 36

def download_subs(file)
   if File.basename(file) =~ /^sample\.(avi|mp4|mkv)/i
     Sl.info("Not looking for subtitles for #{file}")
     return
   end
   delete_video_default_subtitle(file)
	Settings.langs.each do |lang|
		Sl.info "Language: #{lang}"
		se("getsub -s hn -aLl #{lang} \"#{file}\"")
     # Will to it just for the 1st time
     make_default_subtitle(file, lang)
	end
end

.make_default_subtitle(path, lang) ⇒ Object



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

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



52
53
54
55
56
57
58
# File 'lib/os.rb', line 52

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