DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
0 votes

This can't be done just with arguments as it says here: Set download-archive path with args

I want to make two similar scripts. One that downloads the videos and archive file in the uploader's folder for each video. And another script that also downloads the metadata.

I want to check the archive before downloading.

I want to be able to use the function multiple times in parallel putting them on the background.

The only way I can think of getting the uploader is to download the metadata with the output %(uploader)s.

Then create a folder with the uploader's name, remove the file, and download again the files with the correct name from the created folder.

This is what I've tried but it isn't working

# Video Playlist saving archive file to uploader's folder
ytp() {
  # Dl opts=(
    ${opts[@]}
    --download metadata
    --skip-download
    --write-info-json
  )
  # Get ten random characters
  local rand=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1 )
  LOG_NAME=$( get_log_name "$(${paste[@]})" )

  $yt_dl ${opts[@]} --output "%(uploader|Anon-%(id)s)s.%(ext)s" "$(${paste[@]})" >> "/tmp/$LOG_NAME" 2>&1

  for f in *.info.json; do
    local name="${f%.*}"
    if [[ $name == Anon* ]]; then
      name="Anon"
    fi
    mkdir -p "$name"
    rm "$f"
    cd "$name" || exit

    # Download media
    ytv

    cd .. || exit
  done
}
by
edited by

2 Answers

0 votes
 
Best answer
download_playlist() {
  # $1: playlist URL
  playlist=$1

  # Get a list of all video URLs in the playlist
  video_urls=$(youtube-dl "$playlist" -j | jq -r .webpage_url)

  # Iterate through the list of video URLs
  for url in $video_urls; do
    # Get the uploader of the current video
    uploader=$(youtube-dl --print "%(uploader|Unknown)s" "$url")
    # Download the current video, saving the archive file in the output directory
    youtube-dl --download-archive "$uploader/archive.txt" --output "%(title)s-%(id)s.%(ext)s" "$url"
  done
}
by
selected by
0 votes

If you use a sh/bash/zsh-type shell you could do something like this

touch temp_archive.txt; yt-dlp --write-info-json --download-archive temp_archive.txt -o "%(uploader)s/%(title)s-[%(id)s].%(ext)s" --exec after_video:'cat temp_archive.txt >> "%(uploader)s/archive.txt"; printf "" > temp_archive.txt' "URL"
by
edited by
0

This doesn't check the archive before downloading. So it's not really what I want.

Contributions licensed under CC0
...