muz alias and test of the gyts script

VastOne

Aliases are a big part of VSIDO and one of the very best we have is muz which uses a script made by superchompu called gyts.. Any of you using VSIDO can check out the script in /usr/local/bin

Issue is it has apparently stop working for users who are up to date with VSIDO and SID levels...  This is a test to determine the validity of that statement...  I know it does not work for me and jedi has also said it is broke... But we are running the very latest ISO (the first Jedi ISO release) ...

The error is very generic "error with connection" no matter what you select and is their is no way to debug (to my knowledge) due to how generic the script is

gyts using requires 4 apps to run

lynx which in turn requires lynx-cur
lame
ffmpeg
youtube-dl

From all appearances it seems to be an issue with lynx or lynx-cur since they are the engine that gets in gyts

I have racked my brain over it without success and I have contacted the author of the script but he has not responded in kind

First if anyone completely up to date with SID could test the script and let me know if it works or not

Then if any of you can help crack why it is erroring out, I will be eternally grateful

Thankee Sai's

Here is the gyts script for anyone interested


#!/bin/bash
function isFileEmpty()
{
    if [ ! -s $1 ]
    then
            return 0
    else
            return 1
    fi
}

function fileExists()
{
    if [ -f $1 ]
    then
        return 1
    else
        return 0
    fi
}

function makeFileName()
{
    archive=$(echo "${artist} ${song}" | sed -e 's/ /_/g')
}

function downloadBest()
{
    youtube-dl ${1} -o ${2}.ytb
    fileExists ${2}.ytb
    return $?
}

function downloadWorst()
{
    youtube-dl -f worst ${1} -o ${2}.ytb
    fileExists ${2}.ytb
    return $?
}

function getTitle()
{
    youtube-dl --get-title $1
}

function extractAudio() {
    ffmpeg -i ${1}.ytb -ac 2 ${1}.wav
    rm ${1}.ytb
    fileExists ${1}.wav
    return $?
}

function toMp3() {
    lame -b ${1} ${2}.wav ${2}.mp3
    rm ${2}.wav
    fileExists ${2}.mp3
    return $?
}


function getList()
{
    lynx -dump -listonly http://www.youtube.com/results?search_query="${1}"+"${2}">>${3}.rl
    grep http://www.youtube.com/watch?v= ${3}.rl >> ${3}.rl1
    rm ${3}.rl
    cut -b 1-6 --complement ${3}.rl1 >> ${3}.rl2
    rm ${3}.rl1
    uniq ${3}.rl2 >> ${3}.rl3
    rm ${3}.rl2
    grep -v \& ${3}.rl3 >> ${3}.l
    rm ${3}.rl3
    isFileEmpty ${3}.l
    return $?
}

function checkProgram()
{
    if ! type $1 &>/dev/null;
    then
        echo "I require $1 to work.."
        echo "Do I try to install it? (y to install)"
        read -s -n1 char
        if [ "$char" == "y" ]
        then
            echo "trying to install (with apt)"
            sudo apt-get install $1
        else
            echo "see ya!"
            exit
        fi
    fi
}

function printHelp()
{
    echo -e "NAME"
    echo -e "\tgyts"
    echo -e "\tArtist, song and quality->Youtube->Audio->mp3, easy as that"
    echo -e "USAGE"
    echo -e "\tgyts"
    echo -e "\t\tInteractive Mode"
    echo -e "\tgyts \"artist\" \"song\" Q L|F"
    echo -e "\t\tSearch youtube for the artist and song (must be between \" \")"
    echo -e "\t\tQ can be 1, 2 or 3, 3 being the best quality"
    echo -e "\t\tL or l shows a list to choose from"
    echo -e "\t\tF or f shows no list, and download the first result"
    echo -e "\tgyts help"
    echo -e "\t\tPrint a usage message, this one"
    echo -e "\t\tcontact: superchompu@gmail.com"
    echo -e "\t\tLong Live CrunchBang Linux!!"
    echo -e "\t\tVisit http://crunchbanglinux.org/"
    exit
}

function interactiveMode()
{
    echo "Interactive Mode"
    read -p "Artist: " artist
    read -p "Song: " song
    echo "Quality: "
    echo "1 = worst but quick"
    echo "2 = medium quality"
    echo "3 = best quality"
    read quality
    while ! [[ "$quality" =~ ^[1|2|3]$ ]]
    do
        echo "Not a number or out of range (1-3)"
        read quality
    done
    echo "Choose from List or First find: "
    echo "L or l = List"
    echo "F or f = First Find" 
    read chooselist
    while ! [[ "$chooselist" =~ ^[L|l|F|f]$ ]]
    do
        echo "Only L for list or F for first find"
        read chooselist
    done
   
}

function singleSongLine()
{
    artist=$1
    song=$2
    quality=$3
    if ! [[ "$quality" =~ ^[1|2|3]$ ]]
    then
        echo "Bad argument Quality = $quality "
        printHelp
    fi
    chooselist=$4
    if ! [[ "$chooselist" =~ ^[L|l|F|f]$ ]]
    then
        echo "Bad argument List or First find= $chooselist"
        printHelp
    fi   
}

