mirror of
				https://gitea.invidious.io/iv-org/invidious.git
				synced 2024-08-15 00:53:41 +00:00 
			
		
		
		
	More linting
This commit is contained in:
		
							parent
							
								
									b49ed65a07
								
							
						
					
					
						commit
						45b8f6d0cd
					
				
					 1 changed files with 37 additions and 37 deletions
				
			
		|  | @ -92,50 +92,50 @@ module Invidious::Routes::API::V1::Videos | ||||||
|       caption_xml = YT_POOL.client &.get(url).body |       caption_xml = YT_POOL.client &.get(url).body | ||||||
| 
 | 
 | ||||||
|       if caption_xml.starts_with?("<?xml") |       if caption_xml.starts_with?("<?xml") | ||||||
|       	webvtt =caption.timedtext_to_vtt(caption_xml,tlang) |         webvtt = caption.timedtext_to_vtt(caption_xml, tlang) | ||||||
|       else |       else | ||||||
| 	      caption_xml = XML.parse(caption_xml) |         caption_xml = XML.parse(caption_xml) | ||||||
| 	 | 
 | ||||||
| 	      webvtt = String.build do |str| |         webvtt = String.build do |str| | ||||||
| 	        str << <<-END_VTT |           str << <<-END_VTT | ||||||
| 	        WEBVTT | 	        WEBVTT | ||||||
| 	        Kind: captions | 	        Kind: captions | ||||||
| 	        Language: #{tlang || caption.language_code} | 	        Language: #{tlang || caption.language_code} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	        END_VTT | 	        END_VTT | ||||||
| 	 | 
 | ||||||
| 	        caption_nodes = caption_xml.xpath_nodes("//transcript/text") |           caption_nodes = caption_xml.xpath_nodes("//transcript/text") | ||||||
| 	        caption_nodes.each_with_index do |node, i| |           caption_nodes.each_with_index do |node, i| | ||||||
| 	          start_time = node["start"].to_f.seconds |             start_time = node["start"].to_f.seconds | ||||||
| 	          duration = node["dur"]?.try &.to_f.seconds |             duration = node["dur"]?.try &.to_f.seconds | ||||||
| 	          duration ||= start_time |             duration ||= start_time | ||||||
| 	 | 
 | ||||||
| 	          if caption_nodes.size > i + 1 |             if caption_nodes.size > i + 1 | ||||||
| 	            end_time = caption_nodes[i + 1]["start"].to_f.seconds |               end_time = caption_nodes[i + 1]["start"].to_f.seconds | ||||||
| 	          else |             else | ||||||
| 	            end_time = start_time + duration |               end_time = start_time + duration | ||||||
| 	          end |             end | ||||||
| 	 | 
 | ||||||
| 	          start_time = "#{start_time.hours.to_s.rjust(2, '0')}:#{start_time.minutes.to_s.rjust(2, '0')}:#{start_time.seconds.to_s.rjust(2, '0')}.#{start_time.milliseconds.to_s.rjust(3, '0')}" |             start_time = "#{start_time.hours.to_s.rjust(2, '0')}:#{start_time.minutes.to_s.rjust(2, '0')}:#{start_time.seconds.to_s.rjust(2, '0')}.#{start_time.milliseconds.to_s.rjust(3, '0')}" | ||||||
| 	          end_time = "#{end_time.hours.to_s.rjust(2, '0')}:#{end_time.minutes.to_s.rjust(2, '0')}:#{end_time.seconds.to_s.rjust(2, '0')}.#{end_time.milliseconds.to_s.rjust(3, '0')}" |             end_time = "#{end_time.hours.to_s.rjust(2, '0')}:#{end_time.minutes.to_s.rjust(2, '0')}:#{end_time.seconds.to_s.rjust(2, '0')}.#{end_time.milliseconds.to_s.rjust(3, '0')}" | ||||||
| 	 | 
 | ||||||
| 	          text = HTML.unescape(node.content) |             text = HTML.unescape(node.content) | ||||||
| 	          text = text.gsub(/<font color="#[a-fA-F0-9]{6}">/, "") |             text = text.gsub(/<font color="#[a-fA-F0-9]{6}">/, "") | ||||||
| 	          text = text.gsub(/<\/font>/, "") |             text = text.gsub(/<\/font>/, "") | ||||||
| 	          if md = text.match(/(?<name>.*) : (?<text>.*)/) |             if md = text.match(/(?<name>.*) : (?<text>.*)/) | ||||||
| 	            text = "<v #{md["name"]}>#{md["text"]}</v>" |               text = "<v #{md["name"]}>#{md["text"]}</v>" | ||||||
| 	          end |             end | ||||||
| 	 | 
 | ||||||
| 	          str << <<-END_CUE |             str << <<-END_CUE | ||||||
| 	          #{start_time} --> #{end_time} | 	          #{start_time} --> #{end_time} | ||||||
| 	          #{text} | 	          #{text} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	          END_CUE | 	          END_CUE | ||||||
| 	        end |           end | ||||||
| 	      end |         end | ||||||
| 	  end |       end | ||||||
|     else |     else | ||||||
|       # Some captions have "align:[start/end]" and "position:[num]%" |       # Some captions have "align:[start/end]" and "position:[num]%" | ||||||
|       # attributes. Those are causing issues with VideoJS, which is unable |       # attributes. Those are causing issues with VideoJS, which is unable | ||||||
|  | @ -144,11 +144,11 @@ module Invidious::Routes::API::V1::Videos | ||||||
|       # See: https://github.com/iv-org/invidious/issues/2391 |       # See: https://github.com/iv-org/invidious/issues/2391 | ||||||
|       webvtt = YT_POOL.client &.get("#{url}&format=vtt").body |       webvtt = YT_POOL.client &.get("#{url}&format=vtt").body | ||||||
|       if webvtt.starts_with?("<?xml") |       if webvtt.starts_with?("<?xml") | ||||||
| 		webvtt = caption.timedtext_to_vtt(webvtt) |         webvtt = caption.timedtext_to_vtt(webvtt) | ||||||
|       else |       else | ||||||
| 	      webvtt = YT_POOL.client &.get("#{url}&format=vtt").body |         webvtt = YT_POOL.client &.get("#{url}&format=vtt").body | ||||||
| 	        .gsub(/([0-9:.]{12} --> [0-9:.]{12}).+/, "\\1") |           .gsub(/([0-9:.]{12} --> [0-9:.]{12}).+/, "\\1") | ||||||
| 	  end  |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     if title = env.params.query["title"]? |     if title = env.params.query["title"]? | ||||||
|  | @ -371,4 +371,4 @@ module Invidious::Routes::API::V1::Videos | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue