diff --git a/Gemfile b/Gemfile index bb7dbee79d6bd9e65c2154f9a56d9458c223f633..0b7abcf3838972155ab932d33833de2990f904fc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ source "http://rubygems.org" gem "net-yail" -gem "youtube_it" gem "rspec" +gem "youtube_it" +gem "soundcloud" diff --git a/Gemfile.lock b/Gemfile.lock index e741415bfd685c9f15c524ffda45bb21bd88f035..c531c057f572e14cd02425032ec43f2089197c1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,10 +5,18 @@ GEM diff-lcs (1.1.3) faraday (0.8.4) multipart-post (~> 1.1) + hashie (1.2.0) + httmultiparty (0.3.8) + httparty (>= 0.7.3) + multipart-post + httparty (0.9.0) + multi_json (~> 1.0) + multi_xml httpauth (0.2.0) jwt (0.1.5) multi_json (>= 1.0) multi_json (1.5.0) + multi_xml (0.5.1) multipart-post (1.1.5) net-yail (1.6.0) nokogiri (1.5.6) @@ -29,6 +37,10 @@ GEM diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) simple_oauth (0.1.9) + soundcloud (0.3.1) + hashie + httmultiparty (>= 0.3) + httparty (>= 0.7.3) youtube_it (2.1.8) builder faraday (~> 0.8) @@ -43,4 +55,5 @@ PLATFORMS DEPENDENCIES net-yail rspec + soundcloud youtube_it diff --git a/plugins/soundcloud_plugin.rb b/plugins/soundcloud_plugin.rb new file mode 100644 index 0000000000000000000000000000000000000000..aa2e7e10bb503f467fd987598a43a052a05df64d --- /dev/null +++ b/plugins/soundcloud_plugin.rb @@ -0,0 +1,25 @@ +require_relative '../lib/site_plugin.rb' + +require 'rubygems' +require 'bundler/setup' +require 'soundcloud' + +# SitePlugin for Soundcloud +# +# Need an client ID (soundcloud_client_id). +class SoundcloudPlugin < SitePlugin + def self.can_handle?(site) + site =~ /^https?:\/\/(www\.)?soundcloud\.com\/[a-zA-Z0-9\/_-]+$/ + end + + public + def initialize(options) + @client = Soundcloud.new(:client_id => options[:soundcloud_client_id]) + end + + def get(url) + track = @client.get('/resolve', :url => url) + + {:title => track.title, :author => track.user.username} + end +end diff --git a/plugins/youtube_plugin.rb b/plugins/youtube_plugin.rb index 61aca788136363984e3331897c6ecbda853acfc7..58e935d941068bef845a855f05804b3ff0c39bbf 100644 --- a/plugins/youtube_plugin.rb +++ b/plugins/youtube_plugin.rb @@ -7,7 +7,7 @@ require 'youtube_it' # SitePlugin for YouTube class YoutubePlugin < SitePlugin def self.can_handle?(site) - site =~ /^http:\/\/((www.)?youtube.(fr|com)\/watch\?v=|youtu\.be\/)[a-zA-Z0-9]+$/ + site =~ /^https?:\/\/((www.)?youtube.(fr|com)\/watch\?v=|youtu\.be\/)[a-zA-Z0-9]+$/ end public diff --git a/spec/soundcloud_plugin_spec.rb b/spec/soundcloud_plugin_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..5954c12cdae22932a0710915917f1fbd9da2f8d7 --- /dev/null +++ b/spec/soundcloud_plugin_spec.rb @@ -0,0 +1,20 @@ +require_relative '../plugins/soundcloud_plugin.rb' +require_relative '../lib/options.rb' + +describe SoundcloudPlugin do + describe '.can_handle?' do + it 'https://soundcloud.com' do + SoundcloudPlugin.can_handle?('https://soundcloud.com/qdance/scantraxx-radioshow-yearmix').should be_true + end + end + + describe '#get' do + it "return video's informations" do + options = Options.new.read_file + track = SoundcloudPlugin.new(options).get('https://soundcloud.com/qdance/scantraxx-radioshow-yearmix') + + track[:title].should == 'Scantraxx Radioshow Yearmix 2012 | By Waverider & MC Da Syndrome' + track[:author].should == 'Qdance' + end + end +end diff --git a/spec/youtube_plugin_spec.rb b/spec/youtube_plugin_spec.rb index 621a4a34d7ca2b9f4627da4d8787227eda31af42..b26473b47e2aee116cdd1052e7cf8dcff5e655dc 100644 --- a/spec/youtube_plugin_spec.rb +++ b/spec/youtube_plugin_spec.rb @@ -2,15 +2,15 @@ require_relative '../plugins/youtube_plugin.rb' describe YoutubePlugin do describe '.can_handle?' do - it 'true with "youtube.com"' do - YoutubePlugin.can_handle?('http://youtube.com/watch?v=Pb8VPYMgHlg').should be_true + it 'https://youtube.com' do + YoutubePlugin.can_handle?('https://youtube.com/watch?v=Pb8VPYMgHlg').should be_true end - it 'true with "www.youtube.com"' do - YoutubePlugin.can_handle?('http://www.youtube.com/watch?v=Pb8VPYMgHlg').should be_true + it 'https://www.youtube.com' do + YoutubePlugin.can_handle?('https://www.youtube.com/watch?v=Pb8VPYMgHlg').should be_true end - it 'true with "youtu.be"' do + it 'http://youtu.be' do YoutubePlugin.can_handle?('http://youtu.be/Pb8VPYMgHlg').should be_true end end