Last active
August 29, 2015 14:01
-
-
Save turizoft/52e2218a3fb612986079 to your computer and use it in GitHub Desktop.
Revisions
-
turizoft revised this gist
May 16, 2014 . 1 changed file with 1 addition and 0 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 @@ -50,5 +50,6 @@ rescue puts "Error while downloading #{row[0]}" end sleep(3) browser.close end -
turizoft revised this gist
May 16, 2014 . 1 changed file with 44 additions and 51 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,61 +1,54 @@ # This script reads a csv file with song name and # artist name in order to download them. # This csv can be generated using for example http://groovebackup.com/ # if your collection is hosted on Grooveshark. # Before running ensure watir-webdriver gems is installed. # For windows you will also need Chromedriver.exe to be in your PATH. # Finally the extension GroovesharkDownloader is required. # Note that this technique is intrusive! # You can't use your pc while its working since # it opens and closes a lot of windows. require 'csv' require 'watir-webdriver' # Option 1: (Uncomment) Provide a csv [song_name, song_author] (from any source) # csv_path = 'songs.csv' # csv_text = File.read(csv_path) # csv = CSV.parse(csv_text, headers: true) # Option 2: (Default) # 1: Go to groovebackup.com and authorize the app # 2: Choose either full collection, favorites or a playlist # 3: As soon as you click on any of the options it will start to download automatically browser = Watir::Browser.new(:chrome) browser.goto('http://groovebackup.com/') browser.driver.manage.timeouts.implicit_wait = 60 * 60 browser.pre().wait_until_present csv = CSV.parse(browser.pre().text, headers: true) browser.close csv.each do |row| # Format query and url query = "#{row[0]} #{row[1]}" url = "http://www.tinysong.com/#/result/#{query}/" # Start a browser browser = Watir::Browser.new(:chrome, switches: %w[--load-extension=Extensions/ooblpjoncpjmbncgocjlnannofkjjhnp]) # Set timeout to 2 min (for slower connections try setting a higher value) browser.driver.manage.timeouts.implicit_wait = 2 * 60 # Download source from search page browser.goto(url) begin # Wait until results are shown browser.div(id: 'result_wrapper').wait_until_present # Click first button of results (by default) and wait until song downloads browser.div(css: '#result_wrapper > ul > li > div.sharesong').wait_until_present browser.div(css: '#result_wrapper > ul > li > div.sharesong').click browser.div(css: '#result_wrapper > ul > li > div.sharesong.completed').wait_until_present rescue puts "Error while downloading #{row[0]}" end browser.close end -
turizoft revised this gist
May 15, 2014 . 1 changed file with 12 additions and 4 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 @@ -15,11 +15,12 @@ csv_path = 'songs.csv' # Read song list puts 'reading song list' csv_text = File.read(csv_path) csv = CSV.parse(csv_text, headers: true) # Start a browser browser = Watir::Browser.new :chrome csv.each do |row| @@ -39,12 +40,19 @@ if doc.at_css('.song') href = doc.at_css('.song a.button-icon-descargar')['href'] dl_url = "http://www.mp3xd.com#{href}" # Url needs to be opened in a headless browser with js support browser.goto(dl_url) browser.iframe(id: 'dlframe').wait_until_present song_url = browser.iframe(id: 'dlframe').p(id: 'url').a().href #Download song song_name = I18n.transliterate(row[0]).squeeze(' ') artist_name = I18n.transliterate(row[1]).squeeze(' ') path = "#{artist_name} - #{song_name}.mp3" #Note: override this as needed open(path, 'wb') do |file| file << open(song_url).read end else puts "#{row[0]} not found" end -
turizoft created this gist
May 15, 2014 .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,53 @@ require 'csv' require 'i18n' require 'nokogiri' require 'open-uri' require 'watir-webdriver' # This script reads a csv file with song name and # artist name in order to download them # This csv can be generated using for example http://groovebackup.com/ # if your collection is hosted on Grooveshark # Songs are downloaded from http://www.mp3xd.com/ # Before running ensure i18n, watir-webdriver and nokogiri gems are installed csv_path = 'songs.csv' # Read song list puts 'reading song list' csv_text = File.read(csv_path) csv = CSV.parse(csv_text, headers: true) browser = Watir::Browser.new :chrome csv.each do |row| puts "-- downloading #{row[0]} --" # Format query query = I18n.transliterate("#{row[1]} #{row[0]}").downcase.squeeze(' ') query = query.gsub(/[^0-9a-z ]/i, '') # Generate url param = query.gsub(' ', '-') url = "http://www.mp3xd.com/descargar-mp3/#{param}-1.html" # Download source from search page doc = Nokogiri::HTML(open(url)) # Scan document to search for links if doc.at_css('.song') href = doc.at_css('.song a.button-icon-descargar')['href'] dl_url = "http://www.mp3xd.com#{href}" # Url needs to be opened in a headless browser with js support browser.goto(dl_url) browser.iframe(id: 'dlframe').wait_until_present puts browser.iframe(id: 'dlframe').p(id: 'url').a().href else puts "#{row[0]} not found" end end browser.close