Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Question : Extract the video title without additional requests? #4988
Comments
|
You don't need any of the advanced options / hooks for that. Simply call
|
|
Thanks for the information but my question is how to Download the video and extract the information in a single step without multiple page-fetches. The below works for me but is slow and also ignores the
|
|
import youtube_dl
url = 'test:youtube'
ydl_options = {
'outtmpl': '%(title)s-%(id)s.%(ext)s',
'format': 'bestaudio',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'continuedl': True,
'quiet' : True,
'restrictfilenames':True,
}
def hook(s):
print(s)
with youtube_dl.YoutubeDL(ydl_options) as ydl:
try:
ydl.add_default_info_extractors()
ydl.add_progress_hook(hook)
info = ydl.extract_info(url,
download=True # it's the default value, but to make it clearer
)
print(info['title'])
except (youtube_dl.utils.DownloadError,youtube_dl.utils.ContentTooShortError,youtube_dl.utils.ExtractorError) as e:
self.error_occured = True
self.statusSignal.emit(str(e))The reason why it downloads the video again is that the postprocessor deletes the original file, so we can't detect if it has been downloaded, you can use the |
|
Thanks @jaimeMF, this works but does not prints the title nor emits the signal!!!
|
|
I have adapted the script to remove the import youtube_dl
def download(url):
#self.statusSignal.emit('Starting...')
ydl_options = {
'outtmpl': '%(title)s-%(id)s.%(ext)s',
'format': 'bestaudio',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'continuedl': True,
'quiet' : True,
'restrictfilenames':True,
}
def hook(s):
print(s)
with youtube_dl.YoutubeDL(ydl_options) as ydl:
try:
ydl.add_default_info_extractors()
ydl.add_progress_hook(hook)
info = ydl.extract_info(url, download=True )
print(info['title'])
except (youtube_dl.utils.DownloadError,youtube_dl.utils.ContentTooShortError,youtube_dl.utils.ExtractorError) as e:
print(e)
download('test:youtube')Could you try with that script and post the output? |
I would like to know how to extract the video title without additional requests using the official example as below: