Skip to content
Extraits de code Groupes Projets
Valider acb337b5 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

SoundcloudPlugin, et amélioration de YoutubePlugin

parent e5fdc65b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
source "http://rubygems.org"
gem "net-yail"
gem "youtube_it"
gem "rspec"
gem "youtube_it"
gem "soundcloud"
......@@ -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
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
......@@ -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
......
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
......@@ -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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter