2022-07-25 03:00:58 +05:30
|
|
|
enum VideoType
|
|
|
|
Video
|
|
|
|
Livestream
|
|
|
|
Scheduled
|
|
|
|
end
|
|
|
|
|
2019-03-30 03:00:02 +05:30
|
|
|
struct Video
|
2020-07-26 20:28:50 +05:30
|
|
|
include DB::Serializable
|
|
|
|
|
2022-10-04 01:28:52 +05:30
|
|
|
# Version of the JSON structure
|
|
|
|
# It prevents us from loading an incompatible version from cache
|
|
|
|
# (either newer or older, if instances with different versions run
|
|
|
|
# concurrently, e.g during a version upgrade rollout).
|
|
|
|
#
|
|
|
|
# NOTE: don't forget to bump this number if any change is made to
|
|
|
|
# the `params` structure in videos/parser.cr!!!
|
|
|
|
#
|
|
|
|
SCHEMA_VERSION = 2
|
|
|
|
|
2020-07-26 20:28:50 +05:30
|
|
|
property id : String
|
|
|
|
|
|
|
|
@[DB::Field(converter: Video::JSONConverter)]
|
|
|
|
property info : Hash(String, JSON::Any)
|
|
|
|
property updated : Time
|
|
|
|
|
|
|
|
@[DB::Field(ignore: true)]
|
2022-05-24 02:07:58 +05:30
|
|
|
@captions = [] of Invidious::Videos::Caption
|
2020-07-26 20:28:50 +05:30
|
|
|
|
|
|
|
@[DB::Field(ignore: true)]
|
|
|
|
property adaptive_fmts : Array(Hash(String, JSON::Any))?
|
|
|
|
|
|
|
|
@[DB::Field(ignore: true)]
|
|
|
|
property fmt_stream : Array(Hash(String, JSON::Any))?
|
|
|
|
|
|
|
|
@[DB::Field(ignore: true)]
|
|
|
|
property description : String?
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
module JSONConverter
|
2018-08-05 02:00:44 +05:30
|
|
|
def self.from_rs(rs)
|
2020-06-16 04:03:23 +05:30
|
|
|
JSON.parse(rs.read(String)).as_h
|
2018-08-05 02:00:44 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-23 22:33:09 +05:30
|
|
|
# Methods for API v1 JSON
|
2019-04-11 04:28:42 +05:30
|
|
|
|
2022-08-23 22:33:09 +05:30
|
|
|
def to_json(locale : String?, json : JSON::Builder)
|
|
|
|
Invidious::JSONify::APIv1.video(self, json, locale: locale)
|
2019-04-11 04:28:42 +05:30
|
|
|
end
|
|
|
|
|
2021-10-29 18:23:06 +05:30
|
|
|
# TODO: remove the locale and follow the crystal convention
|
2021-11-09 04:22:55 +05:30
|
|
|
def to_json(locale : String?, _json : Nil)
|
2022-08-23 22:33:09 +05:30
|
|
|
JSON.build do |json|
|
|
|
|
Invidious::JSONify::APIv1.video(self, json, locale: locale)
|
|
|
|
end
|
2021-10-29 18:23:06 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def to_json(json : JSON::Builder | Nil = nil)
|
|
|
|
to_json(nil, json)
|
2019-06-09 00:01:41 +05:30
|
|
|
end
|
|
|
|
|
2022-08-23 22:33:09 +05:30
|
|
|
# Misc methods
|
|
|
|
|
2022-07-25 03:00:58 +05:30
|
|
|
def video_type : VideoType
|
|
|
|
video_type = info["videoType"]?.try &.as_s || "video"
|
|
|
|
return VideoType.parse?(video_type) || VideoType::Video
|
2019-03-22 21:02:42 +05:30
|
|
|
end
|
|
|
|
|
2022-10-04 01:28:52 +05:30
|
|
|
def schema_version : Int
|
|
|
|
return info["version"]?.try &.as_i || 1
|
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def published : Time
|
2022-07-25 03:00:58 +05:30
|
|
|
return info["published"]?
|
2022-01-21 02:52:48 +05:30
|
|
|
.try { |t| Time.parse(t.as_s, "%Y-%m-%d", Time::Location::UTC) } || Time.utc
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
2019-03-22 21:02:42 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def published=(other : Time)
|
2022-07-25 03:00:58 +05:30
|
|
|
info["published"] = JSON::Any.new(other.to_s("%Y-%m-%d"))
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
2019-03-22 21:36:58 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def live_now
|
2022-07-25 03:00:58 +05:30
|
|
|
return (self.video_type == VideoType::Livestream)
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
2019-03-22 22:54:47 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def premiere_timestamp : Time?
|
2022-01-21 02:52:48 +05:30
|
|
|
info
|
|
|
|
.dig?("microformat", "playerMicroformatRenderer", "liveBroadcastDetails", "startTimestamp")
|
|
|
|
.try { |t| Time.parse_rfc3339(t.as_s) }
|
2019-03-22 21:36:58 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def related_videos
|
|
|
|
info["relatedVideos"]?.try &.as_a.map { |h| h.as_h.transform_values &.as_s } || [] of Hash(String, String)
|
|
|
|
end
|
2019-02-26 04:58:35 +05:30
|
|
|
|
2022-07-25 03:00:58 +05:30
|
|
|
# Methods for parsing streaming data
|
2019-02-26 04:58:35 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def fmt_stream
|
|
|
|
return @fmt_stream.as(Array(Hash(String, JSON::Any))) if @fmt_stream
|
2020-07-26 20:28:50 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
fmt_stream = info["streamingData"]?.try &.["formats"]?.try &.as_a.map &.as_h || [] of Hash(String, JSON::Any)
|
|
|
|
fmt_stream.each do |fmt|
|
|
|
|
if s = (fmt["cipher"]? || fmt["signatureCipher"]?).try { |h| HTTP::Params.parse(h.as_s) }
|
|
|
|
s.each do |k, v|
|
|
|
|
fmt[k] = JSON::Any.new(v)
|
2019-02-26 04:58:35 +05:30
|
|
|
end
|
2020-09-27 22:49:44 +05:30
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}#{DECRYPT_FUNCTION.decrypt_signature(fmt)}")
|
2018-08-05 09:37:38 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}&host=#{URI.parse(fmt["url"].as_s).host}")
|
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}®ion=#{self.info["region"]}") if self.info["region"]?
|
2018-08-05 09:37:38 +05:30
|
|
|
end
|
2022-04-27 03:50:48 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
fmt_stream.sort_by! { |f| f["width"]?.try &.as_i || 0 }
|
|
|
|
@fmt_stream = fmt_stream
|
|
|
|
return @fmt_stream.as(Array(Hash(String, JSON::Any)))
|
2018-08-05 09:37:38 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def adaptive_fmts
|
|
|
|
return @adaptive_fmts.as(Array(Hash(String, JSON::Any))) if @adaptive_fmts
|
|
|
|
fmt_stream = info["streamingData"]?.try &.["adaptiveFormats"]?.try &.as_a.map &.as_h || [] of Hash(String, JSON::Any)
|
|
|
|
fmt_stream.each do |fmt|
|
|
|
|
if s = (fmt["cipher"]? || fmt["signatureCipher"]?).try { |h| HTTP::Params.parse(h.as_s) }
|
|
|
|
s.each do |k, v|
|
|
|
|
fmt[k] = JSON::Any.new(v)
|
2018-09-13 09:01:47 +05:30
|
|
|
end
|
2020-09-27 22:49:44 +05:30
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}#{DECRYPT_FUNCTION.decrypt_signature(fmt)}")
|
2018-09-13 09:01:47 +05:30
|
|
|
end
|
2018-08-05 09:37:38 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}&host=#{URI.parse(fmt["url"].as_s).host}")
|
|
|
|
fmt["url"] = JSON::Any.new("#{fmt["url"]}®ion=#{self.info["region"]}") if self.info["region"]?
|
2018-10-02 05:31:44 +05:30
|
|
|
end
|
2022-04-27 03:50:48 +05:30
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
fmt_stream.sort_by! { |f| f["width"]?.try &.as_i || 0 }
|
|
|
|
@adaptive_fmts = fmt_stream
|
|
|
|
return @adaptive_fmts.as(Array(Hash(String, JSON::Any)))
|
2018-08-05 09:37:38 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def video_streams
|
|
|
|
adaptive_fmts.select &.["mimeType"]?.try &.as_s.starts_with?("video")
|
2018-08-05 09:37:38 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def audio_streams
|
|
|
|
adaptive_fmts.select &.["mimeType"]?.try &.as_s.starts_with?("audio")
|
2018-08-18 22:17:16 +05:30
|
|
|
end
|
|
|
|
|
2022-07-25 03:00:58 +05:30
|
|
|
# Misc. methods
|
|
|
|
|
2019-04-12 03:30:00 +05:30
|
|
|
def storyboards
|
2022-01-21 02:52:48 +05:30
|
|
|
storyboards = info.dig?("storyboards", "playerStoryboardSpecRenderer", "spec")
|
|
|
|
.try &.as_s.split("|")
|
2019-04-12 03:30:00 +05:30
|
|
|
|
|
|
|
if !storyboards
|
2022-01-21 02:52:48 +05:30
|
|
|
if storyboard = info.dig?("storyboards", "playerLiveStoryboardSpecRenderer", "spec").try &.as_s
|
2019-04-12 03:30:00 +05:30
|
|
|
return [{
|
2019-04-19 02:53:50 +05:30
|
|
|
url: storyboard.split("#")[0],
|
|
|
|
width: 106,
|
|
|
|
height: 60,
|
|
|
|
count: -1,
|
|
|
|
interval: 5000,
|
|
|
|
storyboard_width: 3,
|
|
|
|
storyboard_height: 3,
|
|
|
|
storyboard_count: -1,
|
|
|
|
}]
|
2019-04-12 03:30:00 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
items = [] of NamedTuple(
|
|
|
|
url: String,
|
|
|
|
width: Int32,
|
|
|
|
height: Int32,
|
|
|
|
count: Int32,
|
|
|
|
interval: Int32,
|
|
|
|
storyboard_width: Int32,
|
|
|
|
storyboard_height: Int32,
|
|
|
|
storyboard_count: Int32)
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
return items if !storyboards
|
2019-04-12 03:30:00 +05:30
|
|
|
|
2019-05-27 05:25:22 +05:30
|
|
|
url = URI.parse(storyboards.shift)
|
|
|
|
params = HTTP::Params.parse(url.query || "")
|
2019-04-12 03:30:00 +05:30
|
|
|
|
2022-01-20 21:47:22 +05:30
|
|
|
storyboards.each_with_index do |sb, i|
|
|
|
|
width, height, count, storyboard_width, storyboard_height, interval, _, sigh = sb.split("#")
|
2019-05-27 05:25:22 +05:30
|
|
|
params["sigh"] = sigh
|
|
|
|
url.query = params.to_s
|
2019-04-12 03:30:00 +05:30
|
|
|
|
|
|
|
width = width.to_i
|
|
|
|
height = height.to_i
|
|
|
|
count = count.to_i
|
|
|
|
interval = interval.to_i
|
|
|
|
storyboard_width = storyboard_width.to_i
|
|
|
|
storyboard_height = storyboard_height.to_i
|
2019-10-04 19:53:02 +05:30
|
|
|
storyboard_count = (count / (storyboard_width * storyboard_height)).ceil.to_i
|
2019-04-12 03:30:00 +05:30
|
|
|
|
|
|
|
items << {
|
2019-05-27 05:25:22 +05:30
|
|
|
url: url.to_s.sub("$L", i).sub("$N", "M$M"),
|
2019-04-12 03:30:00 +05:30
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
count: count,
|
|
|
|
interval: interval,
|
|
|
|
storyboard_width: storyboard_width,
|
|
|
|
storyboard_height: storyboard_height,
|
2019-10-04 19:53:02 +05:30
|
|
|
storyboard_count: storyboard_count,
|
2019-04-12 03:30:00 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
items
|
|
|
|
end
|
|
|
|
|
2021-08-15 14:08:30 +05:30
|
|
|
def paid
|
2022-07-25 03:00:58 +05:30
|
|
|
return (self.reason || "").includes? "requires payment"
|
2021-08-15 14:08:30 +05:30
|
|
|
end
|
|
|
|
|
2018-10-16 21:45:14 +05:30
|
|
|
def premium
|
2020-06-16 04:03:23 +05:30
|
|
|
keywords.includes? "YouTube Red"
|
|
|
|
end
|
|
|
|
|
2022-05-24 02:07:58 +05:30
|
|
|
def captions : Array(Invidious::Videos::Caption)
|
|
|
|
if @captions.empty? && @info.has_key?("captions")
|
|
|
|
@captions = Invidious::Videos::Caption.from_yt_json(info["captions"])
|
2019-08-05 07:26:24 +05:30
|
|
|
end
|
2022-05-24 02:07:58 +05:30
|
|
|
|
|
|
|
return @captions
|
2018-10-16 21:45:14 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def hls_manifest_url : String?
|
2022-01-21 02:52:48 +05:30
|
|
|
info.dig?("streamingData", "hlsManifestUrl").try &.as_s
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def dash_manifest_url
|
2022-01-21 02:52:48 +05:30
|
|
|
info.dig?("streamingData", "dashManifestUrl").try &.as_s
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
|
|
|
|
2020-06-17 04:21:49 +05:30
|
|
|
def genre_url : String?
|
|
|
|
info["genreUcid"]? ? "/channel/#{info["genreUcid"]}" : nil
|
2020-06-16 04:03:23 +05:30
|
|
|
end
|
|
|
|
|
2021-08-13 00:56:50 +05:30
|
|
|
def is_vr : Bool?
|
2022-07-25 03:00:58 +05:30
|
|
|
return {"EQUIRECTANGULAR", "MESH"}.includes? self.projection_type
|
2021-09-10 13:12:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def projection_type : String?
|
|
|
|
return info.dig?("streamingData", "adaptiveFormats", 0, "projectionType").try &.as_s
|
2021-04-11 18:39:10 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
def reason : String?
|
|
|
|
info["reason"]?.try &.as_s
|
|
|
|
end
|
2022-07-25 03:00:58 +05:30
|
|
|
|
2023-01-16 18:28:05 +05:30
|
|
|
def music : Array(VideoMusic)
|
2023-01-22 04:42:04 +05:30
|
|
|
info["music"].as_a.map { |music_json|
|
2023-03-08 00:53:08 +05:30
|
|
|
VideoMusic.new(
|
|
|
|
music_json["song"].as_s,
|
|
|
|
music_json["album"].as_s,
|
|
|
|
music_json["artist"].as_s,
|
|
|
|
music_json["license"].as_s
|
|
|
|
)
|
2023-01-22 04:42:04 +05:30
|
|
|
}
|
2023-01-16 18:28:05 +05:30
|
|
|
end
|
|
|
|
|
2022-07-25 03:00:58 +05:30
|
|
|
# Macros defining getters/setters for various types of data
|
|
|
|
|
|
|
|
private macro getset_string(name)
|
|
|
|
# Return {{name.stringify}} from `info`
|
|
|
|
def {{name.id.underscore}} : String
|
|
|
|
return info[{{name.stringify}}]?.try &.as_s || ""
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update {{name.stringify}} into `info`
|
|
|
|
def {{name.id.underscore}}=(value : String)
|
|
|
|
info[{{name.stringify}}] = JSON::Any.new(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
{% if flag?(:debug_macros) %} {{debug}} {% end %}
|
|
|
|
end
|
|
|
|
|
|
|
|
private macro getset_string_array(name)
|
|
|
|
# Return {{name.stringify}} from `info`
|
|
|
|
def {{name.id.underscore}} : Array(String)
|
|
|
|
return info[{{name.stringify}}]?.try &.as_a.map &.as_s || [] of String
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update {{name.stringify}} into `info`
|
|
|
|
def {{name.id.underscore}}=(value : Array(String))
|
|
|
|
info[{{name.stringify}}] = JSON::Any.new(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
{% if flag?(:debug_macros) %} {{debug}} {% end %}
|
|
|
|
end
|
|
|
|
|
|
|
|
{% for op, type in {i32: Int32, i64: Int64} %}
|
|
|
|
private macro getset_{{op}}(name)
|
|
|
|
def \{{name.id.underscore}} : {{type}}
|
2022-11-16 22:48:35 +05:30
|
|
|
return info[\{{name.stringify}}]?.try &.as_i64.to_{{op}} || 0_{{op}}
|
2022-07-25 03:00:58 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def \{{name.id.underscore}}=(value : Int)
|
|
|
|
info[\{{name.stringify}}] = JSON::Any.new(value.to_i64)
|
|
|
|
end
|
|
|
|
|
|
|
|
\{% if flag?(:debug_macros) %} \{{debug}} \{% end %}
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
private macro getset_bool(name)
|
|
|
|
# Return {{name.stringify}} from `info`
|
|
|
|
def {{name.id.underscore}} : Bool
|
|
|
|
return info[{{name.stringify}}]?.try &.as_bool || false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update {{name.stringify}} into `info`
|
|
|
|
def {{name.id.underscore}}=(value : Bool)
|
|
|
|
info[{{name.stringify}}] = JSON::Any.new(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
{% if flag?(:debug_macros) %} {{debug}} {% end %}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method definitions, using the macros above
|
|
|
|
|
|
|
|
getset_string author
|
|
|
|
getset_string authorThumbnail
|
|
|
|
getset_string description
|
|
|
|
getset_string descriptionHtml
|
|
|
|
getset_string genre
|
|
|
|
getset_string genreUcid
|
|
|
|
getset_string license
|
|
|
|
getset_string shortDescription
|
|
|
|
getset_string subCountText
|
|
|
|
getset_string title
|
|
|
|
getset_string ucid
|
|
|
|
|
|
|
|
getset_string_array allowedRegions
|
|
|
|
getset_string_array keywords
|
|
|
|
|
|
|
|
getset_i32 lengthSeconds
|
|
|
|
getset_i64 likes
|
|
|
|
getset_i64 views
|
|
|
|
|
|
|
|
getset_bool allowRatings
|
|
|
|
getset_bool authorVerified
|
|
|
|
getset_bool isFamilyFriendly
|
|
|
|
getset_bool isListed
|
|
|
|
getset_bool isUpcoming
|
2020-07-26 20:28:50 +05:30
|
|
|
end
|
2018-10-21 07:07:55 +05:30
|
|
|
|
2021-12-07 07:25:43 +05:30
|
|
|
def get_video(id, refresh = true, region = nil, force_refresh = false)
|
2021-11-27 00:06:31 +05:30
|
|
|
if (video = Invidious::Database::Videos.select(id)) && !region
|
2020-06-16 04:03:23 +05:30
|
|
|
# If record was last updated over 10 minutes ago, or video has since premiered,
|
|
|
|
# refresh (expire param in response lasts for 6 hours)
|
|
|
|
if (refresh &&
|
|
|
|
(Time.utc - video.updated > 10.minutes) ||
|
|
|
|
(video.premiere_timestamp.try &.< Time.utc)) ||
|
2022-10-04 01:28:52 +05:30
|
|
|
force_refresh ||
|
|
|
|
video.schema_version != Video::SCHEMA_VERSION # cache control
|
2020-06-16 04:03:23 +05:30
|
|
|
begin
|
|
|
|
video = fetch_video(id, region)
|
2021-11-27 00:06:31 +05:30
|
|
|
Invidious::Database::Videos.update(video)
|
2020-06-16 04:03:23 +05:30
|
|
|
rescue ex
|
2021-11-27 00:06:31 +05:30
|
|
|
Invidious::Database::Videos.delete(id)
|
2020-06-16 04:03:23 +05:30
|
|
|
raise ex
|
|
|
|
end
|
2019-02-07 03:42:11 +05:30
|
|
|
end
|
|
|
|
else
|
2020-06-16 04:03:23 +05:30
|
|
|
video = fetch_video(id, region)
|
2021-11-27 00:06:31 +05:30
|
|
|
Invidious::Database::Videos.insert(video) if !region
|
2018-08-05 02:00:44 +05:30
|
|
|
end
|
|
|
|
|
2020-06-16 04:03:23 +05:30
|
|
|
return video
|
2022-04-09 02:22:34 +05:30
|
|
|
rescue DB::Error
|
|
|
|
# Avoid common `DB::PoolRetryAttemptsExceeded` error and friends
|
|
|
|
# Note: All DB errors inherit from `DB::Error`
|
|
|
|
return fetch_video(id, region)
|
2019-02-07 03:42:11 +05:30
|
|
|
end
|
|
|
|
|
2019-06-29 07:47:56 +05:30
|
|
|
def fetch_video(id, region)
|
2021-08-14 01:59:43 +05:30
|
|
|
info = extract_video_info(video_id: id)
|
2018-10-07 08:52:22 +05:30
|
|
|
|
2021-08-14 01:59:43 +05:30
|
|
|
allowed_regions = info
|
|
|
|
.dig?("microformat", "playerMicroformatRenderer", "availableCountries")
|
|
|
|
.try &.as_a.map &.as_s || [] of String
|
2019-08-14 01:51:00 +05:30
|
|
|
|
|
|
|
# Check for region-blocks
|
2020-06-16 04:03:23 +05:30
|
|
|
if info["reason"]?.try &.as_s.includes?("your country")
|
2019-08-19 19:30:37 +05:30
|
|
|
bypass_regions = PROXY_LIST.keys & allowed_regions
|
|
|
|
if !bypass_regions.empty?
|
|
|
|
region = bypass_regions[rand(bypass_regions.size)]
|
2021-08-14 01:59:43 +05:30
|
|
|
region_info = extract_video_info(video_id: id, proxy_region: region)
|
2020-06-16 04:03:23 +05:30
|
|
|
region_info["region"] = JSON::Any.new(region) if region
|
|
|
|
info = region_info if !region_info["reason"]?
|
2019-08-19 19:30:37 +05:30
|
|
|
end
|
2018-08-13 19:47:28 +05:30
|
|
|
end
|
|
|
|
|
2022-02-11 11:13:14 +05:30
|
|
|
if reason = info["reason"]?
|
2022-05-27 19:06:13 +05:30
|
|
|
if reason == "Video unavailable"
|
|
|
|
raise NotFoundException.new(reason.as_s || "")
|
|
|
|
else
|
|
|
|
raise InfoException.new(reason.as_s || "")
|
|
|
|
end
|
2022-02-11 11:13:14 +05:30
|
|
|
end
|
2018-08-05 02:00:44 +05:30
|
|
|
|
2020-07-26 20:28:50 +05:30
|
|
|
video = Video.new({
|
|
|
|
id: id,
|
|
|
|
info: info,
|
|
|
|
updated: Time.utc,
|
|
|
|
})
|
|
|
|
|
2018-08-05 02:00:44 +05:30
|
|
|
return video
|
|
|
|
end
|
|
|
|
|
2021-12-07 07:25:43 +05:30
|
|
|
def process_continuation(query, plid, id)
|
2019-08-06 05:19:13 +05:30
|
|
|
continuation = nil
|
|
|
|
if plid
|
|
|
|
if index = query["index"]?.try &.to_i?
|
|
|
|
continuation = index
|
|
|
|
else
|
|
|
|
continuation = id
|
|
|
|
end
|
|
|
|
continuation ||= 0
|
|
|
|
end
|
|
|
|
|
|
|
|
continuation
|
|
|
|
end
|
|
|
|
|
2020-06-16 03:40:30 +05:30
|
|
|
def build_thumbnails(id)
|
2019-03-09 02:12:37 +05:30
|
|
|
return {
|
2021-04-01 05:53:59 +05:30
|
|
|
{host: HOST_URL, height: 720, width: 1280, name: "maxres", url: "maxres"},
|
|
|
|
{host: HOST_URL, height: 720, width: 1280, name: "maxresdefault", url: "maxresdefault"},
|
|
|
|
{host: HOST_URL, height: 480, width: 640, name: "sddefault", url: "sddefault"},
|
|
|
|
{host: HOST_URL, height: 360, width: 480, name: "high", url: "hqdefault"},
|
|
|
|
{host: HOST_URL, height: 180, width: 320, name: "medium", url: "mqdefault"},
|
|
|
|
{host: HOST_URL, height: 90, width: 120, name: "default", url: "default"},
|
|
|
|
{host: HOST_URL, height: 90, width: 120, name: "start", url: "1"},
|
|
|
|
{host: HOST_URL, height: 90, width: 120, name: "middle", url: "2"},
|
|
|
|
{host: HOST_URL, height: 90, width: 120, name: "end", url: "3"},
|
2019-03-09 02:12:37 +05:30
|
|
|
}
|
|
|
|
end
|