Beispiel #1
0
def autostart(reason, **kwargs):
	print "[CrashlogAutoSubmit] - autostart"
	try:
		device = open("/proc/stb/info/model", "r").readline().strip()
	except:
		device = ""	
	if device != "dm7025":
		rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?']
		etpm = eTPM()
		l2cert = etpm.getData(eTPM.DT_LEVEL2_CERT)
		if l2cert is None:
			return
		l2key = validate_cert(l2cert, rootkey)
		if l2key is None:
			return
		l3cert = etpm.getData(eTPM.DT_LEVEL3_CERT)
		if l3cert is None:
			return
		l3key = validate_cert(l3cert, l2key)
		if l3key is None:
			return
		rnd = read_random()
		if rnd is None:
			return
		val = etpm.computeSignature(rnd)
		result = decrypt_block(val, l3key)
	if device == "dm7025" or result[80:88] == rnd:
		if "session" in kwargs:
			try:
				startMailer(kwargs["session"])
			except ImportError, e:
				print "[CrashlogAutoSubmit] Twisted-mail not available, not starting CrashlogAutoSubmitter", e
Beispiel #2
0
	def send_mail():
		rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?']
		etpm = eTPM()
		l2cert = etpm.getData(eTPM.DT_LEVEL2_CERT)
		if l2cert is None:
			return
		l2key = validate_cert(l2cert, rootkey)
		if l2key is None:
			return
		l3cert = etpm.getData(eTPM.DT_LEVEL3_CERT)
		if l3cert is None:
			return
		l3key = validate_cert(l3cert, l2key)
		if l3key is None:
			return
		rnd = read_random()
		if rnd is None:
			return
		val = etpm.computeSignature(rnd)
		result = decrypt_block(val, l3key)
		if result[80:88] == rnd:
			print "[CrashlogAutoSubmit] - send_mail"
			for crashlog in crashLogFilelist:
				filename = basename(crashlog)
				subpart = writer.nextpart()
				subpart.addheader("Content-Transfer-Encoding", 'base64')
				subpart.addheader("Content-Disposition",'attachment; filename="%s"' % filename)
				subpart.addheader('Content-Description', 'Enigma2 crashlog')
				body = subpart.startbody("%s; name=%s" % ('application/octet-stream', filename))
				mimetools.encode(open(crashlog, 'rb'), body, 'base64')
			writer.lastpart()
			sending = smtp.sendmail(str(mxServer), mailFrom, mailTo, message.getvalue())
			sending.addCallback(handleSuccess).addErrback(handleError)
Beispiel #3
0
def autostart(reason, **kwargs):
	print "[CrashlogAutoSubmit] - autostart"
	try:
		device = open("/proc/stb/info/model", "r").readline().strip()
	except:
		device = ""	
	if device != "dm7025":
		rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?']
		etpm = eTPM()
		l2cert = etpm.getCert(eTPM.TPMD_DT_LEVEL2_CERT)
		if l2cert is None:
			return
		l2key = validate_cert(l2cert, rootkey)
		if l2key is None:
			return
		l3cert = etpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT)
		if l3cert is None:
			return
		l3key = validate_cert(l3cert, l2key)
		if l3key is None:
			return
		rnd = read_random()
		if rnd is None:
			return
		val = etpm.challenge(rnd)
		result = decrypt_block(val, l3key)
	if device == "dm7025" or result[80:88] == rnd:
		if "session" in kwargs:
			try:
				startMailer(kwargs["session"])
			except ImportError, e:
				print "[CrashlogAutoSubmit] Twisted-mail not available, not starting CrashlogAutoSubmitter", e
Beispiel #4
0
def startServerInstance(session, ipaddress, port, useauth=False, l2k=None, usessl=False):
	if hw.get_device_name().lower() != "dm7025":
		l3k = None
		l3c = tpm.getData(eTPM.DT_LEVEL3_CERT)

		if l3c is None:
			return False

		l3k = validate_certificate(l3c, l2k)
		if l3k is None:
			return False

		random = get_random()
		if random is None:
			return False

		value = tpm.computeSignature(random)
		result = decrypt_block(value, l3k)

		if result is None:
			return False
		else:
			if result[80:88] != random:
				return False

	if useauth:
