dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

yt-data.sh (804B)


      1 #!/bin/sh
      2 
      3 # Get basic data for a YouTube video
      4 
      5 url="$1"
      6 TEMP_FILE=/tmp/yt-data.html
      7 
      8 curl -s "$url" > "$TEMP_FILE"
      9 
     10 title="$(cat "$TEMP_FILE" | tr "}" "\n" | grep "videoDetails\":{\"videoId" | sed -nE 's/.*"title":"([^"]*).*/\1/p')"
     11 channel="$(cat "$TEMP_FILE" | tr "}" "\n" | grep ownerProfileUrl | head -n 1 | sed -nE 's/.*https?:\/\/www.youtube.com\/[@]([^"]*).*/\1/p')"
     12 description="$(cat "$TEMP_FILE" | tr "}" "\n" | grep "shortDescription" | head -n 1 | sed -nE 's/.*shortDescription":"([^"]*)".*/\1/p' | sed 's/\\u0026/\&/g')"
     13 release_date="$(cat "$TEMP_FILE" | tr "}" "\n" | grep "publishDate\":{\"simpleText\"" | sed -nE 's/.*publishDate":\{"simpleText":"([^"]*).*/\1/p')"
     14 [ "$description" = "" ] && description="$title"
     15 
     16 echo "$title"
     17 echo "$channel"
     18 echo "$description"
     19 echo "$release_date"