mirror of
				https://github.com/devine-dl/devine.git
				synced 2025-11-04 11:54:50 +00:00 
			
		
		
		
	Use new Subtitle.convert() in dl command for --sub-format
This commit is contained in:
		
							parent
							
								
									e76bc7201d
								
							
						
					
					
						commit
						ee56bc87c2
					
				@ -22,7 +22,6 @@ from uuid import UUID
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import jsonpickle
 | 
					import jsonpickle
 | 
				
			||||||
import pycaption
 | 
					 | 
				
			||||||
import yaml
 | 
					import yaml
 | 
				
			||||||
from construct import ConstError
 | 
					from construct import ConstError
 | 
				
			||||||
from pymediainfo import MediaInfo
 | 
					from pymediainfo import MediaInfo
 | 
				
			||||||
@ -583,28 +582,7 @@ class dl:
 | 
				
			|||||||
                with console.status(f"Converting Subtitles to {sub_format.name}..."):
 | 
					                with console.status(f"Converting Subtitles to {sub_format.name}..."):
 | 
				
			||||||
                    for subtitle in title.tracks.subtitles:
 | 
					                    for subtitle in title.tracks.subtitles:
 | 
				
			||||||
                        if subtitle.codec != sub_format:
 | 
					                        if subtitle.codec != sub_format:
 | 
				
			||||||
                            writer = {
 | 
					                            subtitle.convert(sub_format)
 | 
				
			||||||
                                Subtitle.Codec.SubRip: pycaption.SRTWriter,
 | 
					 | 
				
			||||||
                                Subtitle.Codec.SubStationAlpha: None,
 | 
					 | 
				
			||||||
                                Subtitle.Codec.SubStationAlphav4: None,
 | 
					 | 
				
			||||||
                                Subtitle.Codec.TimedTextMarkupLang: pycaption.DFXPWriter,
 | 
					 | 
				
			||||||
                                Subtitle.Codec.WebVTT: pycaption.WebVTTWriter,
 | 
					 | 
				
			||||||
                                # MPEG-DASH box-encapsulated subtitle formats
 | 
					 | 
				
			||||||
                                Subtitle.Codec.fTTML: None,
 | 
					 | 
				
			||||||
                                Subtitle.Codec.fVTT: None,
 | 
					 | 
				
			||||||
                            }[sub_format]
 | 
					 | 
				
			||||||
                            if writer is None:
 | 
					 | 
				
			||||||
                                self.log.error(f"Cannot yet convert {subtitle.codec} to {sub_format.name}...")
 | 
					 | 
				
			||||||
                                sys.exit(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            caption_set = subtitle.parse(subtitle.path.read_bytes(), subtitle.codec)
 | 
					 | 
				
			||||||
                            subtitle.merge_same_cues(caption_set)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            subtitle_text = writer().write(caption_set)
 | 
					 | 
				
			||||||
                            subtitle.path.write_text(subtitle_text, encoding="utf8")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            subtitle.codec = sub_format
 | 
					 | 
				
			||||||
                            subtitle.move(subtitle.path.with_suffix(f".{sub_format.value.lower()}"))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                with console.status("Repackaging tracks with FFMPEG..."):
 | 
					                with console.status("Repackaging tracks with FFMPEG..."):
 | 
				
			||||||
                    has_repacked = False
 | 
					                    has_repacked = False
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user