From acb337b57718114f10769c584e1091f79b3e9d7e Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@gmail.com> Date: Wed, 2 Jan 2013 21:45:44 +0100 Subject: [PATCH] =?UTF-8?q?SoundcloudPlugin,=20et=20am=C3=A9lioration=20de?= =?UTF-8?q?=20YoutubePlugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 3 ++- Gemfile.lock | 13 +++++++++++++ plugins/soundcloud_plugin.rb | 25 +++++++++++++++++++++++++ plugins/youtube_plugin.rb | 2 +- spec/soundcloud_plugin_spec.rb | 20 ++++++++++++++++++++ spec/youtube_plugin_spec.rb | 10 +++++----- 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 plugins/soundcloud_plugin.rb create mode 100644 spec/soundcloud_plugin_spec.rb diff --git a/Gemfile b/Gemfile index bb7dbee..0b7abcf 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 e741415..c531c05 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 0000000..aa2e7e1 --- /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 61aca78..58e935d 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 0000000..5954c12 --- /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 621a4a3..b26473b 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 -- GitLab