Module: Checker
- Defined in:
- lib/youtube_dlhelper/checker.rb
Overview
The Checker module contains different methods to check anything
Class Method Summary collapse
-
.check_dir(music_dir, folder) ⇒ Object
Checks if the targetdirectory are present.
-
.check_target ⇒ String
rubocop:disable Metrics/LineLength This method smells of :reek:TooManyStatements Ask for names, creates the folders and puts all into a $folder variable.
-
.cleanup(filename, filenameold) ⇒ Object
Cleaner method for unneeded files This method smells of :reek:TooManyStatements.
-
.external_url_is_valid?(url) ⇒ String
This method smells of :reek:TooManyStatements.
-
.http_url_valid?(url) ⇒ Boolean
Method to check http.
-
.https_url_valid?(url) ⇒ Boolean
Method to check https.
-
.oldconfig_exists? ⇒ String
This method checks if a oldconfig is available.
-
.which_decoder? ⇒ String
This method checks which decoder is available This method smells of :reek:TooManyStatements.
Class Method Details
.check_dir(music_dir, folder) ⇒ Object
Checks if the targetdirectory are present. If not, it creates one
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/youtube_dlhelper/checker.rb', line 88 def self.check_dir(music_dir, folder) # @note Checking if musicdir exists if Dir.exist?("#{music_dir}/#{folder}") puts 'Found directory. Im using it.'.colour(:green) else puts 'No directory found. Im creating it.'.colour(:green) # @note Creates the new directory in $music_dir/$folder FileUtils.mkdir_p("#{music_dir}/#{folder}") if Dir.exist?("#{music_dir}/#{folder}") puts 'Created new directory...'.colour(:green) else fail('Cant create directory') end end end |
.check_target ⇒ String
rubocop:disable Metrics/LineLength This method smells of :reek:TooManyStatements Ask for names, creates the folders and puts all into a $folder variable
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/youtube_dlhelper/checker.rb', line 62 def self.check_target entry = ask 'What kind of entry do you have? (Interpret or Group)' subdir = case entry when 'Interpret' [ ask('Whats the surname of your interpret?'), ask('Whats the first name of your interpret?') ].join('_') when 'Group' ask 'Whats the name of the group?' else puts 'Just the entries "Interpret" or "Group" are allowed'.colour(:red) abort('Aborted') end subdir.gsub!(/ /, '_') folder = "#{ subdir }/Youtube-Music" return folder end |
.cleanup(filename, filenameold) ⇒ Object
Cleaner method for unneeded files This method smells of :reek:TooManyStatements
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/youtube_dlhelper/checker.rb', line 133 def self.cleanup(filename, filenameold) puts 'Cleaning up directory'.color(:green) # @note Cleanup the temp files Dir.glob("#{filename}*.mp4").each { |f| File.delete(f) if File.exist?(f) } Dir.glob("#{filename}*.m4a").each { |f| File.delete(f) if File.exist?(f) } Dir.glob("#{filename}*.webm").each { |f| File.delete(f) if File.exist?(f) } Dir.glob("#{filenameold}*.mp4").each { |f| File.delete(f) if File.exist?(f) } Dir.glob("#{filenameold}*.m4a").each { |f| File.delete(f) if File.exist?(f) } Dir.glob("#{filenameold}*.webm").each { |f| File.delete(f) if File.exist?(f) } puts 'Finished cleaning up'.color(:green) end |
.external_url_is_valid?(url) ⇒ String
This method checks if a url is valid
This method smells of :reek:TooManyStatements
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/youtube_dlhelper/checker.rb', line 21 def self.external_url_is_valid?(url) puts 'Checking prefix'.color(:green) puts url if url.include? 'https' puts 'Checking if https URL is valid'.colour(:green) https_url_valid?(url) return url else puts 'Checking if http URL is valid'.colour(:green) http_url_valid?(url) return url end end |
.http_url_valid?(url) ⇒ Boolean
Method to check http
49 50 51 52 53 54 55 56 |
# File 'lib/youtube_dlhelper/checker.rb', line 49 def self.http_url_valid?(url) # @param [String] url Is the given URL to the Youtube file uri = URI.parse(url) response = Net::HTTP.start(uri.host, uri.port) do |http| http.head(uri.path) end response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) end |
.https_url_valid?(url) ⇒ Boolean
Method to check https
37 38 39 40 41 42 43 44 45 |
# File 'lib/youtube_dlhelper/checker.rb', line 37 def self.https_url_valid?(url) # @param [String] url Is the given URL to the Youtube file uri = URI.parse(url) response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.head(uri.path) end response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) end |
.oldconfig_exists? ⇒ String
This method checks if a oldconfig is available
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/youtube_dlhelper/checker.rb', line 106 def self.oldconfig_exists? home = Dir.home if File.exist?("#{home}/.youtube_dlhelper/youtube_dlhelper.conf") puts 'Found configuration file and using it...'.colour(:yellow) else # @raise puts 'Please run rake setup'.colour(:red) fail('Exiting now..').colour(:red) end end |
.which_decoder? ⇒ String
This method checks which decoder is available This method smells of :reek:TooManyStatements
120 121 122 123 124 125 126 127 128 |
# File 'lib/youtube_dlhelper/checker.rb', line 120 def self.which_decoder? getavconv = `which avconv` getffmpeg = `which ffmpeg` avconv = p getavconv.chomp ffmpeg = p getffmpeg.chomp ffmpeg_binary = ffmpeg if ffmpeg != '' ffmpeg_binary = avconv if avconv != '' return ffmpeg_binary end |