youtube_dlhelper 0.1.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gemnasium.yml +5 -0
  4. data/.gemrelease +6 -0
  5. data/.gitignore +8 -0
  6. data/.idea/.name +1 -0
  7. data/.idea/.rakeTasks +7 -0
  8. data/.idea/dictionaries/sascha.xml +3 -0
  9. data/.idea/dictionaries/smanns.xml +3 -0
  10. data/.idea/encodings.xml +5 -0
  11. data/.idea/inspectionProfiles/Project_Default.xml +81 -0
  12. data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
  13. data/.idea/misc.xml +5 -0
  14. data/.idea/modules.xml +9 -0
  15. data/.idea/scopes/scope_settings.xml +5 -0
  16. data/.idea/sonarIssues.xml +29 -0
  17. data/.idea/vagrant.xml +7 -0
  18. data/.idea/vcs.xml +7 -0
  19. data/.idea/workspace.xml +1273 -0
  20. data/.idea/workspace_conflict-20150617-151434.xml +933 -0
  21. data/.idea/youtube_dlhelper.iml +241 -0
  22. data/.idea/youtube_dlhelper_conflict-20150617-151434.iml +230 -0
  23. data/.index +121 -0
  24. data/.overcommit.yml +76 -0
  25. data/.rspec +2 -0
  26. data/.rubocop.yml +39 -0
  27. data/.scrutinizer.yml +26 -0
  28. data/.travis.yml +29 -0
  29. data/.yardopts +7 -0
  30. data/CHANGELOG.md +75 -0
  31. data/CODE_OF_CONDUCT.md +17 -0
  32. data/CONTRIBUTING.md +25 -0
  33. data/Gemfile +5 -0
  34. data/Index.yml +54 -0
  35. data/LICENSE.md +187 -0
  36. data/MANIFEST +635 -0
  37. data/README.md +67 -0
  38. data/Rakefile +318 -0
  39. data/VERSION +1 -0
  40. data/bin/youtube_dlhelper +12 -0
  41. data/circle.yml +16 -0
  42. data/config.reek +111 -0
  43. data/etc/youtube_dlhelper.conf +8 -0
  44. data/lib/youtube_dlhelper.rb +128 -0
  45. data/lib/youtube_dlhelper/checker.rb +160 -0
  46. data/lib/youtube_dlhelper/downloader.rb +80 -0
  47. data/lib/youtube_dlhelper/get.rb +43 -0
  48. data/lib/youtube_dlhelper/import_config.rb +42 -0
  49. data/lib/youtube_dlhelper/ripper.rb +100 -0
  50. data/lib/youtube_dlhelper/version.rb +38 -0
  51. data/ruby-lint.yml +2 -0
  52. data/youtube_dlhelper.gemspec +56 -0
  53. metadata +601 -0
