Last active
August 5, 2017 10:00
-
-
Save kenjoe41/d047d764aeeb35b1064bc5cf2b79cc58 to your computer and use it in GitHub Desktop.
Revisions
-
kenjoe41 revised this gist
Aug 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def create_a_directory(dir_name) end end dir_name = "path/to/podcast/download/folder" #create directory if it doesn't exist create_a_directory(dir_name) -
kenjoe41 revised this gist
Aug 5, 2017 . 1 changed file with 16 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ require 'fileutils' require 'rubygems' require 'typhoeus' #function to create a directory def create_a_directory(dir_name) @@ -12,7 +12,7 @@ def create_a_directory(dir_name) unless File.exist?(dir_name) begin FileUtils.mkdir_p(dir_name) puts "Just made the following dir #{dir_name}" rescue Errno::EACCES => e abort "Failed to create #{dir_name}: #{e.message}" end @@ -21,7 +21,7 @@ def create_a_directory(dir_name) end dir_name = "/home/parzival/Music/Codepen_Podcasts" #create directory if it doesn't exist create_a_directory(dir_name) #latest episode to Download @@ -48,20 +48,21 @@ def create_a_directory(dir_name) puts "Downloading episode #{i}" downloaded_file = File.open "#{dir_name}/#{i}", 'wb' request = Typhoeus::Request.new("codepen-podcast.s3.amazonaws.com/#{i}.mp3") request.on_headers do |response| if response.code != 200 raise "Request failed" end end request.on_body do |chunk| downloaded_file.write(chunk) end request.on_complete do |response| downloaded_file.close # Note that response.body is "" end request.run #increment number of completed podcast downloads podcasts += 1 -
kenjoe41 revised this gist
Jul 31, 2017 . 1 changed file with 24 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,29 @@ #!/usr/bin/ruby require 'fileutils' require 'rubygems' require 'net/http' #function to create a directory def create_a_directory(dir_name) if dir_name # dir_name was specified, ensure it is created and writable. unless File.exist?(dir_name) begin FileUtils.mkdir_p(dir_name) puts "just made the following dir #{dir_name}" rescue Errno::EACCES => e abort "Failed to create #{dir_name}: #{e.message}" end end end end dir_name = "/home/parzival/Music/Codepen_Podcasts" #Kernel.const_get(dir_name).new.start_check #create directory if it doesn't exist create_a_directory(dir_name) #latest episode to Download latest_episode = 138 @@ -21,7 +38,7 @@ i = sprintf('%03d', i) #check if file exists if File.exist? "#{dir_name}/#{i}" next end #check for new range that has a different URL @@ -32,7 +49,9 @@ puts "Downloading episode #{i}" Net::HTTP.start("codepen-podcast.s3.amazonaws.com") do |http| #create file first as call to open fails if it doesn't exist File.new("#{dir_name}/#{i}", 'w') f = open("#{dir_name}/#{i}", 'w') begin http.request_get("/#{i}.mp3") do |resp| resp.read_body do |segment| -
kenjoe41 created this gist
Jul 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/usr/bin/ruby require 'rubygems' require 'net/http' DIR_NAME = "codepen_podcasts" #create directory if it doesn't exist Dir.mkdir(DIR_NAME) unless Dir.exists?(DIR_NAME) #latest episode to Download latest_episode = 138 #variable for number of podcasts downloaded podcasts = 0 #iterate a range of podcasts to download for i in 1..latest_episode # ensure i is 3 digits n pad it with 00 is not. #thank you rindolf in freenode ##programing IRC i = sprintf('%03d', i) #check if file exists if File.exist? "#{DIR_NAME}/#{i}" next end #check for new range that has a different URL if i.to_i >= 124 i = "codepen-" << i end puts "Downloading episode #{i}" Net::HTTP.start("codepen-podcast.s3.amazonaws.com") do |http| f = open(DIR_NAME/"#{i}") begin http.request_get("/#{i}.mp3") do |resp| resp.read_body do |segment| f.write(segment) end end ensure f.close() end end #increment number of completed podcast downloads podcasts += 1 end puts "Done. Downloaded #{podcasts} podcasts"