# HTTPAuthResource handles the authentication for every Resource you want it to
		root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
		site = server.Site(root)
	else:
		root = HTTPRootResource(toplevel)
		site = server.Site(root)

	if has_ipv6 and fileExists('/proc/net/if_inet6') and version.major >= 12:
		if ipaddress == '0.0.0.0':
			ipaddress = '::'
		elif ipaddress == '127.0.0.1':
			ipaddress = '::1'

	if usessl:
		ctx = ChainedOpenSSLContextFactory(KEY_FILE, CERT_FILE)
		try:
			d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False
	else:
		try:
			d = reactor.listenTCP(port, site, interface=ipaddress)
			if ipaddress == '::1':
				d = reactor.listenTCP(port, site, interface='::ffff:127.0.0.1')
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False

	running_defered.append(d)
	print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
	return True
Beispiel #5
0
def startServerInstance(session, ipaddress, port, useauth=False, l2k=None, usessl=False):
	if hw.get_device_name().lower() != "dm7025":
		l3k = None
		l3c = tpm.getData(eTPM.DT_LEVEL3_CERT)

		if l3c is None:
			return False

		l3k = validate_certificate(l3c, l2k)
		if l3k is None:
			return False

		random = get_random()
		if random is None:
			return False

		value = tpm.computeSignature(random)
		result = decrypt_block(value, l3k)

		if result is None:
			return False
		else:
			if result [80:88] != random:
				return False

	if useauth:
# HTTPAuthResource handles the authentication for every Resource you want it to
		root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
		site = server.Site(root)
	else:
		root = HTTPRootResource(toplevel)
		site = server.Site(root)

	if has_ipv6 and fileExists('/proc/net/if_inet6') and version.major >= 12:
		if ipaddress == '0.0.0.0':
			ipaddress='::'
		elif ipaddress == '127.0.0.1':
			ipaddress='::1'

	if usessl:
		ctx = ChainedOpenSSLContextFactory(KEY_FILE, CERT_FILE)
		try:
			d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False
	else:
		try:
			d = reactor.listenTCP(port, site, interface=ipaddress)
			if ipaddress == '::1':
				d = reactor.listenTCP(port, site, interface='::ffff:127.0.0.1')
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False

	running_defered.append(d)
	print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
	return True
Beispiel #6
0
def startServerInstance(session,
                        ipaddress,
                        port,
                        useauth=False,
                        l2k=None,
                        usessl=False):
    if hw.get_device_name().lower() != "dm7025":
        l3k = None
        l3c = tpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT)

        if l3c is None:
            return False

        l3k = validate_certificate(l3c, l2k)
        if l3k is None:
            return False

        random = get_random()
        if random is None:
            return False

        value = tpm.challenge(random)
        result = decrypt_block(value, l3k)

        if result is None:
            return False
        else:
            if result[80:88] != random:
                return False

    if useauth:
        # HTTPAuthResource handles the authentication for every Resource you want it to
        root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
        site = server.Site(root)
    else:
        root = HTTPRootResource(toplevel)
        site = server.Site(root)

    if usessl:
        ctx = ChainedOpenSSLContextFactory(KEY_FILE, CERT_FILE)
        try:
            d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
        except CannotListenError:
            print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (
                ipaddress, port, useauth, usessl)
            return False
    else:
        try:
            d = reactor.listenTCP(port, site, interface=ipaddress)
        except CannotListenError:
            print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (
                ipaddress, port, useauth, usessl)
            return False

    running_defered.append(d)
    print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port,
                                                              useauth, usessl)
    return True
Beispiel #7
0
def startServerInstance(session, ipaddress, port, useauth=False, l2k=None, usessl=False):
	if hw.get_device_name().lower() != "dm7025":
		l3k = None		
		l3c = tpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT)
		
		if l3c is None:
			return False			
		
		l3k = validate_certificate(l3c, l2k)
		if l3k is None:			
			return False
		
		random = get_random()
		if random is None:
			return False
	
		value = tpm.challenge(random)
		result = decrypt_block(value, l3k)
		
		if result is None:
			return False
		else:
			if result [80:88] != random:		
				return False
		
	if useauth:
# HTTPAuthResource handles the authentication for every Resource you want it to			
		root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
		site = server.Site(root)			
	else:
		site = server.Site(toplevel)

	if usessl:
		from twisted.internet import ssl
		from OpenSSL import SSL
		ctx = ssl.DefaultOpenSSLContextFactory('/etc/enigma2/server.pem', '/etc/enigma2/cacert.pem', sslmethod=SSL.SSLv23_METHOD)
		try:
			d = reactor.listenSSL(port, site, ctx, interface=ipaddress)			
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False
	else:
		try:
			d = reactor.listenTCP(port, site, interface=ipaddress)
		except CannotListenError:
			print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
			return False
	
	running_defered.append(d)
	print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
	return True
def startServerInstance(session,
                        ipaddress,
                        port,
                        useauth=False,
                        l2k=None,
                        usessl=False):
    if hw.get_device_name().lower() != "dm7025":
        l3k = None
        l3c = tpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT)

        if l3c is None:
            return False

        l3k = validate_certificate(l3c, l2k)
        if l3k is None:
            return False

        random = get_random()
        if random is None:
            return False

        value = tpm.challenge(random)
        result = decrypt_block(value, l3k)

        if result is None:
            return False
        else:
            if result[80:88] != random:
                return False

    if useauth:
        # HTTPAuthResource handles the authentication for every Resource you want it to
        root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
        site = server.Site(root)
    else:
        site = server.Site(toplevel)

    if usessl:

        ctx = ssl.DefaultOpenSSLContextFactory('/etc/enigma2/server.pem',
                                               '/etc/enigma2/cacert.pem',
                                               sslmethod=SSL.SSLv23_METHOD)
        d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
    else:
        d = reactor.listenTCP(port, site, interface=ipaddress)
    running_defered.append(d)
    print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port,
                                                              useauth, usessl)
    return True
Beispiel #9
0
                except:
                    print "error parsing fmtstring:", fmtstring

            else:
                (fmtid, fmturl) = fmtstring.split("|")
            if VIDEO_FMT_PRIORITY_MAP.has_key(fmtid) and fmtid != "":
                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {"fmtid": fmtid, "fmturl": unquote_plus(fmturl)}
                fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
        print "[YTTrailer] got", sorted(fmt_infomap.iterkeys())
        if video_fmt_map and len(video_fmt_map):
            if self.l3cert:
                l3key = validate_cert(self.l3cert, l2key)
                if l3key:
                    rnd = read_random()
                    val = etpm.computeSignature(rnd)
                    result = decrypt_block(val, l3key)
                    if result[80:88] == rnd:
                        print "[YTTrailer] found best available video format:", video_fmt_map[
                            sorted(video_fmt_map.iterkeys())[0]
                        ]["fmtid"]
                        best_video = video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]
                        video_url = "%s" % (best_video["fmturl"].split(";")[0])
                        print "[YTTrailer] found best available video url:", video_url

        return video_url