@@ -0,0 +1,8 @@
1
+ # Config file for youtube_dlhelper
2
+ # Change this variable to your Musicdir (Without /home/youruser)
3
+ musicdir = 'Musik'
4
+
5
+ # Use ogg: If you accept a ogg file you can leave this
6
+ # setting. If you just want to have MP3s set this to false
7
+ # default: true
8
+ ogg_file_accept = true
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ # Youtube converter main class
3
+ #
4
+ # Copyright (C) 2013-2015 Sascha Manns <samannsml@directbox.com>
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ # Dependencies
20
+ # rubocop:disable Metrics/LineLength
21
+ require File.expand_path(File.join(File.dirname(__FILE__), 'youtube_dlhelper/version'))
22
+ require File.expand_path(File.join(File.dirname(__FILE__), 'youtube_dlhelper/checker'))
23
+ require File.expand_path(File.join(File.dirname(__FILE__), 'youtube_dlhelper/downloader'))
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'youtube_dlhelper/import_config'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), 'youtube_dlhelper/ripper'))
26
+ require 'highline/import'
27
+ require 'fileutils'
28
+ require 'parseconfig'
29
+ require 'addressable/uri'
30
+ require 'viddl-rb'
31
+ require 'streamio-ffmpeg'
32
+ require 'rainbow/ext/string'
33
+
34
+ # The main class YoutubeDlhelper
35
+ class YoutubeDlhelper
36
+ puts 'Running initialize process...'
37
+ puts 'Gets version...'
38
+ # @note Version variable
39
+ version = YoutubeDlhelperVersion::Version::STRING
40
+
41
+ puts 'Gets own process name...'
42
+ # @note Name of the App
43
+ my_name = File.basename($PROGRAM_NAME)
44
+
45
+ puts 'Getting command line arguments...'
46
+ # @note Command line aguments
47
+ argv = ARGV[0].to_s
48
+
49
+ puts 'Checking parsed URL if its valid...'
50
+ # @note Checks if the URL is valid
51
+ # @param [String] argv Given
52
+ url = Checker.external_url_is_valid?(argv)
53
+
54
+ puts 'Checking if your .youtube_dlhelper.conf is available...'
55
+ # @note Check oldconfig
56
+ Checker.oldconfig_exists?
57
+
58
+ puts 'Getting variables from your .youtube_dlhelper.conf...'
59
+ # @note Imports the configuration
60
+ home = Dir.home
61
+ music_dir_get, ogg_file_accept = Import.import_config
62
+ music_dir = "#{home}/#{music_dir_get}"
63
+
64
+ puts 'Initialized...'
65
+ puts 'Launching ...'
66
+ puts "Script: #{my_name}".color(:yellow)
67
+ puts "Version: #{version}".color(:yellow)
68
+ puts
69
+ puts 'Copyright (C) 2013-2015 Sascha Manns <Sascha-Manns@web.com>'
70
+ puts 'Description: This script can download music from YouTube'
71
+ puts "converts it to OGG/MP3 and places it in #{music_dir}."
72
+ puts 'License: See LICENSE file'
73
+ puts ''
74
+ puts 'This program is free software: you can redistribute it and/or modify'
75
+ puts 'it under the terms of the GNU General Public License as published by'
76
+ puts 'the Free Software Foundation, either version 3 of the License, or'
77
+ puts '(at your option) any later version.'
78
+ puts ''
79
+ puts 'This program is distributed in the hope that it will be useful,'
80
+ puts 'but WITHOUT ANY WARRANTY; without even the implied warranty of'
81
+ puts 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the'
82
+ puts 'GNU General Public License for more details.'
83
+ puts 'You should have received a copy of the GNU General Public License'
84
+ puts 'along with this program. If not, see <http://www.gnu.org/licenses/>.'
85
+ puts 'File bugreports and feature requests there:'
86
+ puts 'http://saigkill-bugs.myjetbrains.com/youtrack/issues'
87
+
88
+ # Check which decoder should used
89
+ ffmpeg_binary = Checker.which_decoder?
90
+
91
+ puts 'CHECKING TARGET'.color(:yellow)
92
+ # @note Checks if target directory is present. Otherwise it creates one
93
+ folder = Checker.check_target
94
+
95
+ # @note Prints out which targetfolder is choosen.
96
+ puts 'SEARCHING FOR TARGETDIR'
97
+ puts "Your present Targetfolder is: #{music_dir}/#{folder}".color(:yellow)
98
+ puts 'You can choose another one directly in the configfile.'
99
+ puts 'Checking now, if your targetdirectory exists...'
100
+ # @param [String] music_dir Path to the music directory
101
+ # @param [String] folder Path to the targetfolder
102
+ Checker.check_dir(music_dir, folder)
103
+
104
+ # @note Using FileUtils to enter the generated directory
105
+ puts 'SWITCHING TO TARGETDIR'.color(:yellow)
106
+ # @param [String] music_dir Path to the music directory
107
+ # @param [String] folder Path to the targetfolder
108
+ FileUtils.cd("#{music_dir}/#{folder}") do
109
+ puts "Now we are switched to directory #{Dir.pwd}".color(:yellow)
110
+ puts 'DOWNLOADING YOUR VIDEO'
111
+
112
+ # @param [String] url Is the given URL to the Youtube file
113
+ filename, filenameold = Downloader.get(url)
114
+
115
+ # @param [String] filename The filename
116
+ # @param [String] ogg_file_accept OGG file as end file accepted?
117
+ # (true/false)
118
+ # @param [String] ffmpeg_binary Path to the ffmpeg binary
119
+ filenamenew, extension = Ripper.rip_prepare(filename, ogg_file_accept,
120
+ ffmpeg_binary)
121
+
122
+ # @param [String] filenamenew The new produced filename
123
+ Checker.cleanup(filenamenew, filenameold)
124
+
125
+ puts "Now you can find your file in #{music_dir}/#{folder}/#{filenamenew}.#{extension}".color(:yellow)
126
+ puts "Thank you for using #{my_name} #{version}".color(:yellow)
127
+ end
128
+ end
@@ -0,0 +1,160 @@
1
+ # Youtube Converter for Ruby
2
+ # Description: Downloads a file from a YT URL transcodes them to MP3 and places
3
+ # it into a choosen folder
4
+ # Module: Checker
5
+ # Work: This Module provides different checker methods
6
+ # Class Documentation:
7
+ # http://www.rubydoc.info/github/saigkill/youtube_dlhelper/Checker
8
+ #
9
+ # Copyright (C) 2013-2015 Sascha Manns <samannsml@directbox.com>
10
+ #
11
+ # This program is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+
25
+ # Dependencies
26
+ require 'rainbow/ext/string'
27
+ require 'fileutils'
28
+ require 'net/http'
29
+ require 'uri'
30
+
31
+ # The Checker module contains different methods to check anything
32
+ module Checker
33
+ # @note This method checks if a url is valid
34
+ # This method smells of :reek:TooManyStatements
35
+ # @param [String] url Is the given URL to the Youtube file
36
+ # @return [String] url
37
+ def self.external_url_is_valid?(url)
38
+ puts 'Checking prefix'.color(:green)
39
+ puts url
40
+ if url.include? 'https'
41
+ puts 'Checking if https URL is valid'.color(:green)
42
+ https_url_valid?(url)
43
+ return url
44
+ else
45
+ puts 'Checking if http URL is valid'.color(:green)
46
+ http_url_valid?(url)
47
+ return url
48
+ end
49
+ end
50
+
51
+ # Method to check https
52
+ # @param [String] url Is the given URL to the Youtube file
53
+ def self.https_url_valid?(url)
54
+ # @param [String] url Is the given URL to the Youtube file
55
+ uri = URI.parse(url)
56
+ response = Net::HTTP.start(uri.host, uri.port,
57
+ :use_ssl => uri.scheme == 'https') do |http|
58
+ http.head(uri.path)
59
+ end
60
+ response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
61
+ end
62
+
63
+ # Method to check http
64
+ # @param [String] url Is the given URL to the Youtube file
65
+ def self.http_url_valid?(url)
66
+ # @param [String] url Is the given URL to the Youtube file
67
+ uri = URI.parse(url)
68
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
69
+ http.head(uri.path)
70
+ end
71
+ response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
72
+ end
73
+
74
+ # rubocop:disable Metrics/LineLength
75
+ # This method smells of :reek:TooManyStatements
76
+ # Ask for names, creates the folders and puts all into a $folder variable
77
+ # @return [String] folder
78
+ def self.check_target
79
+
80
+ entry = ask 'What kind of entry do you have? (Interpret or Group)'
81
+
82
+ subdir = case entry
83
+ when 'Interpret'
84
+ [
85
+ ask('Whats the surname of your interpret?'),
86
+ ask('Whats the first name of your interpret?')
87
+ ].join('_')
88
+
89
+ when 'Group'
90
+ ask 'Whats the name of the group?'
91
+
92
+ else
93
+ puts 'Just the entries "Interpret" or "Group" are allowed'.color(:red)
94
+ abort('Aborted')
95
+ end
96
+ subdir.gsub(/ /, '_')
97
+ folder = "#{ subdir }/Youtube-Music"
98
+ return folder
99
+ end
100
+
101
+ # Checks if the targetdirectory are present. If not, it creates one
102
+ # @param [String] music_dir Path to the music directory
103
+ # @param [String] folder Path to the targetfolder
104
+ def self.check_dir(music_dir, folder)
105
+ # @note Checking if musicdir exists
106
+ if Dir.exist?("#{music_dir}/#{folder}")
107
+ puts 'Found directory. Im using it.'.color(:green)
108
+ else
109
+ puts 'No directory found. Im creating it.'.color(:green)
110
+ # @note Creates the new directory in $music_dir/$folder
111
+ FileUtils.mkdir_p("#{music_dir}/#{folder}")
112
+ if Dir.exist?("#{music_dir}/#{folder}")
113
+ puts 'Created new directory...'.color(:green)
114
+ else
115
+ fail('Cant create directory')
116
+ end
117
+ end
118
+ end
119
+
120
+ # This method checks if a oldconfig is available
121
+ # @return [String] true or false
122
+ def self.oldconfig_exists?
123
+ home = Dir.home
124
+ if File.exist?("#{home}/.youtube_dlhelper/youtube_dlhelper.conf")
125
+ puts 'Found configuration file and using it...'.color(:yellow)
126
+ else
127
+ # @raise
128
+ puts 'Please run rake setup'.color(:red)
129
+ fail('Exiting now..').color(:red)
130
+ end
131
+ end
132
+
133
+ # This method checks which decoder is available
134
+ # This method smells of :reek:TooManyStatements
135
+ # @return [String] ffmpeg_binary
136
+ def self.which_decoder?
137
+ getavconv = `which avconv`
138
+ getffmpeg = `which ffmpeg`
139
+ avconv = p getavconv.chomp
140
+ ffmpeg = p getffmpeg.chomp
141
+ ffmpeg_binary = ffmpeg if ffmpeg != ''
142
+ ffmpeg_binary = avconv if avconv != ''
143
+ return ffmpeg_binary
144
+ end
145
+
146
+ # Cleaner method for unneeded files
147
+ # This method smells of :reek:TooManyStatements
148
+ # @param [String] filename The name of the new produced file
149
+ def self.cleanup(filename, filenameold)
150
+ puts 'Cleaning up directory'.color(:green)
151
+ # @note Cleanup the temp files
152
+ File.delete("#{filename}.mp4") if File.exist?("#{filename}.mp4")
153
+ File.delete("#{filename}.m4a") if File.exist?("#{filename}.m4a")
154
+ File.delete("#{filename}.webm") if File.exist?("#{filename}.webm")
155
+ File.delete("#{filenameold}.mp4") if File.exist?("#{filenameold}.mp4")
156
+ File.delete("#{filenameold}.m4a") if File.exist?("#{filenameold}.m4a")
157
+ File.delete("#{filenameold}.webm") if File.exist?("#{filenameold}.webm")
158
+ puts 'Finished cleaning up'.color(:green)
159
+ end
160
+ end
@@ -0,0 +1,80 @@
1
+ # Youtube Converter for Ruby
2
+ # Description: Downloads a file from a YT URL transcodes them to MP3 or OGG and
3
+ # places it into a choosen folder
4
+ # Module: Downloader
5
+ # Work: It downloads a *.mp4 file from Youtube, then extracts audio to *.m4a
6
+ # Class Documentation:
7
+ # http://www.rubydoc.info/github/saigkill/youtube_dlhelper/Downloader
8
+ #
9
+ # Copyright (C) 2013-2015 Sascha Manns <samannsml@directbox.com>
10
+ #
11
+ # This program is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+
25
+ # Dependencies
26
+ require 'viddl-rb'
27
+ require 'rainbow/ext/string'
28
+ require 'fileutils'
29
+
30
+ # Module for all Downloading things
31
+ module Downloader
32
+ # Accessing the url with get(url) via viddl-rb
33
+ # @param [String] url Is the given URL to the Youtube file
34
+ def self.get(url)
35
+ puts 'Downloading file...'.color(:green)
36
+ system('viddl-rb', '-e', "#{url}")
37
+ puts 'Downloading done...'.color(:green)
38
+ rename(url)
39
+ end
40
+
41
+ # rubocop:disable Metrics/AbcSize
42
+ # This method smells of :reek:TooManyStatements
43
+ # This method smells of :reek:UncommunicativeVariableName
44
+ # Method for renaming the orig file with blanks to underscores
45
+ # @param [String] url Is the given URL to the Youtube file
46
+ # @return [String] filenamenew The fixed filename with underscores
47
+ def self.rename(url)
48
+ file = ViddlRb.get_names(url)
49
+ file.first
50
+ extn = File.extname file.first.to_s # .mp4
51
+ # Culture Beat Mr. Vain
52
+ filename = File.basename file.first.to_s, extn
53
+ ext = file_exist_ogg_m4a(filename)
54
+ # @note Replacing blanks with underscrores and delete non standard chars in
55
+ # filename
56
+ filenamenew0 = filename.gsub(/ /, '_')
57
+ pattern = /[a-zA-Z0-9\-\s\_]/
58
+ # Culture_Beat___________Mr_Vain
59
+ filenamenew = filenamenew0.split(//).keep_if do |chr|
60
+ chr =~ pattern
61
+ end.join
62
+ puts 'Renaming the downloaded file'.color(:green)
63
+ FileUtils.mv("#{filename}.#{ext}", "#{filenamenew}.#{ext}")
64
+ [filenamenew, filename]
65
+ end
66
+
67
+ # It checks what old file are available
68
+ # @param [String] filename
69
+ # @return ext
70
+ def self.file_exist_ogg_m4a(filename)
71
+ if File.exist?("#{filename}.ogg")
72
+ ext = 'ogg'
73
+ elsif File.exist?("#{filename}.m4a")
74
+ ext = 'm4a'
75
+ elsif File.exist?("#{filename}.webm")
76
+ ext = 'webm'
77
+ end
78
+ return ext
79
+ end
80
+ end
@@ -0,0 +1,43 @@
1
+ # Youtube Converter for Ruby
2
+ # Description: Downloads a file from a YT URL transcodes them to MP3 or OGG and
3
+ # places it into a choosen folder
4
+ # Module: Downloader
5
+ # Work: It downloads a *.mp4 file from Youtube, then extracts audio to *.m4a
6
+ # Class Documentation:
7
+ # http://www.rubydoc.info/github/saigkill/youtube_dlhelper/Downloader
8
+ #
9
+ # Copyright (C) 2013-2015 Sascha Manns <samannsml@directbox.com>
10
+ #
11
+ # This program is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ # Class for methods who getting informations
25
+ module YoutubeDlhelperGet
26
+
27
+ # Method for getting the url
28
+ # @return [String] urlchecked
29
+ def self.url
30
+ # @note Put the yad input
31
+ urlinput = `yad --entry --button="Go" --title="URL" --text="Place your URL:"`
32
+ puts urlinput
33
+ return urlinput
34
+ end
35
+
36
+ # Method for getting the type of the musicans
37
+ # def self.type
38
+ # # @note Put the yad input
39
+ # type = `yad --title="Create documentation" --center --on-top --text="Is it a group or a single interpret" --button="Group" --button="Interpret"`
40
+ # puts type
41
+ #
42
+ # end
43
+ end
@@ -0,0 +1,42 @@
1
+ # Youtube Converter for Ruby
2
+ # Description: Downloads a file from a YT URL transcodes them to MP3 and places
3
+ # it into a choosen folder
4
+ # Module: Parses the configfile and imports the config
5
+ # Work: This file contains some standard methods for YoutubeDlhelper
6
+ # Class Documentation:
7
+ # http://www.rubydoc.info/github/saigkill/youtube_dlhelper/Import
8
+ # Copyright (C) 2013-2015 Sascha Manns <samannsml@directbox.com>
9
+ #
10
+ # This program is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # This program is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+
23
+
24
+ # Dependencies
25
+ require 'parseconfig'
26
+
27
+ # Module for Importing Informations
28
+ module Import
29
+ # This Module parses the youtube_dlhelper.conf
30
+ # @return [Array] music_dir, ogg_file_accept, ffmpeg_binary
31
+ def self.import_config
32
+ home = Dir.home
33
+ config = ParseConfig.new(File.join(File.dirname(home),
34
+ '.youtube_dlhelper/youtube_dlhelper.conf'))
35
+ # @note Saving the variable musiddir
36
+ music_dir = config['musicdir'].to_s
37
+ # @note Saving the variable ogg_file_accept
38
+ ogg_file_accept = config['ogg_file_accept'].to_s
39
+ # @note It returns a array with music_dir, ogg_file_accept, ffmpeg_binary
40
+ [music_dir, ogg_file_accept]
41
+ end
42
+ end