How do I check whether a file is available to download?
I usually check the HTTP Code and then run from there. Since this is tagged AppleScript here is an example handler I wrote:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set foundMP4 to my checkStream(c)

on checkStream(passedStream)
    try
        set serverCommand to "curl -o /dev/null -Iw '%{http_code}' " &amp; passedStream
        set serverResult to do shell script serverCommand
        if serverResult does not start with "2" then
            return false
        else
            return true
        end if
    on error serverResult
        display dialog "Ran into issue checking server status, with error: " &amp; serverResult with title "Server Check"
    end try
end checkStream


After you check the HTTP code you could write for the script to download the file.