Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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