Created
May 1, 2018 01:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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