I was referred here from another forum that said my problem could be best solved by AppleScript. I know only the bare minimum about AS and was wondering if I could ask for your help.
My problem is I have 3 text files, each with their own set of links.
The first is a list of URLs that direct to a website that contains a large picture in the middle of it, surrounded by text, links etc. I was told that a script could be made to select and download a website’s largest image. Also, is there anyway to incorporate the name of the picture in the download? I strongly doubt this is possible or plausible, but a lot of the pictures are DSC0290nnnn.jpg, and I would like a better if there was a way to add the title to the file name.
Here’s a sample link: http://www.trekearth.com/gallery/photo130615.htm
The next is a file filled with Youtube links that I am supposed to download and convert for an iPod touch. I have Tubesock, but is there anyway I can do a batch of them all at once rather than one by one?
And finally, the last file contains links to a website where I need to open Safari’s activity window, download the largest file (a .flv), and then convert it to be playable on an iPod Touch (similar site to youtube, previously I used iSquint for conversion). Is there anyway to automate this? Finally, the files download name is always getvid.flv, is there anyway to replace this with the website title as the name?
Thanks.
I know that this is a lot to ask for, but I’m wondering if anyone can help with this. I was given a list of a few hundred links and that would take quite some time to do it manually.
There’s many steps involved in what you need. I think if you break each part into its individual steps needed to accomplish the task then you can find your answers by searching this website. All of your answers are probably already solved, you just need to take it one step at a time. For example to accomplish your first task of downloading and renaming the pictures from the link file. You need to figure out how to do the following…
How do you read in a text file into your script?
make the text into a list of the links
repeat through each link
use curl to get the html source from the link’s web page
parse the html source to find the image link
use curl to download the found image link
parse the html code for the name of the picture
use the Finder to rename the downloaded picture
I’m certain the tools to accomplish each step can already be found. You just need to find them and put them into one script, tweaking each to your particulars. It takes time but that’s how you learn to applescript. Once you can accomplish this task then the others will be very similar and thus much easier.
Regulus is probably right about using CURL. I would do it a bit different due to my lack of luck using and knowledge of CURL. Basically if you want an image and you are using Safari you can use this thread as a guide: http://bbs.applescript.net/viewtopic.php?id=18758
Kel shows a nice bit of javascript which will return a list of images in the page:
set image_url to (do JavaScript "document.images[" & (i - 1) & "].src" in document 1)
I’m not real familiar with JavaScript, so I’m not sure if there is a way to identify the largest image using JavaScript so you might have to resort to parsing the HTML source where you can get the width and height of the image. You can get the source for the page as well through Safari using this:
tell application "Safari"
set SourceCode to source of document 1
end tell
To download the images you can use the URL you get with the following:
tell application "URL Access Scripting" to download ImageLink to (DownloadFolder & FileName) replacing yes without progress
Where DownloadFolder is the path and FileName is the name you want for the file.
Of course with CURL you can get and download the image as well but if you are not familiar with UNIX commands and how they are called through AppleScirpt the above might be easier.
And back to the beginning, reading the text file.
If you use the using delimiters then you can read it in as a list, so:
set URLList to read theFile using delimiter {return}
returns the list:
from a text file:
Then you can step through the list of URLs and use them with whatever method that you choose to get the images.