function downloadAndConvert()
{
    if [[ "$quality" -gt 1  ]]
    then
        downloadBest $1 $archive
    else
        downloadWorst $1 $archive
    fi
    if [[ $? -eq 0  ]]
    then
        echo "problem with link"
        return 0
    else
        extractAudio $archive
        if [[ $? -eq 0 ]]
        then
            echo "problem when extracting audio"
            return 0
        else
            if [[ "$quality" -eq 3 ]]
            then
                toMp3 320 $archive
            else
                toMp3 192 $archive
            fi
            if [[ $? -eq 0 ]]
            then
                echo "problem converting to mp3"
                return 0
            else
                return 1
            fi
        fi
    fi   
}

function chooseFromList()
{
        read -p "Choose: " index
        while ! [[ "$index" =~ ^[0-9]+$ ]]
        do
            echo "not a number"
            chooseFromList $1
        done
        while ! [[ "$index" -lt $1 ]]
        do
            echo "out of range"
            chooseFromList $1
        done
}
clear
checkProgram "lynx"
checkProgram "youtube-dl"
checkProgram "ffmpeg"
checkProgram "lame"

if [[ $# -gt 4 ]]
then
    echo "Too many arguments."
    printHelp
    exit
fi

if [ $# -eq 1 ] || [ $# -eq 3 ]
then
    printHelp
fi

if [[ $# -eq 2 ]]
then
    printHelp
else
    if [[ $# -eq 0 ]]
    then
        interactiveMode
    else
        if [[ $# -eq 4 ]]
        then
            singleSongLine "$1" "$2" "$3" "$4"
        fi
    fi
    makeFileName "$artist" "$song"
    getList "$artist" "$song" "$archive"
    if [[ $? -eq 0 ]]
    then
        echo "Error with connection"
        exit
    fi
    if  [ "$chooselist" == "L"  ] || [ "$chooselist" == "l" ]
    then
        iterator=0
        for link in $(cat ${archive}.l)
        do
            echo -n "[${iterator}]: "
            getTitle $link
            let iterator++
        done
        a=( $( cat ${archive}.l ) )
        alenght=$(( ${#a[@]} ))
        chooseFromList alenght
        downloadAndConvert ${a[$index]}
        if [[ $? -eq 0 ]]
        then
            echo "something went horribly wrong :( ..."
        else
            rm ${archive}.l
            exit
        fi
    else
        for link in $(cat ${archive}.l)
        do
            downloadAndConvert $link
            if [[ $? -eq 0 ]]
            then
                echo "trying to download another..."
                continue
            else
                rm ${archive}.l
                exit
            fi
        done
        rm ${archive}.l
        echo "ran out of links"
    fi
fi
exit
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

Looks like the makeFileName function is broken -

<snip>

function makeFileName()
{
    archive=$(echo "${artist} ${song}" | sed -e 's/ /_/g')

}

<snip>

    makeFileName "$artist" "$song"
    getList "$artist" "$song" "$archive"
    if [[ $? -eq 0 ]]
    then
        echo "Error with connection"
        exit
    fi

<snip>


If you try to get a video (Elvis Costello, Pump it Up for this exercise), a zero bite file:

elvis_costello_pump_it_up.l

gets created in the ~/music folder. Appears the script dies if that file can't be created.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Right... but that process is succeeding. The file is created correctly but with zero bytes because there is no connection.  That appears to be the lynx process process failing
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#3
Would it the connection itself, or is that function deprecated (like the sed portion no longer works)?

I tried connecting to youtube with lynx in a terminal and it stops until you accept a cookie. I tried the "Always" option to see if it would then proceed on subsequent tries but it always stops. Maybe that is the cause

elinks goes through without issue though. I wonder if the script can be rewritten with elinks, or an extra command passed to lynx to accept the cookie automatically.

just brain storming here.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Good brainstorming... I will take a longer look when my granddaughter takes her nap...  ???
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

#5
elinks would be a really good replacement but it does not seem to have any -listonly option that lynx does and the script needs

Lynx does have the option to  -accept_all_cookies (accept all cookies) I am looking at how to incorporate that into the script

Lynx also has an option to accept a specific cookie by file name
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

I have tried the cookie options with Lynx and it does not make a difference...

In using lynx with generic basic commands, I get the results I am expecting ... without any prompts for cookies

lynx --dump --listonly youtube.com

lynx --dump --listonly youtube.com | grep http | cut -f2- -d'.' | tr -d ' ' | sort | uniq

Perhaps this error is a failure at the creation of that file and not at getting the data as you suggested PackRat...

Any ideas on turning on a bash debugging tool?
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

I don't know what's needed to debug the script. Reminds me of what's always happening to conky scripts - like the weather - that pull from websites. The site re-designs the webpage and the scripts quit working because the various awk, grep, sed calls are returning what is effectively gibberish.

I can actually see where youtube would deliberately re-design their site to break scripts like this to avoid any (real or imagined) copyright issues.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

I think you are spot on with that assessment RatMan... I was just using smplayer and it failed to get a video stating 'changes to the youtube page' ... but it offered an update and low and behold it worked then.. so someone is keeping up with changes with that add on..

I never did hear back from the guy who wrote this script and hate to say it but it appears to be dead and gone...

... sad, it was one of my favorite tools in VSIDO
VSIDO      VSIDO Change Blog    

    I dev VSIDO

jedi

Wow.  One of my favorites as well.  R.I.P. Muz... I will miss this little app quite a lot.
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous