Sha256: fd58a1c347fab7b08b0466d240ba1b664637edbbe6ef3c8d759572da891f980e

Contents?: true

Size: 779 Bytes

Versions: 9

Compression:

Stored size: 779 Bytes

Contents

# Blatently copied from: https://github.com/prep/magnet-uri

require 'cgi'
require 'uri'

module FeedTorrents
  module Feed
    class MagnetURI
      def initialize(uri)
        raise ArgumentError, 'bad argument (expected magnet URI)' unless uri =~ /^magnet:\?/

        uri = CGI.unescapeHTML(uri)

        scheme, params = uri.split('?', 2)

        @params = {}.tap do |param|
          CGI.parse(URI.decode(params)).each do |name, value|
            name  = name.to_sym
            value = (value.size == 1 ? value.first : value)

            param[name] = value
          end
        end

        @info_hash = @params[:xt].split(':').last
      end

      def reflektor_link
        "http://reflektor.karmorra.info/torrent/#{@info_hash}.torrent"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
feed_torrents-0.2.2 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.2.1 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.2.0 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.5 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.4 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.3 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.2 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.1 lib/feed_torrents/feed/magnet-uri.rb
feed_torrents-0.1.0 lib/feed_torrents/feed/magnet-uri.rb