#!/usr/bin/expect
set transcription_hash [lindex $argv 0];
set youtube_video_id [lindex $argv 1];

spawn ssh root@74.81.189.3 -p 6732
#expect "(yes/no)?"
#send "yes\r"
expect "assword:"
send "bangk!20120710"
send "\r"
expect "]#"



####################### GET THE AUDIO FROM YOUTUBE:
send "youtube-dl -f 139 -o '/var/www/html/_other/tube-to-text.com/_temporary_audio/direct_from_youtube_${transcription_hash}.m4a' 'https://www.youtube.com/watch?v=${youtube_video_id}'"

send "\r"
expect "]#"
send "\r"
expect "]#"



### ####################### CONVERT THE AUDIO TO WAV:

# v1:
# send "ffmpeg -i '/var/www/html/_other/tube-to-text.com/tubetotext_audio_to_transcribe_${transcription_hash}.m4a' -r 16k '/var/www/html/_other/tube-to-text.com/tubetotext_audio_to_transcribe_${transcription_hash}.wav'"

#v2: 
send "ffmpeg -i '/var/www/html/_other/tube-to-text.com/_temporary_audio/direct_from_youtube_${transcription_hash}.m4a' -b:a 128K '/var/www/html/_other/tube-to-text.com/_temporary_audio/ready_for_IBM_${transcription_hash}.mp3' > '/var/www/html/_other/tube-to-text.com/_logs/ffmpeg_${transcription_hash}.txt'"

send "\r"
expect "]#"
send "\r"
expect "]#"


### ####################### LOAD THE PHP PAGE FOR FURTHER CONVERSION AND TRANSCRIPTION:

send "php /var/www/html/_other/tube-to-text.com/_admin/transcription_engine_slave_v2.nsdb ${transcription_hash}"

# send "/usr/bin/wget -q -O /var/www/html/_other/tube-to-text.com/_logs/transcription_engine_master.txt http://tube-to-text.com/_admin/transcription_engine_slave.nsdb?hash=${transcription_hash}"

send "\r"
expect "]#"
send "\r"
expect "]#"



exit





