Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jacroe opened this issue Feb 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jacroe
Copy link

jacroe commented Feb 6, 2024

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
Copy link
Owner

jmbannon commented Feb 8, 2024

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

@jmbannon jmbannon added the bug Something isn't working label Feb 8, 2024
@jacroe
Copy link
Author

jacroe commented Feb 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants