作者:gl君 | 来源:互联网 | 2023-10-13 09:21
篇首语:本文由编程笔记#小编为大家整理,主要介绍了ruby 传递一个Twitch集合URL作为参数,它将下载所有这些相关的知识,希望对你有一定的参考价值。
#! /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}"