mirror of
				https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
				synced 2024-08-15 00:53:38 +00:00 
			
		
		
		
	Update video extractor
This commit is contained in:
		
							parent
							
								
									4ee3ec09df
								
							
						
					
					
						commit
						ff5d79e3ee
					
				
					 4 changed files with 30 additions and 15 deletions
				
			
		| 
						 | 
					@ -3649,7 +3649,7 @@ get "/api/v1/top" do |env|
 | 
				
			||||||
            generate_thumbnails(json, video.id, config, Kemal.config)
 | 
					            generate_thumbnails(json, video.id, config, Kemal.config)
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          json.field "lengthSeconds", video.info["length_seconds"].to_i
 | 
					          json.field "lengthSeconds", video.length_seconds
 | 
				
			||||||
          json.field "viewCount", video.views
 | 
					          json.field "viewCount", video.views
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          json.field "author", video.author
 | 
					          json.field "author", video.author
 | 
				
			||||||
| 
						 | 
					@ -4494,7 +4494,7 @@ get "/api/manifest/dash/id/:id" do |env|
 | 
				
			||||||
  XML.build(indent: "  ", encoding: "UTF-8") do |xml|
 | 
					  XML.build(indent: "  ", encoding: "UTF-8") do |xml|
 | 
				
			||||||
    xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011",
 | 
					    xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011",
 | 
				
			||||||
      "profiles": "urn:mpeg:dash:profile:full:2011", minBufferTime: "PT1.5S", type: "static",
 | 
					      "profiles": "urn:mpeg:dash:profile:full:2011", minBufferTime: "PT1.5S", type: "static",
 | 
				
			||||||
      mediaPresentationDuration: "PT#{video.info["length_seconds"]}S") do
 | 
					      mediaPresentationDuration: "PT#{video.length_seconds}S") do
 | 
				
			||||||
      xml.element("Period") do
 | 
					      xml.element("Period") do
 | 
				
			||||||
        i = 0
 | 
					        i = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -329,7 +329,7 @@ struct Video
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      json.field "subCountText", self.sub_count_text
 | 
					      json.field "subCountText", self.sub_count_text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      json.field "lengthSeconds", self.info["length_seconds"].to_i
 | 
					      json.field "lengthSeconds", self.length_seconds
 | 
				
			||||||
      json.field "allowRatings", self.allow_ratings
 | 
					      json.field "allowRatings", self.allow_ratings
 | 
				
			||||||
      json.field "rating", self.info["avg_rating"].to_f32
 | 
					      json.field "rating", self.info["avg_rating"].to_f32
 | 
				
			||||||
      json.field "isListed", self.is_listed
 | 
					      json.field "isListed", self.is_listed
 | 
				
			||||||
| 
						 | 
					@ -563,7 +563,14 @@ struct Video
 | 
				
			||||||
        fmt["clen"] = fmt_stream["contentLength"]?.try &.as_s || "0"
 | 
					        fmt["clen"] = fmt_stream["contentLength"]?.try &.as_s || "0"
 | 
				
			||||||
        fmt["bitrate"] = fmt_stream["bitrate"]?.try &.as_i.to_s || "0"
 | 
					        fmt["bitrate"] = fmt_stream["bitrate"]?.try &.as_i.to_s || "0"
 | 
				
			||||||
        fmt["itag"] = fmt_stream["itag"].as_i.to_s
 | 
					        fmt["itag"] = fmt_stream["itag"].as_i.to_s
 | 
				
			||||||
 | 
					        if fmt_stream["url"]?
 | 
				
			||||||
          fmt["url"] = fmt_stream["url"].as_s
 | 
					          fmt["url"] = fmt_stream["url"].as_s
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        if fmt_stream["cipher"]?
 | 
				
			||||||
 | 
					          HTTP::Params.parse(fmt_stream["cipher"].as_s).each do |key, value|
 | 
				
			||||||
 | 
					            fmt[key] = value
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
        fmt["quality"] = fmt_stream["quality"].as_s
 | 
					        fmt["quality"] = fmt_stream["quality"].as_s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if fmt_stream["width"]?
 | 
					        if fmt_stream["width"]?
 | 
				
			||||||
