How to modify this sed awk command so that the output goes to a file of choice?

前端 未结 3 1966
小鲜肉
小鲜肉 2021-01-23 15:48

I am using the last command from this SO answer https://stackoverflow.com/a/54818581/80353

cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub          


        
3条回答
  •  再見小時候
    2021-01-23 16:33

    Here's a detailed bash script for those who wants to save the subs file with a relative path.

    The result is saved as plaintext, removing time, new lines and other markup.

    #!/bin/bash
    # video-cap.sh videoUrl sub.txt
    
    # Download captions only and save in a .vtt file
    youtube-dl --skip-download --write-auto-sub "$1";
    
    # Find .vtt files in current directory created within last 3 seconds, limit to 1
    vtt=$(find . -cmin -0.05 -name "*.vtt" | head -1)
    
    # Extract the subs and save as plaintext, removing time, new lines and other markup
    sed '1,/^$/d' "$vtt" \
      | sed 's/<[^>]*>//g' \
      | awk -F. 'NR%8==1{$1}NR%8==3' \
      | tr '\n' ' ' > "$2"
    
    # Remove the original .vtt subs file
    rm -f "$vtt"
    

提交回复
热议问题