jmbannon / ytdl-sub

Lightweight tool to automate downloading and metadata generation with yt-dlp
https://ytdl-sub.readthedocs.io
GNU General Public License v3.0
1.59k stars 61 forks source link

When using a regex in specifying subtitle languages, FileNotFoundError is thrown #919

Open jacroe opened 5 months ago

jacroe commented 5 months ago

yt-dlp itself supports using regex when specifying a subtitle's language(s). This is potentially helpful when videos may have English subtitles that are more specific than just "English", e.g. "English (United States)". In that case, en != en-US.

When attempting to use a regex with the following configuration, I receive several errors surrounding the fact that the file cannot be found.

subtitles:
  subtitles_name: "Season {season}/{episode_file_name}.{lang}.{subtitles_ext}"
  subtitles_type: "srt"
  embed_subtitles: False
  languages: "en.*"
  allow_auto_generated_subtitles: False
[ytdl-sub:yt-dlp] [Merger] Merging formats into "/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.mkv"
[ytdl-sub:yt-dlp] [debug] ffmpeg command line: /usr/bin/ffmpeg -y -loglevel repeat+info -i file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.f313.webm -i file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.f251.webm -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.temp.mkv
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.f313.webm (pass -k to keep)
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.f251.webm (pass -k to keep)
[ytdl-sub:yt-dlp] [SubtitlesConvertor] Converting subtitles
[ytdl-sub:yt-dlp] [debug] ffmpeg command line: /usr/bin/ffmpeg -y -loglevel repeat+info -i file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en-US.vtt -f srt -movflags +faststart file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en-US.srt
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en-US.vtt (pass -k to keep)
[ytdl-sub:yt-dlp] [Metadata] Adding metadata to "/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.mkv"
[ytdl-sub:yt-dlp] [debug] ffmpeg command line: /usr/bin/ffmpeg -y -loglevel repeat+info -i file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.mkv -i file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.meta -map 0 -dn -ignore_unknown -c copy -map_metadata 1 -movflags +faststart file:/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.temp.mkv
[ytdl-sub:yt-dlp] [debug] Adding to archive: youtube AREK4H8k7Ng
[ytdl-sub] The following error occurred for the subscription linustechtips_tech_upgrade:
Traceback (most recent call last):
  File "/usr/lib/python3.11/shutil.py", line 825, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Cross-device link: '/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en.*.srt' -> '/tv_shows/LTT Tech Upgrade/Season 2022/LTT Tech Upgrade - S2022E0723 - I Did a Terrible Job of This - Intel $5,000 Extreme Tech Upgrade.en.*.srt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/ytdl_sub/utils/file_handler.py", line 406, in move
    shutil.move(src=src_file_path, dst=dst_file_path)
  File "/usr/lib/python3.11/shutil.py", line 845, in move
    copy_function(src, real_dst)
  File "/usr/lib/python3.11/shutil.py", line 436, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en.*.srt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/ytdl_sub/subscriptions/subscription_download.py", line 375, in exception_handling
    yield
  File "/usr/lib/python3.11/site-packages/ytdl_sub/cli/entrypoint.py", line 126, in _download_subscriptions_from_yaml_files
    subscription.download(dry_run=dry_run)
  File "/usr/lib/python3.11/site-packages/ytdl_sub/subscriptions/subscription_download.py", line 362, in download
    return self._process_subscription(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ytdl_sub/subscriptions/subscription_download.py", line 319, in _process_subscription
    self._process_entry(
  File "/usr/lib/python3.11/site-packages/ytdl_sub/subscriptions/subscription_download.py", line 250, in _process_entry
    self._post_process_entry(
  File "/usr/lib/python3.11/site-packages/ytdl_sub/subscriptions/subscription_download.py", line 225, in _post_process_entry
    optional_plugin_entry_metadata = plugin.post_process_entry(entry)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ytdl_sub/plugins/subtitles.py", line 218, in post_process_entry
    self.save_file(
  File "/usr/lib/python3.11/site-packages/ytdl_sub/ytdl_additions/enhanced_download_archive.py", line 737, in save_file
    self._enhanced_download_archive.save_file_to_output_directory(
  File "/usr/lib/python3.11/site-packages/ytdl_sub/ytdl_additions/enhanced_download_archive.py", line 660, in save_file_to_output_directory
    is_modified = self._file_handler.move_file_to_output_directory(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ytdl_sub/utils/file_handler.py", line 478, in move_file_to_output_directory
    self.move(src_file_path=source_file_path, dst_file_path=output_file_path)
  File "/usr/lib/python3.11/site-packages/ytdl_sub/utils/file_handler.py", line 411, in move
    cls.copy(src_file_path, dst_file_path)
  File "/usr/lib/python3.11/site-packages/ytdl_sub/utils/file_handler.py", line 388, in copy
    shutil.copyfile(src=src_file_path, dst=dst_file_path)
  File "/usr/lib/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ytdl-sub-downloads/linustechtips_tech_upgrade/AREK4H8k7Ng.en.*.srt'
[ytdl-sub] Transaction log for linustechtips_tech_upgrade:
Files created:
----------------------------------------
/tv_shows/LTT Tech Upgrade/Season 2022
  LTT Tech Upgrade - S2022E0723 - I Did a Terrible Job of This - Intel $5,000 Extreme Tech Upgrade.en.*.srt
[ytdl-sub] Download Summary:
linustechtips_tech_upgrade     0 0 0     30 FileNotFoundError
Total: 1                       0 0 0     30 Error

Ideally, the subtitle would get saved as LTT Tech Upgrade - S2022E0723 - I Did a Terrible Job of This - Intel $5,000 Extreme Tech Upgrade.en-US..srt as that's the language the subtitle says it is.

I'm running the latest Docker image. If I can provide more details, please let me know.

jmbannon commented 4 months ago

As a workaround, what happens when specifying en-US instead of regex?

jacroe commented 4 months ago

When using en-US, it will grab subs that are marked as "English (United States)" but not subs that are "English". But the subs do get downloaded and named/moved correctly. So as a workaround for now, I have

languages:
  - "en"
  - "en-US"
  - "en-GB"

set.