import re, urllib, urllib2, urlparse from resolv.shared import ResolverError, TechnicalError, unescape, Task class YoutubeTask(Task): result_type = "video" name = "YouTube" author = "Sven Slootweg" author_url = "http://cryto.net/~joepie91" extra_headers = { 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5' } def run(self): try: contents = self.fetch_page(self.url) except urllib2.URLError, e: self.state = "failed" raise TechnicalError("Could not retrieve the specified URL.") if '', contents).group(1)) except: self.state = "failed" raise TechnicalError("Could not find the video title.") self.results = { 'title': video_title, 'videos': stream_pool } self.state = "finished" return self