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

Cant download the dataset now. #14

Open
rohaantahir opened this issue Mar 17, 2023 · 11 comments
Open

Cant download the dataset now. #14

rohaantahir opened this issue Mar 17, 2023 · 11 comments

Comments

@rohaantahir
Copy link

Hi I want to use this dataset, Can you please guide me how to download I tried to download using script but it fails.

@Suvi-dha
Copy link

Suvi-dha commented Mar 29, 2023

Try yt-dlp instead of youtube-dl (line no. 169) after installing yt-dlp
pip install yt-dlp

@rohaantahir
Copy link
Author

sure thanks

@rohaantahir
Copy link
Author

@Suvi-dha can you please tell the exact file name where it needs to be changed?

@Suvi-dha
Copy link

@rohaantahir
here,
https://github.com/universome/HDTF/blob/main/download.py#L171

@auroraxs
Copy link

The video downloaded has no audio, how to solve it?

@auroraxs
Copy link

The video downloaded has no audio, how to solve it?

change the doanload_video function as below can download video with audio
`import os
import subprocess

def download_video(video_id, download_path, resolution: int=None, video_format="mp4", log_file=None):
"""
Download video with audio from YouTube.
:param video_id: YouTube ID of the video.
:param download_path: Where to save the video.
:param video_format: Format to download.
:param log_file: Path to a log file for youtube-dl.
:return: Tuple: path to the downloaded video and a bool indicating success.

Copy-pasted from https://github.com/ytdl-org/youtube-dl
"""
if os.path.isfile(download_path): return True # File already exists

if log_file is None:
    stderr = subprocess.DEVNULL
else:
    stderr = open(log_file, "a")

video_selection = f"bestvideo[ext={video_format}]+bestaudio[ext=m4a]/best[ext={video_format}]"
video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"

command = [
    "youtube-dl",
    "https://youtube.com/watch?v={}".format(video_id), "--quiet", "-f",
    video_selection,
    "--output", download_path,
    "--no-continue",
    "--merge-output-format", video_format
]

print(command)

return_code = subprocess.call(command, stderr=stderr)
success = return_code == 0

if log_file is not None:
    stderr.close()

return success and os.path.isfile(download_path)

`

@justin4ai
Copy link

@moyusxs Thanks to your code, the error doesn't occur. But still there are no video or audio files created in the output folder. Do you have any idea about this?

@Cuiyuhang001
Copy link

You can try the following code
`
def download_video(video_id, download_path, resolution: int=None, video_format="mp4", log_file=None):
"""
Download video from YouTube.
:param video_id: YouTube ID of the video.
:param download_path: Where to save the video.
:param video_format: Format to download.
:param log_file: Path to a log file for youtube-dl.
:return: Tuple: path to the downloaded video and a bool indicating success.

Copy-pasted from https://github.com/ytdl-org/youtube-dl
"""
# if os.path.isfile(download_path): return True # File already exists

if log_file is None:
    stderr = subprocess.DEVNULL
else:
    stderr = open(log_file, "a")
# video_selection = f"bestvideo[ext={video_format}]"
# video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"

video_selection = f"bestvideo[ext={video_format}]+bestaudio[ext=m4a]/best[ext={video_format}]"
video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"
command = [
    "yt-dlp",
    "https://youtube.com/watch?v={}".format(video_id), "--quiet", "-f",
    video_selection,
    "--output", download_path,
    "--no-continue"
]
return_code = subprocess.call(command, stderr=stderr)
success = return_code == 0

if log_file is not None:
    stderr.close()

return success and os.path.isfile(download_path)

`
Download yt-dlp and replace youtube dl, modify download parameters to download videos with audio

@justin4ai
Copy link

You can try the following code ` def download_video(video_id, download_path, resolution: int=None, video_format="mp4", log_file=None): """ Download video from YouTube. :param video_id: YouTube ID of the video. :param download_path: Where to save the video. :param video_format: Format to download. :param log_file: Path to a log file for youtube-dl. :return: Tuple: path to the downloaded video and a bool indicating success.

Copy-pasted from https://github.com/ytdl-org/youtube-dl
"""
# if os.path.isfile(download_path): return True # File already exists

if log_file is None:
    stderr = subprocess.DEVNULL
else:
    stderr = open(log_file, "a")
# video_selection = f"bestvideo[ext={video_format}]"
# video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"

video_selection = f"bestvideo[ext={video_format}]+bestaudio[ext=m4a]/best[ext={video_format}]"
video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"
command = [
    "yt-dlp",
    "https://youtube.com/watch?v={}".format(video_id), "--quiet", "-f",
    video_selection,
    "--output", download_path,
    "--no-continue"
]
return_code = subprocess.call(command, stderr=stderr)
success = return_code == 0

if log_file is not None:
    stderr.close()

return success and os.path.isfile(download_path)

` Download yt-dlp and replace youtube dl, modify download parameters to download videos with audio

Thank you so much! It works. But almost a half of videos are not downloaded generating some txt files. Does this happen to you as well?

@Cuiyuhang001
Copy link

The video link provided by the author is old, and perhaps some of the videos have been removed from the shelves, so they cannot be downloaded. This is my opinion

@1129571
Copy link

1129571 commented Dec 6, 2023

You can try the following code ` def download_video(video_id, download_path, resolution: int=None, video_format="mp4", log_file=None): """ Download video from YouTube. :param video_id: YouTube ID of the video. :param download_path: Where to save the video. :param video_format: Format to download. :param log_file: Path to a log file for youtube-dl. :return: Tuple: path to the downloaded video and a bool indicating success.

Copy-pasted from https://github.com/ytdl-org/youtube-dl
"""
# if os.path.isfile(download_path): return True # File already exists

if log_file is None:
    stderr = subprocess.DEVNULL
else:
    stderr = open(log_file, "a")
# video_selection = f"bestvideo[ext={video_format}]"
# video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"

video_selection = f"bestvideo[ext={video_format}]+bestaudio[ext=m4a]/best[ext={video_format}]"
video_selection = video_selection if resolution is None else f"{video_selection}[height={resolution}]"
command = [
    "yt-dlp",
    "https://youtube.com/watch?v={}".format(video_id), "--quiet", "-f",
    video_selection,
    "--output", download_path,
    "--no-continue"
]
return_code = subprocess.call(command, stderr=stderr)
success = return_code == 0

if log_file is not None:
    stderr.close()

return success and os.path.isfile(download_path)

` Download yt-dlp and replace youtube dl, modify download parameters to download videos with audio

Thank you so much! It works. But almost a half of videos are not downloaded generating some txt files. Does this happen to you as well?

Hello buddy, I downloaded a lot less videos. Have you solved this problem now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants