Last active
October 15, 2023 17:32
-
-
Save bonnebulle/1fbcd16f41bdc1cb26986be19bc87f3e to your computer and use it in GitHub Desktop.
Get Youtube metadatas ( description + med_thumbnail ) using Youte + Google API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DO : Get Youtube metadatas ( description + med_thumbnail ) | |
# DO : dwl img using curl + copy description to clipboard | |
# HOW = using Youte + Google API | |
# USAGE = youte_youtube_infos_API.sh https://www.youtube.com/watch?v=7_22jCiq4nk | |
# USAGE = youte_youtube_infos_API.sh 7_22jCiq4nk # <- id only | |
# USAGE = youte_youtube_infos_API.sh 7_22jCiq4nk img # <- img only | |
# TODO : search_replace "~/Bureau/YT/" -> Your Destination folder ! | |
# TODO : mkdir ~/Bureau/YT/ | |
# TODO : chmod +x youte_youtube_infos_API.sh && mv youte_youtube_infos_API.sh /usr/bin/ | |
# DEP installer = pip / pipx | |
# DEP Youte = https://youte.readthedocs.io/en/latest/tutorial/ | |
# DEP Youte = https://github.com/QUT-Digital-Observatory/youte | |
# DEP Google API = https://developers.google.com/youtube/v3/getting-started | |
# DEP Jq = https://command-not-found.com/jq | |
# DEP perl = https://command-not-found.com/perl | |
# DEP curl = https://command-not-found.com/curl | |
# DEP xclip = https://command-not-found.com/xclip | |
# DEP extra catimg = https://github.com/posva/catimg | |
## HELP | |
echo "\$1 URL / ID" | |
echo "\$2 img => dwl med thumb" | |
echo "=> ~/Bureau/YT/" | |
echo | |
echo | |
## SETUP | |
URL=$1 | |
OPT=$2 | |
# ( if \$2 == "img" -> img only ! ) | |
## VERIFY if is YT URL => get ID | |
if [[ $URL =~ ^(https?://)?(www.)?(youtu.be/|youtube.com/(embed/|v/|watch\?v=|watch\?.+&v=|playlist\?list=))([[:alnum:]|_|-]{11})($|&(.+)?) ]]; then | |
VIDID=$(echo $1 | grep -oP '[0-9A-Z-a-z_\-]{1,}$') | |
elif [[ $URL ]] | |
then | |
VIDID=$1 | |
else | |
echo "--- give \$1 URL" | |
fi | |
if [[ $URL ]] | |
then | |
echo | |
echo | |
echo "[[ $VIDID ]]" | |
echo | |
## YOUTE | |
youte videos $VIDID -o ~/Bureau/YT/$VIDID.json | |
## IMG | |
IMGURL=$(jq '.[].items[].snippet.thumbnails.medium.url' ~/Bureau/YT/$VIDID.json | sed 's/^.//' | sed 's/.$//') | |
echo $IMGURL | |
curl $IMGURL -o ~/Bureau/YT/$VIDID.jpg | |
catimg ~/Bureau/YT/$VIDID.jpg -H 20 | |
## OPT img ONLY | |
if [[ $OPT != "img" ]] | |
then | |
echo | |
echo "------" | |
echo | |
## DESCRIPTION | |
jq '.[].items[].snippet.description' ~/Bureau/YT/$VIDID.json | sed 's/^.//' | sed 's/.$//' | perl -pe 's/\\n/\n/g' > ~/Bureau/YT/{$VIDID}_desc.json && cat ~/Bureau/YT/{$VIDID}_desc.json | xclip -sel clip && cat ~/Bureau/YT/{$VIDID}_desc.json | |
fi | |
fi | |
## RESUME | |
echo | |
echo "------" | |
echo | |
echo $(jq '.[].items[].snippet.title' ~/Bureau/YT/$VIDID.json | sed 's/^.//' | sed 's/.$//') | |
echo "[[ $VIDID ]]" | |
catimg ~/Bureau/YT/$VIDID.jpg -H 10 | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment