def YTubeDownload(self, url, recv, PARTS, info, wMutex, flag): ''' Calls a Youtube download by fetching the link ''' self.info = info if recv == None: return headers = {'User-Agent': 'LINUX DOWNLOAD MANAGER'} # build header req = urllib2.Request(url, None, headers) proXy = {} proxy_info = UIXML().getProxyInformation('&LDM') try: if len(proxy_info) == 2: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proxy = "http://%(host)s:%(port)d" % proXy info = {"http": ""} info["http"] = "http://%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add proxy information elif len(proxy_info) == 4: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proXy['user'] = str(proxy_info[2]) proXy['pass'] = str(int(proxy_info[3])) proxy = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy info = {"http": ""} info[ "http"] = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add USER & PASS else: opener = urllib2.build_opener() # build empty handler except Exception, e: print "Error ", str(e) sys.exit(0)
def __init__(self, parent=None, loc=None, user=None): QtGui.QWidget.__init__(self, parent) self.setWindowTitle('Network Configuration') self.username = user self.authenticated = 1 self.posMove = None self.setWindowFlags(QtCore.Qt.FramelessWindowHint) self.uixml = UIXML(os.getcwd()) okay = QtGui.QPushButton('Ok') cancel = QtGui.QPushButton('Cancel') hbox3 = QtGui.QHBoxLayout() hbox3.addWidget(okay) hbox3.addWidget(cancel) lhttp = QtGui.QLabel('HTTPProxy: ') lport = QtGui.QLabel('Port: ') self.http = QtGui.QLineEdit() self.port = QtGui.QLineEdit() hbox1 = QtGui.QHBoxLayout() hbox1.addWidget(lhttp) hbox1.addWidget(self.http) hbox1.addWidget(lport) hbox1.addWidget(self.port) self.cbox = QtGui.QCheckBox('No Authentication') userl = QtGui.QLabel('Username: '******'Password: '******'Network Proxy') self.connect(self.cbox, QtCore.SIGNAL('stateChanged(int)'), self.Authenticate) self.connect(okay, QtCore.SIGNAL('clicked()'), self.Finalize) self.connect(cancel, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('close()'))
def YTubePartition(self, info, recv, PARTS, wMutex, flag, bit): ''' It download if resume is called with download information ''' if recv == None: return if not (os.path.exists(os.getcwd() + '/Download/' + info.fileName + '_LDM')): ''' Checks if file with past download is not present is start-over again ''' info = self.YTubeDownload(info.url, recv, PARTS, info, wMutex, flag) return info[0], info[1], 0 if bit == 1: ''' If url is a youtube url Link is fetched again ''' headers = { 'User-Agent': 'LINUX DOWNLOAD MANAGER' } # building of header req = urllib2.Request(info.url, None, headers) proXy = {} proxy_info = UIXML().getProxyInformation('&LDM') try: if len(proxy_info) == 2: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proxy = "http://%(host)s:%(port)d" % proXy info = {"http": ""} info["http"] = "http://%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener( handler) # Add proxy information elif len(proxy_info) == 4: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proXy['user'] = str(proxy_info[2]) proXy['pass'] = str(int(proxy_info[3])) proxy = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy info = {"http": ""} info[ "http"] = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add USER & PASS else: opener = urllib2.build_opener() # build empty handler except Exception, e: print "Error ", str(e) s = opener.open(req).read() # reads html search = re.search(self.regX, s) if search: url = 'http' + urllib2.unquote(search.group(1))
def Download(self, url, recv, PARTS, info, wMutex, flag, fileName=''): ''' Takes a url fetches it's information & partition it to calls download routine ''' self.flag = flag # To keep track of signal send to it from GUI self.wMutex = wMutex # Synchronize Loading of information & writing of information of a download self.transmit = recv # Communication PIPE self.url = url # Url or location form where to download self.info = info # Have download prtition & information if len(url) == 0: return if len(fileName ) == 0: # If filename not present , read it from the link self.aUrl = url fileName = url.split('/') fileName = fileName[len(fileName) - 1] fileName = self.InAscii(fileName) req = urllib2.Request( url, None, {'User-Agent': 'LINUX DOWNLOAD MANAGER'}) # build the header proXy = {} proxy_info = UIXML().getProxyInformation('&LDM') try: if len(proxy_info) == 2: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proxy = "http://%(host)s:%(port)d" % proXy info = {"http": ""} info["http"] = "http://%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add proxy information elif len(proxy_info) == 4: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proXy['user'] = str(proxy_info[2]) proXy['pass'] = str(int(proxy_info[3])) proxy = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy info = {"http": ""} info[ "http"] = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add USER & PASS else: opener = urllib2.build_opener() # build empty handler except Exception, e: print "Error ", str(e) sys.exit(0)
def forkVariousPart(self, obj, url, fileName, transmit, monitor): ''' To fetch individual part this technique is used ''' if obj.UL - (obj.LL + obj.length.value ) <= 0: # checks whether partition is a valid partition sys.exit(0) # intializes state obj.LOCK.value = 2 req = urllib2.Request(url) # perform the request from the url proXy = {} proxy_info = UIXML().getProxyInformation( '&LDM' ) # If user is working under a proxy , fetches proxy information try: if len(proxy_info) == 2: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proxy = "http://%(host)s:%(port)d" % proXy info = {"http": ""} info["http"] = "http://%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add proxy information elif len(proxy_info) == 4: proXy['host'] = str(proxy_info[0]) proXy['port'] = int(proxy_info[1]) proXy['user'] = str(proxy_info[2]) proXy['pass'] = str(int(proxy_info[3])) proxy = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy info = {"http": ""} info[ "http"] = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proXy handler = urllib2.ProxyHandler(info) opener = urllib2.build_opener(handler) # Add USER & PASS else: opener = urllib2.build_opener() # build empty handler except Exception, e: print "Error : ", str(e)