spaam/svtplay-dl

Mutliple subtitles and merging

Closed this issue · 3 comments

andh0g commented

Version: 4.28.1 (latest in git at the time of writing).

The recent changes to downloading caption subtitles in commit f15f366 about two weeks ago changed the file name of the caption files. When merging subtitles with the option -M the old filename is still expected.

Below is one example and its error message. It is clear from the last line that the old name was expected while at the beginning we can see that the caption files includes the new part ".sv" and ".sv-caption" respectively.

$ svtplay-dl -S -M --all-subtitles 'https://www.svtplay.se/video/jmydJyb/30-minuter/avsnitt-9?info=visa'
INFO: Outfile: 30.minuter.s2023e09.avsnitt.9-81d8651-svtplay.sv.srt
INFO: Outfile: 30.minuter.s2023e09.avsnitt.9-81d8651-svtplay.sv-caption.srt
INFO: Outfile: 30.minuter.s2023e09.avsnitt.9-81d8651-svtplay.mp4
INFO: Selected to download dash, bitrate: 5476 format: h264
[453/453][========================================] ETA: 0:00:00
[453/453][========================================] ETA: 0:00:00
INFO: Merge audio, video and subtitle into 30.minuter.s2023e09.avsnitt.9-81d8651-svtplay.mp4
INFO: Determining the language of the subtitle(s).
Traceback (most recent call last):
  File "/home/andersh/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/andersh/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/andersh/bin/svtplay-dl/__main__.py", line 15, in <module>
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/__init__.py", line 69, in main
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/utils/getmedia.py", line 63, in get_media
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/utils/getmedia.py", line 222, in get_one_media
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/postprocess/__init__.py", line 90, in merge
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/postprocess/__init__.py", line 222, in _sublanguage
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/postprocess/__init__.py", line 186, in query
  File "/home/andersh/bin/svtplay-dl/svtplay_dl/postprocess/__init__.py", line 182, in parse
FileNotFoundError: [Errno 2] No such file or directory: '30.minuter.s2023e09.avsnitt.9-81d8651-svtplay.srt'

I also have this issue and an effective workaround for myself to still be able to use svtplay-dl is to disable merging in the config file or enable the "--no-merge" option when running the command.

Here's how my error looks like, running in a Windows 11 environment with python 3.12 installed

C:\ytdl>svtplay-dl -A https://www.svtplay.se/innan-vi-dor
INFO: Episode 1 of 18
INFO: Url: http://www.svtplay.se/video/8rbWRyQ/innan-vi-dor/avsnitt-1
INFO: Outfile: innan.vi.dor.s01e01.avsnitt.1-4fc03a5-svtplay.sv-caption.srt
INFO: Outfile: innan.vi.dor.s01e01.avsnitt.1-4fc03a5-svtplay.sv.srt
INFO: Outfile: innan.vi.dor.s01e01.avsnitt.1-4fc03a5-svtplay.mp4
INFO: Selected to download dash, bitrate: 6021 format: h264-51
[915/915][================================================================================] ETA: 0:00:00
[915/915][================================================================================] ETA: 0:00:00
INFO: Merge audio, video and subtitle into innan.vi.dor.s01e01.avsnitt.1-4fc03a5-svtplay.mkv
INFO: Determining the language of the subtitle(s).
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\Lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 124, in run
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\Lib\site-packages\cx_Freeze\initscripts\console.py", line 16, in run
  File "bin\svtplay-dl", line 7, in <module>
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\__init__.py", line 69, in main
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\utils\getmedia.py", line 61, in get_media
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\utils\getmedia.py", line 93, in get_all_episodes
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\utils\getmedia.py", line 222, in get_one_media
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\postprocess\__init__.py", line 90, in merge
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\postprocess\__init__.py", line 210, in _sublanguage
  File "D:\a\svtplay-dl\svtplay-dl\lib\svtplay_dl\postprocess\__init__.py", line 210, in <listcomp>
AttributeError: 'bool' object has no attribute 'strip'

None of those folders are assigned by me as download paths btw, not sure if that's just part of how the script function or if something is going wrong there.

I wish I could be more helpful but my python knowledge is near nil -_-

Did some digging here, and the problem stems from the fact that m3u files are treated as subtitles in subtitles/__init__.py:

elif subdata.text.startswith("#EXTM3U"):
    m3u8 = M3U8(subdata.text)
    yield subtitle(config, "wrstsegment", url, **kwargs, m3u8=m3u8)

As I have no background in this project I'm not comfortable doing anything here, but in my specific use-case of downloading episodes from SVTPlay with all subtitles and merging to MKV the issue goes away when removing those lines.

The problem, downstream from m3us being identified as subtitles, is that get_all_subtitles gets set to False, which means the subtitle files can't be found. If we handle that, then there's another error when the m3u subtitle file can't be found (which isn't a huge surprise as the m3u file is never really downloaded).

For those who want it, there's a quick fix in my fork.

this should work better now in 4.69 🤔