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 http://www.apple.com/trailers but the links are provided by http://www.hd-trailers.net/
what you need:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#!/usr/bin/python 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:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11' #strap movie url from html def getMovieUrl(movieName, resolution): moviePageUrl = getMoviePage(movieName,resolution) f = urllib.urlopen(moviePageUrl) s = f.read() s = re.findall(r'http.+apple.+'+resolution+'.+mov', s) if s: return s[0] else: print "Trailer not found" #strap movie page from google search def getMoviePage(movieName, resolution): try: myopener = myOpenUrl() page = myopener.open('http://www.google.com/search?q='+ string.join(movieName.split(), "+") + "+site:http://www.hd-trailers.net/") html = page.read() 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: ./trailerDownloader.py" print "OR" print "usage: ./trailerDownloader.py listOfMovie.txt" sys.exit(0) source = open(sys.argv[1], 'r') movieNameList = source.readlines() source.close() else: movieName = raw_input("Name of the movie : ") movieNameList.append(movieName) for movieName in movieNameList: print "Searching for '"+movieName+"'..." movieUrl = getMovieUrl(movieName,resolution) if movieUrl: try: print "starting to download : "+ movieUrl cmd = 'wget -U QuickTime/7.6.2 ' + movieUrl os.system(cmd) except e: print "Error when trying to download : " + movieName else: print "movie not found" if __name__ == '__main__': main() |
to run the script first you have to give permission
$ chmod +x ./trailerDownloader.py
to run you have 2 options:
1) if you want to download only one trailer, the script will ask you for the name.
$ ./trailerDownloader.py
2)if you want to download more than you.
$ ./trailerDownloader.py 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 🙂
6 abril, 2013 at 2:29 pm
” Lisa rebukes her, saying, “Janey, school isn’t a waste of time” Immediately following, Ms. Characters, whether it be an actor playing a task or a cartoon character, adds a whole new dimension to the poster printing. The family is manufactured from Homer Simpson, that’s the man in the home,
he is an overweight safety inspector in the cities strength plant, he often offers bad suggestions.