Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/teletube/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ module Teletube
@client.get_browsable_waveform
when "chapter-markers"
@client.get_browsable_chapter_markers
when "text-tracks"
if context.params.has_key?("format")
@client.get_browsable_text_track
else
@client.get_browsable_text_tracks
end
end
when "config"
@config.attributes = {
Expand Down
32 changes: 31 additions & 1 deletion src/teletube/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module Teletube
if response.status_code == 200
offset = response.headers["Upload-Offset"].to_i
elsif response.status_code == 423
sleep 10
sleep(1.second)
end
end
offset
Expand Down Expand Up @@ -292,6 +292,36 @@ module Teletube
handle_response(@http.get(path: "/api/v1/browse/videos/#{@context.params["video_id"]}/chapter_markers"))
end

def get_browsable_text_tracks
handle_response(@http.get(path: "/api/v1/browse/videos/#{@context.params["video_id"]}/text_tracks"))
end

def get_browsable_text_track
response = get_browsable_text_tracks
if response.status_code == 200
text_tracks = JSON.parse(response.body).as_a
text_tracks.each do |text_track|
if @context.params.has_key?("language")
if @context.params["language"].as_s == text_track["language"].as_s
print_browsable_text_track(text_track)
return
end
else
print_browsable_text_track(text_track)
return
end
end
end
end

def print_browsable_text_track(text_track)
path = text_track["#{@context.params["format"]}_path"].as_s
response = handle_response(@http.get(path: path))
if response.status_code == 200
puts response.body
end
end

def handle_response(response)
STDERR.puts "⚡️ #{response.status} (#{response.status_code})"
puts response.body unless response.body.blank?
Expand Down
12 changes: 12 additions & 0 deletions src/teletube/option_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ module Teletube
context.params["video_id"] = JSON::Any.new(id)
end
end
parser.on("text-tracks", "Show details for the text-tracks for a video.") do
context.command = "text-tracks"
parser.on("--video-id ID", "The public identifier of the video.") do |id|
context.params["video_id"] = JSON::Any.new(id)
end
parser.on("--language LANGUAGE", "Which of the tracks you want to fetch.") do |language|
context.params["language"] = JSON::Any.new(language)
end
parser.on("--format <srt|vvt|txt>", "Which of the tracks you want to fetch.") do |format|
context.params["format"] = JSON::Any.new(format)
end
end
end

parser.separator "Other options:"
Expand Down