Monday, January 15, 2018

How to search your youtube history from the command line in ?

So I eventually found that the personal Youtube search url is at:

A nice ui no doubt but I need to get at from the command line...

To avoid breaking the URI we must ensure the query text is url encoded so:

urlencode() {
    # urlencode <string>
    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf '%%%02X' "'$c"

with that:

#youtube history command
    urlencode | google-chrome "'${*//[$'\t\r\n ']}'&restrict=ytw"

p.s. all these go in a dotfile say at ~/Dotfiles/.functions and then sourced via:

$source ~/Dotfiles/.functions

so to look up the legendary session "Willy Wonka of Containers - Jessie Frazelle"

I need only type:

$yth Willy Wonka

And I instantly achieve container nirvana at #ContainerCamp.