mirror of
				https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
				synced 2024-08-15 00:53:38 +00:00 
			
		
		
		
	Fix chunking for livestream segments
This commit is contained in:
		
							parent
							
								
									28df6881a7
								
							
						
					
					
						commit
						8033d1ca6d
					
				
					 1 changed files with 14 additions and 6 deletions
				
			
		| 
						 | 
					@ -4651,6 +4651,7 @@ get "/videoplayback" do |env|
 | 
				
			||||||
    chunk_end = chunk_start + HTTP_CHUNK_SIZE - 1
 | 
					    chunk_end = chunk_start + HTTP_CHUNK_SIZE - 1
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # TODO: Record bytes written so we can restart after a chunk fails
 | 
				
			||||||
  while true
 | 
					  while true
 | 
				
			||||||
    if !range_end && content_length
 | 
					    if !range_end && content_length
 | 
				
			||||||
      range_end = content_length
 | 
					      range_end = content_length
 | 
				
			||||||
| 
						 | 
					@ -4700,17 +4701,24 @@ get "/videoplayback" do |env|
 | 
				
			||||||
            env.response.headers["Content-Disposition"] = "attachment; filename=\"#{URI.escape(title)}\"; filename*=UTF-8''#{URI.escape(title)}"
 | 
					            env.response.headers["Content-Disposition"] = "attachment; filename=\"#{URI.escape(title)}\"; filename*=UTF-8''#{URI.escape(title)}"
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          content_length = response.headers["Content-Range"].split("/")[-1].to_i64
 | 
					          if !response.headers.includes_word?("Transfer-Encoding", "chunked")
 | 
				
			||||||
          if env.request.headers["Range"]?
 | 
					            content_length = response.headers["Content-Range"].split("/")[-1].to_i64
 | 
				
			||||||
            env.response.headers["Content-Range"] = "bytes #{range_start}-#{range_end || (content_length - 1)}/#{content_length}"
 | 
					            if env.request.headers["Range"]?
 | 
				
			||||||
            env.response.content_length = ((range_end.try &.+ 1) || content_length) - range_start
 | 
					              env.response.headers["Content-Range"] = "bytes #{range_start}-#{range_end || (content_length - 1)}/#{content_length}"
 | 
				
			||||||
          else
 | 
					              env.response.content_length = ((range_end.try &.+ 1) || content_length) - range_start
 | 
				
			||||||
            env.response.content_length = content_length
 | 
					            else
 | 
				
			||||||
 | 
					              env.response.content_length = content_length
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        proxy_file(response, env)
 | 
					        proxy_file(response, env)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # For livestream segments, break after first chunk
 | 
				
			||||||
 | 
					      if url.includes? "&file=seg.ts"
 | 
				
			||||||
 | 
					        break
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    rescue ex
 | 
					    rescue ex
 | 
				
			||||||
      if ex.message != "Error reading socket: Connection reset by peer"
 | 
					      if ex.message != "Error reading socket: Connection reset by peer"
 | 
				
			||||||
        break
 | 
					        break
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue