Last month I bought a box media player and I filled with I bunch of movies that were stuck in my laptop. I realized that if a invite my friends to watch a movie, it would be nice to have the trailer so I don’t have to tell them what’s the movie is about.

So I wrote this little script which given a movie name or a file with a list of names, it will search for it and download to the current directory.

All trailers will be downloaded from but the links are provided by

what you need:


import urllib
import re
import sys
import os
import string

from urllib import FancyURLopener

class myOpenUrl(FancyURLopener):
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv: Gecko/20071127 Firefox/'

#strap movie url from html
def getMovieUrl(movieName, resolution):

    moviePageUrl = getMoviePage(movieName,resolution)

    f = urllib.urlopen(moviePageUrl)
    s =

    s = re.findall(r'http.+apple.+'+resolution+'.+mov', s)

    if s:
        return s[0]
        print "Trailer not found"

#strap movie page from google search
def getMoviePage(movieName, resolution):

        myopener = myOpenUrl()
        page =''+ string.join(movieName.split(), "+") + "+site:")
        html =

        s = re.findall(r'href=['"]/url.q=([^'"& >]+)',html)
        return s[0]

    except e:
        print "Search failed: %s" % e

def main():

    #if you want you can change to 720 or 1080, but is not garantee that it will find it
    resolution = "480"

    movieNameList = []
    if len(sys.argv) > 1:
        if (sys.argv[1] == "-h"):
            print "usages: ./"
            print "OR"
            print "usage: ./ listOfMovie.txt"
        source = open(sys.argv[1], 'r')
        movieNameList = source.readlines()
        movieName = raw_input("Name of the movie : ")

    for movieName in movieNameList:

        print "Searching for '"+movieName+"'..."
        movieUrl = getMovieUrl(movieName,resolution)

        if movieUrl:
                print "starting to download : "+ movieUrl
                cmd = 'wget -U QuickTime/7.6.2 ' + movieUrl
            except e:
                print "Error when trying to download : " + movieName
            print "movie not found"

if __name__ == '__main__':


to run the script first you have to give permission

$ chmod +x ./

to run you have 2 options:
1) if you want to download only one trailer, the script will ask you for the name.
$ ./

2)if you want to download more than you.
$ ./ listOfMovies.txt

Feel free to improve the script, and please let me know so I can update here.

And of course, use it at your own risk

Leave your comments :)