Hello Everyone,
I’m trying to write a script that will download YouTube videos using curl, but as we already know, YouTube likes to make this hard. I searched the forum for the topic and tried all suggestions, but it still doesn’t work.
Here is my code:
[code]on searchAndReplace(txt, srch, rpl)
set oldtid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {srch}
set temp to every text item of txt
set AppleScript's text item delimiters to {rpl}
set temp to (temp as string)
set AppleScript's text item delimiters to oldtid
return temp
end searchAndReplace
set y to 1
repeat while y is 1
set vID to ""
set site1 to text returned of (display dialog "Enter site: " with title "Flash Content" buttons {"Cancel", "Download"} default answer "" default button 2)
try
if button returned of the result is "Cancel" then quit
end try
--set site1 to searchAndReplace(site1, "\","/")
--set site1 to searchAndReplace(site1,"/","/")
tell site1 to set url2 to "http://www.youtube.com/v/" & text ((my (offset of "=" in it)) + 1) thru -1
set locationURL to do shell script "curl -I " & url2 & " | grep ^Location | grep -o 'video_id=.*'"
set downloadURL to "http://youtube.com/get_video?" & locationURL
set gtheUrl to do shell script "curl -IL " & quoted form of downloadURL & "| grep ^Location "
set oldDelims to AppleScript's text item delimiters -- get normal dilm
set AppleScript's text item delimiters to {"Location: "} --sets new dilm
set line_start to text item -1 of gtheUrl as string ---
set AppleScript's text item delimiters to oldDelims -- resets dilm
do shell script "cd ~/Desktop; curl " & line_start & " -o ~/Desktop/Youtube_1.flv " -- downloads the file, may take some time.
display dialog "Done! Please check content in your download location. Again?" with title "Complete" buttons {"Cancel", "Again"} default button 2
try
if button returned of the result is "Cancel" then quit
if button returned of the result is "Again" then set y to 1
end try
end repeat[/code]
Nevermind with searchAndReplace. I put that in because I even tried downloading the .html then reading in a certain section replacing certain characters and then removing the .html.
Let me explain what this “certain” part is. When I download the video via Safari, it gives the location:
http:\/\/o-o.preferred.iad09s14.v5.lscache5.c.youtube.com\/generate_204?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hQS1BQV19FSkNOMF9ISkFD\u0026fexp=900502%2C904539%2C913519\u0026itag=43\u0026ip=0.0.0.0\u0026signature=6BF4908C7E93161975C735B4896C9BA63047C8D5.52B06C9DEF67FAF58C50FC221ABA7BACAA944F7F\u0026sver=3\u0026ratebypass=yes\u0026expire=1316059200\u0026key=yt1\u0026ipbits=0\u0026id=27a65694392cd274
Which if you notice, I’m forced to change certain characters. Now, when I try to go to that URL (after the change), it won’t work.
So anyone have any ideas?
I see two main problems-there are many redirects and I don’t think anyone knows which directory the videos are held.