Exemplo n.º 1
0
    def init_downloads_table(self):
        try:
            datas =[]
            row = 0
            files= os.listdir(init.download_info_folder)
            for file_path in files:
                with open(os.path.join(init.download_info_folder,file_path)) as f:
                    info = f.readline()
                    info = json.loads(info)
                datas.append(info)

            for i in range(len(datas)-1):
                Max=float((datas[i])['last_try'])
                index = i
                for j in range(i+1,len(datas)):
                    el =float((datas[j])['last_try'])
                    if el > Max :
                        Max = el
                        index = j
                t = datas[i]
                datas[i] = datas[index]
                datas[index] = t

            for info in datas:
                self.downloads_tw.setRowCount(row+1)
                for j in range(self.downloads_tw_cols):
                    if j == 0:
                        item = QtWidgets.QTableWidgetItem(unquote(os.path.basename(info['file_path'])))
                        self.downloads_tw.setItem(row , j , item)
                    if j == 1:
                        item = QtWidgets.QTableWidgetItem(info['status'])
                        item.url = info['link']
                        item.file_size = info['file_size']
                        self.downloads_tw.setItem(row , j , item)

                    if j == 2:
                        item = QtWidgets.QTableWidgetItem(Download.h_size(info['file_size']))
                        self.downloads_tw.setItem(row , j , item)
                    if j == 3:
                        
                        item = QtWidgets.QTableWidgetItem(info['percent']+' %')
                        self.downloads_tw.setItem(row , j , item)
                    
                    if j == 4:
                        item = QtWidgets.QTableWidgetItem(Download.h_size(info['last_byte']))
                        self.downloads_tw.setItem(row , j , item)

                    if j== 5:
                        item = QtWidgets.QTableWidgetItem(time.ctime(float(info['last_try'])))
                        self.downloads_tw.setItem(row , j , item)




                row += 1
        except Exception as e:
            print(str(e))
Exemplo n.º 2
0
    def info_has_found(self,info_tuple):
        self.yes_pb.setEnabled(True)
        size , file_type = info_tuple
        self.real_size = size
        try:
            ext = re.search(r'\.((\w{,3}\.)?\w{,3})$' , self.url).group(1)
        except :
            pass
        if re.search(r'application/octet-stream',file_type):
            if 'mkv' in ext or 'mp4' in ext   or 'avi' in ext :
                ext = ext[-3:]
                self.fileType_la.setText(ext)
                self.filePicture_la.setPixmap(QtGui.QPixmap(self.videoPicAddr))
            elif ext == 'exe': 
                self.fileType_la.setText(ext)
                self.filePicture_la.setPixmap(QtGui.QPixmap(self.softPicAddr))
            elif ext == 'mp3': 
                self.fileType_la.setText(ext)
                self.filePicture_la.setPixmap(QtGui.QPixmap(self.musicPicAddr))
            else:
                self.fileType_la.setText('Unknown')

        elif re.search(r'application/pdf',file_type ):
            self.fileType_la.setText('pdf')
            self.filePicture_la.setPixmap(QtGui.QPixmap(self.pdfPicAddr))
        elif re.search(r'text/html',file_type):
            self.fileType_la.setText('html')
            self.filePicture_la.setPixmap(QtGui.QPixmap(self.filePicAddr))

        
        size = Download.h_size(int(size))
        self.size_la.setText(size)
Exemplo n.º 3
0
    def run(self):
        try: size , file_type = Download.check_url(self.url)

        except Exception as e:
            print(str(e))

        else:
            self.infoHasFound.emit((size,file_type))
Exemplo n.º 4
0
    def showEvent(self, event):
        self.url_le.setText(self.url)
        print('downloading')
        self.status_la.setText('Downloading ...')
        self.fileSize_la.setText(Download.h_size(self.file_size))

        #download the url in seprate thread
        self.make_thread(self.resume)
Exemplo n.º 5
0
    def __init__(self,
                 link,
                 file_path,
                 file_size,
                 frange='0-',
                 chunk_counter=0):
        Download.__init__(self, link, file_path, file_size, frange,
                          chunk_counter)
        QThread.__init__(self)
        self.m_time = 1

        self.timer = Timer()

        #we need stop watch for counting every one second
        self.st_watch = StopWatch(self.m_time)

        #this the downloaded amount within one second
        self.tmp_downloaded = 0
Exemplo n.º 6
0
 def download_finished_or_stoped(self, status):
     self.parent.init_downloads_table()
     if status == 'complete':
         print('download complete')
         self.parent.download_finished(self.url,
                                       Download.h_size(self.file_size),
                                       self.file_name)
         self.close()
     elif status == 'stoped':
         print('download stoped')
         self.close()
     elif status == 'paused':
         pass
Exemplo n.º 7
0
 def downloaded_slot(self, size):
     self.downloaded_la.setText(Download.h_size(size))