Add additional handling for unplayable videos

This commit is contained in:
Omar Roth 2019-09-21 19:58:10 -04:00
parent a006963fb8
commit cfb68e3bff
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2
1 changed files with 16 additions and 16 deletions

View File

@ -316,10 +316,10 @@ struct Video
json.field "premiereTimestamp", self.premiere_timestamp.not_nil!.to_unix
end
if self.player_response["streamingData"]?.try &.["hlsManifestUrl"]?
if player_response["streamingData"]?.try &.["hlsManifestUrl"]?
host_url = make_host_url(config, kemal_config)
hlsvp = self.player_response["streamingData"]["hlsManifestUrl"].as_s
hlsvp = player_response["streamingData"]["hlsManifestUrl"].as_s
hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", host_url)
json.field "hlsUrl", hlsvp
@ -489,7 +489,7 @@ struct Video
end
def live_now
live_now = self.player_response["videoDetails"]?.try &.["isLive"]?.try &.as_bool
live_now = player_response["videoDetails"]?.try &.["isLive"]?.try &.as_bool
if live_now.nil?
return false
@ -536,7 +536,7 @@ struct Video
end
def keywords
keywords = self.player_response["videoDetails"]?.try &.["keywords"]?.try &.as_a
keywords = player_response["videoDetails"]?.try &.["keywords"]?.try &.as_a
keywords ||= [] of String
return keywords
@ -545,7 +545,7 @@ struct Video
def fmt_stream(decrypt_function)
streams = [] of HTTP::Params
if fmt_streams = self.player_response["streamingData"]?.try &.["formats"]?
if fmt_streams = player_response["streamingData"]?.try &.["formats"]?
fmt_streams.as_a.each do |fmt_stream|
if !fmt_stream.as_h?
next
@ -619,7 +619,7 @@ struct Video
def adaptive_fmts(decrypt_function)
adaptive_fmts = [] of HTTP::Params
if fmts = self.player_response["streamingData"]?.try &.["adaptiveFormats"]?
if fmts = player_response["streamingData"]?.try &.["adaptiveFormats"]?
fmts.as_a.each do |adaptive_fmt|
if !adaptive_fmt.as_h?
next
@ -712,12 +712,12 @@ struct Video
end
def storyboards
storyboards = self.player_response["storyboards"]?
storyboards = player_response["storyboards"]?
.try &.as_h
.try &.["playerStoryboardSpecRenderer"]?
if !storyboards
storyboards = self.player_response["storyboards"]?
storyboards = player_response["storyboards"]?
.try &.as_h
.try &.["playerLiveStoryboardSpecRenderer"]?
@ -784,13 +784,8 @@ struct Video
end
def paid
reason = self.player_response["playabilityStatus"]?.try &.["reason"]?
if reason == "This video requires payment to watch."
paid = true
else
paid = false
end
reason = player_response["playabilityStatus"]?.try &.["reason"]?
paid = reason == "This video requires payment to watch." ? true : false
return paid
end
@ -836,7 +831,7 @@ struct Video
end
def length_seconds
self.player_response["videoDetails"]["lengthSeconds"].as_s.to_i
player_response["videoDetails"]["lengthSeconds"].as_s.to_i
end
db_mapping({
@ -1210,6 +1205,11 @@ def fetch_video(id, region)
player_json = JSON.parse(info["player_response"])
reason = player_json["playabilityStatus"]?.try &.["reason"]?.try &.as_s
if reason == "This video is not available."
raise "This video is not available."
end
title = player_json["videoDetails"]["title"].as_s
author = player_json["videoDetails"]["author"]?.try &.as_s || ""
ucid = player_json["videoDetails"]["channelId"]?.try &.as_s || ""