Browse Source

Add YouTube normalisation script

master
JustAnotherArchivist 4 years ago
parent
commit
91adce786f
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      youtube-normalise

+ 29
- 0
youtube-normalise View File

@@ -0,0 +1,29 @@
#!/bin/bash
while read -r url
do
if [[ "${url}" =~ ^https?://(www\.)?youtube\.com/ ]]
then
if [[ "${url}" == *'?'* ]]
then
rurl="${url}&disable_polymer=1"
else
rurl="${url}?disable_polymer=1"
fi
page="$(curl -4sL -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept-Language: en-US,en;q=0.5' "${rurl}")"
canonical="$(grep -Po '<link itemprop="url" href="http://www\.youtube\.com/\Kuser/[^"]+' <<< "${page}")"
if [[ "${canonical}" ]]
then
echo "https://www.youtube.com/${canonical}"
else
canonical="$(grep -Po '<link itemprop="url" href="http://www\.youtube\.com/\Kchannel/[^"]+' <<< "${page}")"
if [[ "${canonical}" ]]
then
echo "https://www.youtube.com/${canonical}"
else
echo "${url}"
fi
fi
else
echo "${url}"
fi
done

Loading…
Cancel
Save