class YTTrailerList(Screen, YTTrailer):

    skin = """
		<screen name="YTTrailerList" position="center,center" size="580,436" title="YT Trailer-List" backgroundColor="#ff000000">
Beispiel #10
0
				except:
					print "error parsing fmtstring:",fmtstring

                        else:
				(fmtid,fmturl) = fmtstring.split('|')
			if VIDEO_FMT_PRIORITY_MAP.has_key(fmtid) and fmtid != "":
				video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = { 'fmtid': fmtid, 'fmturl': unquote_plus(fmturl) }
				fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
		print "[YTTrailer] got",sorted(fmt_infomap.iterkeys())
		if video_fmt_map and len(video_fmt_map):
			if self.l3cert:
				l3key = validate_cert(self.l3cert, l2key)
				if l3key:
					rnd = read_random()
					val = etpm.challenge(rnd)
					result = decrypt_block(val, l3key)
					if result[80:88] == rnd:
						print "[YTTrailer] found best available video format:",video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]['fmtid']
						best_video = video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]
						video_url = "%s&signature=%s" %(best_video['fmturl'].split(';')[0], best_video['fmtsig'])
						print "[YTTrailer] found best available video url:",video_url
		return video_url

class YTTrailerList(Screen, YTTrailer):

	skin = """
		<screen name="YTTrailerList" position="center,center" size="580,436" title="YT Trailer-List" backgroundColor="#ff000000">
			<widget name="list" position="0,0" size="580,436" />
		</screen>"""

	def __init__(self, session, eventname):
Beispiel #11
0
def startServerInstance(session,
                        port,
                        useauth=False,
                        l2k=None,
                        usessl=False,
                        ipaddress="::",
                        ipaddress2=None):
    l3k = None
    l3c = tpm.getData(eTPM.DT_LEVEL3_CERT)

    if l3c is None:
        return False

    l3k = validate_certificate(l3c, l2k)
    if l3k is None:
        return False

    random = get_random()
    if random is None:
        return False

    value = tpm.computeSignature(random)
    result = decrypt_block(value, l3k)

    if result is None:
        return False
    else:
        if result[80:88] != random:
            return False

    if useauth:
        # HTTPAuthResource handles the authentication for every Resource you want it to
        root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
        site = server.Site(root)
    else:
        root = HTTPRootResource(toplevel)
        site = server.Site(root)

    result = False

    def logFail(addr, exception=None):
        print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (
            addr, port, useauth, usessl)
        if exception:
            print exception

    if usessl:
        ctx = ChainedOpenSSLContextFactory(KEY_FILE, CERT_FILE)
        try:
            d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
            result = True
            running_defered.append(d)
        except CannotListenError as e:
            logFail(ipaddress, e)
        if ipaddress2:
            try:
                d = reactor.listenSSL(port, site, ctx, interface=ipaddress2)
                result = True
                running_defered.append(d)
            except CannotListenError as e:
                logFail(ipaddress2, e)
    else:
        try:
            d = reactor.listenTCP(port, site, interface=ipaddress)
            result = True
            running_defered.append(d)
        except CannotListenError as e:
            logFail(ipaddress, e)
        if ipaddress2:
            try:
                d = reactor.listenTCP(port, site, interface=ipaddress2)
                result = True
                running_defered.append(d)
            except CannotListenError as e:
                logFail(ipaddress2, e)

    print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port,
                                                              useauth, usessl)
    return result
Beispiel #12
0
def validate_cert(cert, key):
	buf = decrypt_block(cert[8:], key) 
	if buf is None:
		return None
	return buf[36:107] + cert[139:196]
Beispiel #13
0
def validate_certificate(cert, key):
	buf = decrypt_block(cert[8:], key)
	if buf is None:
		return None
	return buf[36:107] + cert[139:196]
Beispiel #14
0
def startServerInstance(session, port, useauth=False, l2k=None, usessl=False, ipaddress="::", ipaddress2=None):
	l3k = None
	l3c = tpm.getData(eTPM.DT_LEVEL3_CERT)

	if l3c is None:
		return False

	l3k = validate_certificate(l3c, l2k)
	if l3k is None:
		return False

	random = get_random()
	if random is None:
		return False

	value = tpm.computeSignature(random)
	result = decrypt_block(value, l3k)

	if result is None:
		return False
	else:
		if result [80:88] != random:
			return False

	if useauth:
# HTTPAuthResource handles the authentication for every Resource you want it to
		root = HTTPAuthResource(toplevel, "Enigma2 WebInterface")
		site = server.Site(root)
	else:
		root = HTTPRootResource(toplevel)
		site = server.Site(root)

	result = False

	def logFail(addr, exception=None):
		print "[Webinterface] FAILED to listen on %s:%i auth=%s ssl=%s" % (addr, port, useauth, usessl)
		if exception:
			print exception

	if usessl:
		ctx = ChainedOpenSSLContextFactory(KEY_FILE, CERT_FILE)
		try:
			d = reactor.listenSSL(port, site, ctx, interface=ipaddress)
			result = True
			running_defered.append(d)
		except CannotListenError as e:
			logFail(ipaddress, e)
		if ipaddress2:
			try:
				d = reactor.listenSSL(port, site, ctx, interface=ipaddress2)
				result = True
				running_defered.append(d)
			except CannotListenError as e:
				logFail(ipaddress2, e)
	else:
		try:
			d = reactor.listenTCP(port, site, interface=ipaddress)
			result = True
			running_defered.append(d)
		except CannotListenError as e:
			logFail(ipaddress, e)
		if ipaddress2:
			try:
				d = reactor.listenTCP(port, site, interface=ipaddress2)
				result = True
				running_defered.append(d)
			except CannotListenError as e:
				logFail(ipaddress2, e)
	
	print "[Webinterface] started on %s:%i auth=%s ssl=%s" % (ipaddress, port, useauth, usessl)
	return result
Beispiel #15
0
    def getVideoUrl(self, entry):
        std_headers = {
            'User-Agent':
            'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100627 Firefox/3.6.6',
            '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',
        }

        VIDEO_FMT_PRIORITY_MAP = {
            '18': 4,  #MP4 360p
            '35': 5,  #FLV 480p
            '34': 6,  #FLV 360p
        }

        if int(config.plugins.yttrailer.best_resolution.value) <= 1:
            VIDEO_FMT_PRIORITY_MAP["38"] = 1  #MP4 Original (HD)
            VIDEO_FMT_PRIORITY_MAP["22"] = 3  #MP4 720p (HD)

            if int(config.plugins.yttrailer.best_resolution.value) == 0:
                VIDEO_FMT_PRIORITY_MAP["37"] = 2  #MP4 1080p (HD)

        video_url = None
        video_id = str(self.getTubeId(entry))

        # Getting video webpage
        #URLs for YouTube video pages will change from the format http://www.youtube.com/watch?v=ylLzyHk54Z0 to http://www.youtube.com/watch#!v=ylLzyHk54Z0.
        watch_url = 'http://www.youtube.com/watch?v=%s&gl=US&hl=en' % video_id
        watchrequest = Request(watch_url, None, std_headers)
        try:
            print("[YTTrailer] trying to find out if a HD Stream is available",
                  watch_url)
            watchvideopage = urlopen2(watchrequest).read()
        except (URLError, HTTPException, socket_error) as err:
            print(
                "[YTTrailer] Error: Unable to retrieve watchpage - Error code: ",
                str(err))
            return video_url

        # Get video info
        for el in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
            info_url = (
                'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en'
                % (video_id, el))
            request = Request(info_url, None, std_headers)
            try:
                infopage = urlopen2(request).read()
                videoinfo = parse_qs(infopage)
                if ('url_encoded_fmt_stream_map'
                        or 'fmt_url_map') in videoinfo:
                    break
            except (URLError, HTTPException, socket_error) as err:
                print("[YTTrailer] Error: unable to download video infopage",
                      str(err))
                return video_url

        if ('url_encoded_fmt_stream_map' or 'fmt_url_map') not in videoinfo:
            # Attempt to see if YouTube has issued an error message
            if 'reason' not in videoinfo:
                print(
                    '[YTTrailer] Error: unable to extract "url_encoded_fmt_stream_map" or "fmt_url_map" parameter for unknown reason'
                )
            else:
                reason = unquote_plus(videoinfo['reason'][0])
                print('[YTTrailer] Error: YouTube said: %s' %
                      reason.decode('utf-8'))
            return video_url

        video_fmt_map = {}
        fmt_infomap = {}

        if 'url_encoded_fmt_stream_map' in videoinfo:
            tmp_fmtUrlDATA = videoinfo['url_encoded_fmt_stream_map'][0].split(
                ',')
        else:
            tmp_fmtUrlDATA = videoinfo['fmt_url_map'][0].split(',')
        for fmtstring in tmp_fmtUrlDATA:
            fmturl = fmtid = ""
            if 'url_encoded_fmt_stream_map' in videoinfo:
                try:
                    for arg in fmtstring.split('&'):
                        if arg.find('=') >= 0:
                            print(arg.split('='))
                            key, value = arg.split('=')
                            if key == 'itag':
                                if len(value) > 3:
                                    value = value[:2]
                                fmtid = value
                            elif key == 'url':
                                fmturl = value

                    if fmtid != "" and fmturl != "" and fmtid in VIDEO_FMT_PRIORITY_MAP:
                        video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                            'fmtid': fmtid,
                            'fmturl': unquote_plus(fmturl)
                        }
                        fmt_infomap[int(fmtid)] = "%s" % (unquote_plus(fmturl))
                    fmturl = fmtid = ""

                except:
                    print("error parsing fmtstring:", fmtstring)

            else:
                (fmtid, fmturl) = fmtstring.split('|')
            if fmtid in VIDEO_FMT_PRIORITY_MAP and fmtid != "":
                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                    'fmtid': fmtid,
                    'fmturl': unquote_plus(fmturl)
                }
                fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
        print("[YTTrailer] got", sorted(fmt_infomap.iterkeys()))
        if video_fmt_map and len(video_fmt_map):
            if self.l3cert:
                l3key = validate_cert(self.l3cert, l2key)
                if l3key:
                    rnd = read_random()
                    val = etpm.computeSignature(rnd)
                    result = decrypt_block(val, l3key)
                    if result[80:88] == rnd:
                        print(
                            "[YTTrailer] found best available video format:",
                            video_fmt_map[sorted(
                                video_fmt_map.iterkeys())[0]]['fmtid'])
                        best_video = video_fmt_map[sorted(
                            video_fmt_map.iterkeys())[0]]
                        video_url = "%s" % (best_video['fmturl'].split(';')[0])
                        print("[YTTrailer] found best available video url:",
                              video_url)

        return video_url