I did a search and did not seem to come up with what i was looking for so i figured i would ask. Here is what i am trying to do:
Paste a link to a asx into an apple script that then calls mplayer to save the info from that link to a text file.
I then want applescript to open that text file and parse it for the mms link that is inside.
take the mms link and give it to a variable in apple script to then pass to mplayer again to download the video.
here is my code so far
on run
set theFileName to ""
--ask for asx link from user
display dialog "enter value" default answer theFileName
set theFileName to text returned of the result
--extract file name from link without extention
get every word of theFileName
set everyWord to theFileName as string
set lastWord to word -1 of everyWord
set secondToLast to word -2 of everyWord
set theFile to secondToLast
--set file name with txt extention
set textFile to theFile & ".txt"
--set save directory
set mmsTXTdir to "/Users/donaldradlund/Movies/inside_nba/" & textFile
--run through mplayer to get txt file
do shell script "mplayer -dumpstream -dumpfile " & mmsTXTdir & " " & theFileName
--open text edit to manually copy mms link into next step
tell application "TextEdit"
open mmsTXTdir
end tell
set theMMSName to ""
set wmvFile to theFile & ".wmv"
--get mms link from user
display dialog "enter value" default answer theMMSName
set theMMSName to text returned of the result
--set save directory
set mmsWMVdir to "/Users/donaldradlund/Movies/inside_nba/" & wmvFile
--run through mplayer to get wmv file
do shell script "mplayer -dumpstream -dumpfile " & mmsWMVdir & " " & theMMSName
display alert "File Downloaded. Enjoy!"
end run
This all works perfectly except for i dont know how to implement the parsing of the text file for the mms link
this is what the txt file created by the first step looks like
<asx version="3.0">
<title> title </title>
<author> author </author>
<copyright> copyright </copyright>
<entry>
<title> title </title>
<author> author </author>
<copyright> copyright </copyright>
<ref href="mms://nbastreams.link_to_movie&aifp=0001"/>
<ref href="mms://wm3-cm.link_to_movie&aifp=0001"/>
</entry>
</asx>
<!-- Generated by Akamai Stream OS BOSS (v2-20071212-cpcodebreakout) / 4b0f2ab6 -->
The amount of characters in the , , , and tags actually changes each time. that is what has me stumped.
can anyone help me on how to get started on extracting that mms link?
set Q to "<asx version=\"3.0\">
<title> title </title>
<author> author </author>
<copyright> copyright </copyright>
<entry>
<title> title </title>
<author> author </author>
<copyright> copyright </copyright>
<ref href=\"mms://nbastreams.link_to_movie&aifp=0001\"/>
<ref href=\"mms://wm3-cm.link_to_movie&aifp=0001\"/>
</entry>
</asx>
<!-- Generated by Akamai Stream OS BOSS (v2-20071212-cpcodebreakout) / 4b0f2ab6 -->"
set mm to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<ref "
set PQ to text items 2 thru 3 of Q
set AppleScript's text item delimiters to "/>"
repeat with P in PQ
set end of mm to first text item of contents of P
end repeat
set AppleScript's text item delimiters to tid
mm --> {"href=\"mms://nbastreams.link_to_movie&aifp=0001\"", "href=\"mms://wm3-cm.link_to_movie&aifp=0001\""}
Thank you very much for the help. I used your code, modified it a little and added some other stuff… here is the result:
on run
set theFileName to ""
--get url from front page of safari
tell application "Safari"
set thisPage to do JavaScript "document.URL" in document 1
end tell
--extract asx link from url
set theFileName to {}
set del to AppleScript's text item delimiters
set AppleScript's text item delimiters to "video&url="
set QR to text items 2 thru 2 of thisPage
set AppleScript's text item delimiters to "&"
repeat with Q in QR
set end of theFileName to first text item of contents of Q
end repeat
set AppleScript's text item delimiters to del
--extract file name from link without extention
get every word of theFileName
set everyWord to theFileName as string
set lastWord to word -1 of everyWord
set secondToLast to word -2 of everyWord
set theFile to secondToLast
--set file name with txt extention
set textFile to theFile & ".txt"
--set save directory
choose folder with prompt "Select Destination"
set saveDir to POSIX path of the result
set mmsTXTdir to saveDir & textFile
--run through mplayer to get txt file
do shell script "mplayer -dumpstream -dumpfile " & mmsTXTdir & " " & theFileName
tell application "TextEdit"
open mmsTXTdir
set textContent to get text of document 1
close document 1
end tell
--extract mms link from downloaded text file
set theMMSName to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<ref href=\""
set PQ to text items 2 thru 2 of textContent
set AppleScript's text item delimiters to "\"/>"
repeat with P in PQ
set end of theMMSName to first text item of contents of P
end repeat
set AppleScript's text item delimiters to tid
set wmvFile to theFile & ".wmv"
--set save directory
set mmsWMVdir to saveDir & wmvFile
--run through mplayer to get wmv file
do shell script "mplayer -dumpstream -dumpfile " & mmsWMVdir & " " & theMMSName
end run
enjoy if you want to download the wmv files from nba.com