Sha256: ceac7707f02230127d93071c5aaadd314d4f447f9126034ef0dbbb4926776e3c

Contents?: true

Size: 793 Bytes

Versions: 2

Compression:

Stored size: 793 Bytes

Contents

require 'youtube_to_rss/version'

module YoutubeToRss
  class Error < StandardError; end

  class << self
    def convert(url)
      url = remove_query_strings(url)
      base_url = 'https://www.youtube.com/feeds/videos.xml?'

      if url.include?('/channel/')
        "#{base_url}channel_id=#{extract_param(url, '/channel/')}"
      elsif url.include?('/c/')
          "#{base_url}channel_id=#{extract_param(url, '/c/')}"
      elsif url.include?('/user/')
        "#{base_url}user=#{extract_param(url, '/user/')}"
      else
        raise 'URL should have "channel" or "c" or "user" param.'
      end
    end

    private

    def extract_param(url, param)
      url.split(param).last
    end

    def remove_query_strings(url)
      url.split('?').first.split('&').first
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
youtube_to_rss-0.2 lib/youtube_to_rss.rb
youtube_to_rss-0.1.2 lib/youtube_to_rss.rb