| 
						 | 
					@ -635,8 +642,14 @@ struct Video
 | 
				
			||||||
        fmt["clen"] = adaptive_fmt["contentLength"]?.try &.as_s || "0"
 | 
					        fmt["clen"] = adaptive_fmt["contentLength"]?.try &.as_s || "0"
 | 
				
			||||||
        fmt["bitrate"] = adaptive_fmt["bitrate"]?.try &.as_i.to_s || "0"
 | 
					        fmt["bitrate"] = adaptive_fmt["bitrate"]?.try &.as_i.to_s || "0"
 | 
				
			||||||
        fmt["itag"] = adaptive_fmt["itag"].as_i.to_s
 | 
					        fmt["itag"] = adaptive_fmt["itag"].as_i.to_s
 | 
				
			||||||
 | 
					        if adaptive_fmt["url"]?
 | 
				
			||||||
          fmt["url"] = adaptive_fmt["url"].as_s
 | 
					          fmt["url"] = adaptive_fmt["url"].as_s
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        if adaptive_fmt["cipher"]?
 | 
				
			||||||
 | 
					          HTTP::Params.parse(adaptive_fmt["cipher"].as_s).each do |key, value|
 | 
				
			||||||
 | 
					            fmt[key] = value
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
        if index = adaptive_fmt["indexRange"]?
 | 
					        if index = adaptive_fmt["indexRange"]?
 | 
				
			||||||
          fmt["index"] = "#{index["start"]}-#{index["end"]}"
 | 
					          fmt["index"] = "#{index["start"]}-#{index["end"]}"
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
| 
						 | 
					@ -827,7 +840,7 @@ struct Video
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def length_seconds
 | 
					  def length_seconds
 | 
				
			||||||
    return self.info["length_seconds"].to_i
 | 
					    self.player_response["videoDetails"]["lengthSeconds"].as_s.to_i
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  db_mapping({
 | 
					  db_mapping({
 | 
				
			||||||
| 
						 | 
					@ -1162,17 +1175,19 @@ def fetch_video(id, region)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if info["errorcode"]?.try &.== "2"
 | 
					  if info["errorcode"]?.try &.== "2" || !info["player_response"]
 | 
				
			||||||
    raise "Video unavailable."
 | 
					    raise "Video unavailable."
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if !info["title"]? || info["title"].empty?
 | 
					  if info["reason"]?
 | 
				
			||||||
    raise "Video unavailable."
 | 
					    raise info["reason"]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  title = info["title"]
 | 
					  player_json = JSON.parse(info["player_response"])
 | 
				
			||||||
  author = info["author"]? || ""
 | 
					
 | 
				
			||||||
  ucid = info["ucid"]? || ""
 | 
					  title = player_json["videoDetails"]["title"].as_s
 | 
				
			||||||
 | 
					  author = player_json["videoDetails"]["author"]?.try &.as_s || ""
 | 
				
			||||||
 | 
					  ucid = player_json["videoDetails"]["ucid"]?.try &.as_s || ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  views = html.xpath_node(%q(//meta[@itemprop="interactionCount"]))
 | 
					  views = html.xpath_node(%q(//meta[@itemprop="interactionCount"]))
 | 
				
			||||||
    .try &.["content"].to_i64? || 0_i64
 | 
					    .try &.["content"].to_i64? || 0_i64
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@
 | 
				
			||||||
var video_data = {
 | 
					var video_data = {
 | 
				
			||||||
    id: '<%= video.id %>',
 | 
					    id: '<%= video.id %>',
 | 
				
			||||||
    plid: '<%= plid %>',
 | 
					    plid: '<%= plid %>',
 | 
				
			||||||
    length_seconds: '<%= video.info["length_seconds"].to_f %>',
 | 
					    length_seconds: '<%= video.length_seconds.to_f %>',
 | 
				
			||||||
    video_series: <%= video_series.to_json %>,
 | 
					    video_series: <%= video_series.to_json %>,
 | 
				
			||||||
    params: <%= params.to_json %>,
 | 
					    params: <%= params.to_json %>,
 | 
				
			||||||
    preferences: <%= preferences.to_json %>,
 | 
					    preferences: <%= preferences.to_json %>,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@
 | 
				
			||||||
var video_data = {
 | 
					var video_data = {
 | 
				
			||||||
    id: '<%= video.id %>',
 | 
					    id: '<%= video.id %>',
 | 
				
			||||||
    plid: '<%= plid %>',
 | 
					    plid: '<%= plid %>',
 | 
				
			||||||
    length_seconds: <%= video.info["length_seconds"].to_f %>,
 | 
					    length_seconds: <%= video.length_seconds.to_f %>,
 | 
				
			||||||
    play_next: <%= !rvs.empty? && !plid && params.continue %>,
 | 
					    play_next: <%= !rvs.empty? && !plid && params.continue %>,
 | 
				
			||||||
    next_video: '<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>',
 | 
					    next_video: '<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>',
 | 
				
			||||||
    youtube_comments_text: '<%= HTML.escape(translate(locale, "View YouTube comments")) %>',
 | 
					    youtube_comments_text: '<%= HTML.escape(translate(locale, "View YouTube comments")) %>',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue