Class: Ripper

Inherits:
Object
  • Object
show all
Defined in:
lib/youtube_dlhelper/ripper.rb

Overview

Module for all ripping methods

Class Method Summary collapse

Class Method Details

.convert(ogg_file_accept, ffmpeg_binary, filenamein, filename) ⇒ String

Method for converting stuff This method smells of :reek:TooManyStatements This method smells of :reek:LongParameterList This method smells of :reek:ControlParameter


75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/youtube_dlhelper/ripper.rb', line 75

def self.convert(ogg_file_accept, ffmpeg_binary, filenamein, filename)
  # @note Transcoding the file to MP3
  if ogg_file_accept == 'true'
    system("#{ffmpeg_binary} -i #{filenamein} -acodec vorbis -vn -ac 2 -aq 60 -strict -2 #{filename}.ogg")
    ext = 'ogg'
    #puts ext
  else
    system("#{ffmpeg_binary} -i #{filenamein} -acodec libmp3lame -ac 2 -ab 192k #{filename}.mp3")
    ext = 'mp3'
    #puts ext
  end
  return ext
end

.rip(filename, ext, ogg_file_accept, ffmpeg_binary) ⇒ String

rubocop:disable Metrics/LineLength This method smells of :reek:TooManyStatements This method smells of :reek:LongParameterList Method for transcoding the *.m4a file to *.mp3. Output should be a valid MP3 file.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/youtube_dlhelper/ripper.rb', line 51

def self.rip(filename, ext, ogg_file_accept, ffmpeg_binary)
  # @note Initialize the file
  FFMPEG.ffmpeg_binary = ffmpeg_binary
  filenamein = "#{filename}.#{ext}"
  audio = FFMPEG::Movie.new(filenamein)
  puts 'Initializing finished'.colour(:green)
  # @note Checking if valid
  puts 'Checking if the movie is valid.'.colour(:yellow)
  audio.valid?
  puts 'Validated'.colour(:green)
  ext = convert(ogg_file_accept, ffmpeg_binary, filenamein, filename)
  puts 'Transcoded'.colour(:green)
  [filename, ext]
end

.rip_prepare(filename, ogg_file_accept, ffmpeg_binary) ⇒ Object

rubocop:disable Metrics/AbcSize This method smells of :reek:TooManyStatements Checking which fileformat is present


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/youtube_dlhelper/ripper.rb', line 23

def self.rip_prepare(filename, ogg_file_accept, ffmpeg_binary)
  # @note Checks if a *.m4a file is present. Then it routes to Ripper.rip
  puts 'Checking if transcoding is needed. Depends on ogg_file_accept.'.colour(:yellow)
  if File.exist?("#{filename}.m4a")
    puts 'TRANSCODING TO MP3'.colour(:yellow)
    ext = 'm4a'
    rip(filename, ext, ogg_file_accept, ffmpeg_binary)
  elsif File.exist?("#{filename}.ogg") && ogg_file_accept == 'false'
    puts 'TRANSCODING TO MP3'.colour(:yellow)
    ext = 'ogg'
    rip(filename, ext, ogg_file_accept, ffmpeg_binary)
  elsif File.exist?("#{filename}.ogg")
    puts 'Already a ogg file. No transcoding needed'.colour(:green)
  else
    puts 'No transcoding needed'.colour(:green)
  end
end