Class: Propre
Constant Summary
Constants included from Version
Instance Method Summary collapse
- #confirm ⇒ Object
- #crawlDirectory(path) ⇒ Object
- #format(movie) ⇒ Object
-
#initialize(options) ⇒ Propre
constructor
A new instance of Propre.
- #sanitize(filename) ⇒ Object
- #searchMovieFromFile(file) ⇒ Object
- #video?(file) ⇒ Boolean
Methods included from Prompt
Constructor Details
#initialize(options) ⇒ Propre
Returns a new instance of Propre.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/propre.rb', line 13 def initialize() = @settings = Settings.new("#{Dir.home}/.config/Propre/settings.yaml") if @settings.get('apikey').nil? puts "It's seem you didn't set your TMDB API Key (stored in ~/.config/Propre/settings.yaml) \nPlease tell me: " @settings.set('apikey', STDIN.gets.chomp()) puts "Thanks !" end Tmdb::Api.key(@settings.get('apikey')) Tmdb::Api.language(@settings.get('locale') ? @settings.get('locale') : 'en') end |
Instance Method Details
#confirm ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/propre.rb', line 58 def confirm() @selected = false @movies.each do |movie| answer = Prompt.yesno("#{File.basename(@file)} -> #{self.format(movie)}") if answer === false; next ; elsif answer === 'skip'; puts "Skipping..."; return end @selected = movie break end if @selected then @selected end end |
#crawlDirectory(path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/propre.rb', line 25 def crawlDirectory(path) Dir.foreach(path) do |item| next if item == '.' or item == '..' if File.directory?(File.join(path, item)) if [:recursive] then self.crawlDirectory(File.join(path, item)) end else self.searchMovieFromFile(File.join(path, item)) end end end |
#format(movie) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/propre.rb', line 69 def format(movie) year = !movie.release_date.empty? ? Date.strptime(movie.release_date, "%Y-%m-%d").year : false title = year ? "#{movie.title} (#{year})" : "#{movie.title}" title.gsub! ':','-' return "#{title}#{File.extname(@file)}" end |
#sanitize(filename) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/propre.rb', line 76 def sanitize(filename) filename.downcase! filename.gsub!(/\(.*\)/, '') filename.gsub!("_", ' ') filename.gsub!(".", ' ') filename.sub!(/(19|20)\d{2}/, '') filename.strip! warez = ["truefrench","brrip", "ac3-funky", "fansub","bluray","720", "720p", "x264","french", "fr", "divx","hdcam","xvid","appz","bdrip","board","cam","dvd","dvd-r","dvdrip","dupecheck","fake","fs","gamez","hddvd","hddvdrip","hdrip","hdtv","pdtv","internal","int","keygen","leecher","limited","nuke","proper","repack","retail","rip","rip","screener","serial","subforced","hardsub","stv","telecine","telesync","tvrip","unrated","vhsrip","vo","vost","vostfr","workprint","french","wp","subbed","unsubbed", "r5", "r6", "md"] (filename.split - warez).join(' ') end |
#searchMovieFromFile(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/propre.rb', line 36 def searchMovieFromFile(file) @file = file filename = File.basename(file,File.extname(file)) if [:videonly] && !video?(file) return end if ![:dotfile] && filename.start_with?('.') return end if [:sanitize] then filename = self.sanitize(filename) end begin @movies = Tmdb::Movie.find(filename) rescue if Tmdb::Api.response['code'] === 401 abort("Error: Did you set you're API Key ? (401)") end end if self.confirm File.rename(file, File.join(File.dirname(file), self.format(@selected))) end end |
#video?(file) ⇒ Boolean
87 88 89 |
# File 'lib/propre.rb', line 87 def video?(file) MIME::Types[/^video/].include? MIME::Types.of(file) end |