Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using yt-dlp options in Python
#1
Hello,

Does exist some document that explain how to use yt-dlp options in Python.
There are a lot of options an it's more or less clear how to use it when using tool from command line.
With Python, these options seem less obvious.
For example when I want to download just subtitles (not video) I use this command:
yt-dlp --write-sub --sub-lang fr --skip-download https://www.arte.tv/fr/videos/104769-000...almodovar/
... and it works - only subtitles file is downloaded.

When I try to use skip-download in Python, it doesn't work.
This code downloads both subtitles and video.
import yt_dlp
links = 'https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/'
ydl_opts = {'writesubtitles': True, 'skip-download': True}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download([links])
Reply
#2
use skip_download
Reply
#3
(Jun-28-2022, 04:42 PM)Axel_Erfurt Wrote: use skip_download
Thanks, works
Another oddity appeared.
First it downloaded french subtitles.
Then I tried to use another language by providing another option 'sub-lang': 'en'.
With this I could download english subtitles.
But when I tried again french (i.e. 'sub-lang': 'fr'), the tool contunued to download english.
Reply
#4
Apparently there are 2 version of subtitles for German and French:
Output:
(arte_env1) pavel@ALABAMA:~/arte_env1$ yt-dlp --list-subs --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/ DeprecationWarning: Support for Python version 3.6 has been deprecated and will break in future versions of yt-dlp! Please update to Python 3.7 or above [ArteTV] 104769-000-A: Downloading JSON metadata [ArteTV] 104769-000-A: Downloading m3u8 information [ArteTV] 104769-000-A: Downloading m3u8 information [ArteTV] 104769-000-A: Downloading m3u8 information [ArteTV] 104769-000-A: Downloading m3u8 information [ArteTV] 104769-000-A: Downloading m3u8 information [ArteTV] 104769-000-A: Downloading m3u8 information [info] Available subtitles for 104769-000-A: Language Formats fr vtt, vtt de vtt, vtt en vtt it vtt (arte_env1) pavel@ALABAMA:~/arte_env1$
I suppose that one version (of two) is applied if the video is playing online in French or German and only Spanish words are subtitles.
How to select such version for downloading?
Reply
#5
(Jun-28-2022, 05:34 PM)Pavel_47 Wrote: How to select such version for downloading?
Get a specific language.
yt-dlp --write-sub --sub-lang fr --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar
Get all subs.
yt-dlp --write-sub --all-subs --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/
(Jun-28-2022, 05:34 PM)Pavel_47 Wrote: Does exist some document that explain how to use yt-dlp options in Python.
The original documentation is sparse,but if you search for youtube-dl embedded with python will find tutorials(eg this one ).
I have used this option many times though the years for my Norwegian Tv project and apps with Flask and Click(eg getting mp3 with Click).
Reply
#6
(Jun-29-2022, 12:26 AM)snippsat Wrote:
(Jun-28-2022, 05:34 PM)Pavel_47 Wrote: How to select such version for downloading?
Get a specific language.
yt-dlp --write-sub --sub-lang fr --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar
Get all subs.
yt-dlp --write-sub --all-subs --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/
(Jun-28-2022, 05:34 PM)Pavel_47 Wrote: Does exist some document that explain how to use yt-dlp options in Python.
The original documentation is sparse,but if you search for youtube-dl embedded with python will find tutorials(eg this one ).
I have used this option many times though the years for my Norwegian Tv project and apps with Flask and Click(eg getting mp3 with Click).
Both commands (i.e. specific language and "all subtitles") get "full" French subtitles, i.e. not only Spanish is subtitled , but also French.
The subtitle file size is approximately 98 KB.
If, when playing the video online, you access the "Web Developer Tools" (if you are using Firefox), you can access the actual subtitle file (Network tab and specify vtt in the Filter field), i.e. the file which is used when the video is playing online. If you download this file, you can see that it is much smaller in size than what was downloaded using yt-dlp - around 44KB. This file contains the subtitles for Spanish only. My question is: is it possible to get this file using yt-dlp?
Reply
#7
(Jun-29-2022, 09:23 AM)Pavel_47 Wrote: My question is: is it possible to get this file using yt-dlp?
You get the four languages that see in --list-subs ,no Spanish.
yt-dlp --list-subs --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/
.....
Language Formats
fr       vtt, vtt
de       vtt, vtt
en       vtt
it       vtt
 yt-dlp --write-sub --all-subs --skip-download https://www.arte.tv/fr/videos/104769-000-A/antonio-banderas-et-pedro-almodovar/
.....
Antonio Banderas et Pedro Almodovar [104769-000-A].it.vtt
Antonio Banderas et Pedro Almodovar [104769-000-A].en.vtt
Antonio Banderas et Pedro Almodovar [104769-000-A].de.vtt
Antonio Banderas et Pedro Almodovar [104769-000-A].fr.vtt
This mean that they have not made Spanish official available,if need that have try to scrape from eg FireFox.
Reply
#8
(Jun-29-2022, 11:38 AM)snippsat Wrote: This mean that they have not made Spanish official available,if need that have try to scrape from eg FireFox.
I meant here that somewhere on the resource there is a French .vtt file, which works as follows:
  • It subtitles (in French) the speeches in Spanish, e.g. when Pedro Almodóvar and Antonio Banderas speak Spanish
  • It does not subtitle the speeches in French, e.g. when the background voices speak in French
Such a file exists on the resource, you can access it using "Web Developer Tools" in Firefox.
This file contains the sentences in French that coincide with the speech in Spanish. When the background voice speaks in French, there are no subtitles.
The question is how to access this file from yt-dlp
I didn't mean I was looking for Spanish subtitles!
Reply
#9
Have you noticed that facing 'fr' and 'de' (as opposed to 'en' and 'it') there are 2 vtt.
This probably means that there are two versions of subtitles for French and German (unlike English and Italian).
ARTE is a bilingual French-German channel, so for each emission there are two versions - French and German (which is not the case for English and Italian)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getting options from a html form pgoosen 5 3,259 Jul-03-2019, 06:07 PM
Last Post: nilamo
  HTML select options from python list adi.6194 4 11,662 Oct-20-2016, 01:31 PM
Last Post: adi.6194

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020