Skip to content

Commit

Permalink
Mod: Update default backend to download AudioCaps from youtube-dl to …
Browse files Browse the repository at this point in the history
…yt-dlp.
  • Loading branch information
Labbeti committed Oct 4, 2023
1 parent 218fcc7 commit 10a5637
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
## [0.4.1] UNRELEASED
### Changed
- Set log level to WARNING if verbose<=0 in check.py and download.py scripts.
- Update download message for AudioCaps.
- Use `ytdlp` instead of `youtube-dl` as backend to download AudioCaps audio files.

## [0.4.0] 2023-09-25
### Added
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ numpy >= 1.21.2

### External requirements (AudioCaps only)

The external requirements needed to download **AudioCaps** are **ffmpeg** and **youtube-dl** (yt-dlp should work too).
These two programs can be download on Ubuntu using `sudo apt install ffmpeg youtube-dl`.
The external requirements needed to download **AudioCaps** are **ffmpeg** and **yt-dlp**.
**ffmpeg** can be install on Ubuntu using `sudo apt install ffmpeg` and **yt-dlp** from the [official repo](https://github.com/yt-dlp/yt-dlp).
<!-- programs can be downloaded on Ubuntu using `sudo apt install ffmpeg`. -->

You can also override their paths for AudioCaps:
```python
from aac_datasets import AudioCaps
dataset = AudioCaps(
download=True,
ffmpeg_path="/my/path/to/ffmpeg",
ytdl_path="/my/path/to/youtube_dl",
ytdl_path="/my/path/to/ytdlp",
)
```

Expand Down
26 changes: 15 additions & 11 deletions src/aac_datasets/datasets/audiocaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ def _prepare_audiocaps_dataset(
n_already_ok = 0
n_already_err = 0

for line in tqdm.tqdm(captions_data, total=n_samples, disable=verbose < 1):
for i, line in enumerate(
tqdm.tqdm(captions_data, total=n_samples, disable=verbose < 1)
):
# Keys: audiocap_id, youtube_id, start_time, caption
audiocap_id, youtube_id, start_time = [
line[key] for key in ("audiocap_id", "youtube_id", "start_time")
Expand All @@ -613,6 +615,7 @@ def _prepare_audiocaps_dataset(
f'Start time "{start_time}" is not an integer (audiocap_id={audiocap_id}, youtube_id={youtube_id}).'
)
start_time = int(start_time)
prefix = f"[{audiocap_id:6s};{i:5d}/{n_samples}] "

if not osp.isfile(fpath):
success = _download_and_extract_from_youtube(
Expand All @@ -630,41 +633,42 @@ def _prepare_audiocaps_dataset(
if valid_file:
if verbose >= 2:
pylog.debug(
f"[{audiocap_id:6s}] File '{youtube_id}' has been downloaded and verified."
f"{prefix}File '{youtube_id}' has been downloaded and verified."
)
n_download_ok += 1
else:
if verbose >= 1:
pylog.warning(
f"[{audiocap_id:6s}] File '{youtube_id}' has been downloaded but it is not valid and it will be removed."
f"{prefix}File '{youtube_id}' has been downloaded but it is not valid and it will be removed."
)
os.remove(fpath)
n_download_err += 1
else:
pylog.error(
f"[{audiocap_id:6s}] Cannot extract audio from {youtube_id}."
)
if verbose >= 0:
pylog.warning(
f"{prefix}Cannot extract audio from {youtube_id}. (maybe the source video has been removed?)"
)
n_download_err += 1

elif verify_files:
valid_file = _check_file(fpath, sr)
if valid_file:
if verbose >= 2:
pylog.debug(
f"[{audiocap_id:6s}] File '{youtube_id}' is already downloaded and has been verified."
if verbose >= 1:
pylog.info(
f"{prefix}File '{youtube_id}' is already downloaded and has been verified."
)
n_already_ok += 1
else:
if verbose >= 1:
pylog.warning(
f"[{audiocap_id:6s}] File '{youtube_id}' is already downloaded but it is not valid and will be removed."
f"{prefix}File '{youtube_id}' is already downloaded but it is not valid and will be removed."
)
os.remove(fpath)
n_already_err += 1
else:
if verbose >= 2:
pylog.debug(
f"[{audiocap_id:6s}] File '{youtube_id}' is already downloaded but it is not verified due to verify_files={verify_files}."
f"{prefix}File '{youtube_id}' is already downloaded but it is not verified due to verify_files={verify_files}."
)
n_already_ok += 1

Expand Down
2 changes: 1 addition & 1 deletion src/aac_datasets/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ytdl": {
"user": None,
"env": "AAC_DATASETS_YTDL_PATH",
"package": "youtube-dl",
"package": "ytdlp",
},
"ffmpeg": {
"user": None,
Expand Down

0 comments on commit 10a5637

Please sign in to comment.