Skip to content

Instantly share code, notes, and snippets.

@DNA
Created May 1, 2018 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNA/580d2315e89656567946a5431cca6260 to your computer and use it in GitHub Desktop.
Save DNA/580d2315e89656567946a5431cca6260 to your computer and use it in GitHub Desktop.
Pass a Twitch collection URL as an argument and it'll download all of them
#! /usr/bin/env ruby
require 'net/http'
require 'json'
require 'tempfile'
download_list = Tempfile.new
CLIENT_ID = 'TWITCH_CLIENT_ID'
collection_id = ARGV.first.split('/').last
twitch_uri = URI("https://api.twitch.tv/kraken/collections/#{collection_id}/items")
collections = Net::HTTP.start(twitch_uri.hostname, twitch_uri.port, use_ssl: true) do |http|
req = Net::HTTP::Get.new(twitch_uri)
req['Accept'] = 'application/vnd.twitchtv.v5+json'
req['Client-ID'] = CLIENT_ID
JSON.parse(http.request(req).body)
end
collections['items'].each do |collection|
download_list.write "https://www.twitch.tv/videos/#{collection['item_id']}\n"
end
download_list.rewind
download_list.flush
exec "youtube-dl -a #{download_list.path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment