Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • ce3c9efa5df696af70cb7b6f2eea454c22c89fa1
  • master par défaut
  • cinch
  • ruby
  • gh-pages
5 résultats

soundcloud_plugin.rb

Blame
  • Bifurcation depuis Alexandre MORIGNOT / PlayBot
    Le projet source a une visibilité limitée.
    • Alexandre Morignot's avatar
      ce3c9efa
      Database support, new config file location · ce3c9efa
      Alexandre Morignot a rédigé
      Links are now registered in a database !
      Its configurtion muste be
      defined in the database section in the config file. The migration for
      the database can be done simply using "rake".
      
      The config file has moved !
      He must be located at "~/.playbot/config".
      
      Site Plugins return value has changed !
      The hash must contain a new key "url". It allow the plugin to normalize
      it if many different url can link to a same content.
      ce3c9efa
      Historique
      Database support, new config file location
      Alexandre Morignot a rédigé
      Links are now registered in a database !
      Its configurtion muste be
      defined in the database section in the config file. The migration for
      the database can be done simply using "rake".
      
      The config file has moved !
      He must be located at "~/.playbot/config".
      
      Site Plugins return value has changed !
      The hash must contain a new key "url". It allow the plugin to normalize
      it if many different url can link to a same content.
    soundcloud_plugin.rb 660 o
    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)
            url.gsub(/http:\/\//, 'https://')
    
            {:title => track.title, :author => track.user.username, :url => url}
        end
    end