def downloadUnpause(gid): download_info_file = os.path.join(download_info_folder, gid) readList(download_info_file) # this section is sending unpause request to aria2 . see aria2 # documentation for more informations. try: answer = server.aria2.unpause(gid) version_answer = 'ok' except: answer = str("None") return answer
def endTime(end_hour, end_minute, gid): time.sleep(1) print("end time is actived " + gid) logger.sendToLog("End time is activated " + gid, "INFO") sigma_end = sigmaTime(end_hour, end_minute) sigma_now = nowTime() download_info_file = os.path.join(download_info_folder, gid) while sigma_end != sigma_now: status_file = 'no' # waiting for start downloading : while status_file == 'no': time.sleep(0.5) try: download_info_file_list = readList(download_info_file) status_file = 'yes' status = download_info_file_list[1] except: status_file = 'no' # checking download's status if status == 'downloading' or status == 'paused' or status == 'waiting': answer = 'continue' else: answer = 'end' print("Download ended before! " + str(gid)) logger.sendToLog("Download has been finished! " + str(gid), "INFO") break sigma_now = nowTime() time.sleep(2.1) if answer != 'end': print("Time is Up") logger.sendToLog("Time is up!", "INFO") answer = downloadStop(gid) i = 0 # trying to stop download 10 times while answer == 'None' and (i <= 9): time.sleep(1) answer = downloadStop(gid) i = i + 1 if (answer == 'None') and (os_type != 'Windows'): os.system("killall aria2c") download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None download_info_file_list[9] = add_link_dictionary download_info_file_list[1] = "stopped" writeList(download_info_file, download_info_file_list)
def downloadPause(gid): download_info_file = os.path.join(download_info_folder, gid) readList(download_info_file) # this section is sending pause request to aira2 . see aria2 documentation # for more informations try: answer = server.aria2.pause(gid) version_answer = 'ok' except: answer = str("None") print(answer + " paused") logger.sendToLog(answer + " paused", "INFO") return answer
def downloadStop(gid): download_info_file = download_info_folder + "/" + gid download_info_file_list = readList(download_info_file) status = download_info_file_list[1] if status != 'scheduled': try: answer = server.aria2.remove(gid) if status == 'downloading': server.aria2.removeDownloadResult(gid) except: answer = str("None") print(answer + " stopped") else: answer = 'stopped' if answer != 'None' or (answer == 'None' and status == 'waiting'): add_link_dictionary = download_info_file_list[9] add_link_dictionary['start_hour'] = None add_link_dictionary['start_minute'] = None add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None add_link_dictionary['after_download'] = 'None' download_info_file_list[1] = "stopped" download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list) return answer
def downloadStop(gid): download_info_file = os.path.join(download_info_folder, gid) download_info_file_list = readList(download_info_file) version_answer = 'ok' #if status is scheduled so download request is not sended to aria2 yet! status = download_info_file_list[1] if status != 'scheduled': try: #this section is sending request to aria2 to removing download. see aria2 documentation for more informations answer = server.aria2.remove(gid) if status == 'downloading': server.aria2.removeDownloadResult(gid) except: answer = str("None") print(answer + " stopped") else: answer = 'stopped' if status != 'complete': add_link_dictionary = download_info_file_list[9] add_link_dictionary['start_hour'] = None add_link_dictionary['start_minute'] = None add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None add_link_dictionary['after_download'] = 'None' download_info_file_list[1] = "stopped" download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list) return answer
def startTime(start_hour, start_minute, gid): print("Download starts at " + start_hour + ":" + start_minute) logger.sendToLog("Download starts at " + start_hour + ":" + start_minute, "INFO") sigma_start = sigmaTime(start_hour, start_minute) # getting sima time sigma_now = nowTime() # getting sigma now time # getting download_info_file path download_info_file = os.path.join(download_info_folder, gid) status = 'scheduled' # defining status while sigma_start != sigma_now: # this loop is countinuing until download time arrival! time.sleep(2.1) sigma_now = nowTime() try: # this part is reading download informations for finding download status , perhaps user canceled download! try command used for avoiding some problems when readList reading files download_info_file_list = readList(download_info_file) except: download_info_file_list = ['some_name', 'scheduled'] # if download_info_file_list[1] = stopped >> it means that user # canceled download , and loop is breaking! if download_info_file_list[1] == 'stopped': status = 'stopped' break else: status = 'scheduled' return status # if user canceled download , then 'stopped' returns and if download time arrived then 'scheduled' returns!
def endTime(end_hour, end_minute, gid): time.sleep(1) print("end time actived") sigma_end = sigmaTime(end_hour, end_minute) sigma_now = nowTime() download_info_file = download_info_folder + "/" + gid while sigma_end != sigma_now: status_file = 'no' #wait for start downloading : while status_file == 'no': time.sleep(0.5) try: download_info_file_list = readList(download_info_file) status_file = 'yes' status = download_info_file_list[1] except: status_file = 'no' #check download's status if status == 'downloading' or status == 'paused': answer = 'continue' else: answer = 'end' print("Download ended before!") break sigma_now = nowTime() time.sleep(1.1) if answer != 'end': print("Time is Up") answer = downloadStop(gid) i = 0 while answer == 'None' and (i <= 9): time.sleep(1) answer = downloadStop(gid) i = i + 1 if answer == 'None': os.system("killall aria2c") download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None download_info_file_list[9] = add_link_dictionary download_info_file_list[1] = "stopped" writeList(download_info_file, download_info_file_list)
def __init__(self, parent, gid, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.parent = parent self.gid = gid self.status = None self.resume_pushButton.clicked.connect(self.resumePushButtonPressed) self.stop_pushButton.clicked.connect(self.stopPushButtonPressed) self.pause_pushButton.clicked.connect(self.pausePushButtonPressed) self.download_progressBar.setValue(0) self.limit_pushButton.clicked.connect(self.limitPushButtonPressed) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitCheckBoxToggled) self.after_frame.setEnabled(False) self.after_checkBox.toggled.connect(self.afterCheckBoxToggled) self.after_pushButton.clicked.connect(self.afterPushButtonPressed) # check if limit speed actived by user or not download_info_file_list_len = 1 while download_info_file_list_len != 13: download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) download_info_file_list_len = len(download_info_file_list) add_link_dictionary = download_info_file_list[9] limit = add_link_dictionary['limit'] if limit != 0: limit_number = limit[:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(int(limit_number)) if limit_unit == 'K': self.after_comboBox.setCurrentIndex(0) else: self.after_comboBox.setCurrentIndex(1) self.limit_checkBox.setChecked(True) self.after_comboBox.currentIndexChanged.connect( self.afterComboBoxChanged) self.limit_comboBox.currentIndexChanged.connect( self.limitComboBoxChanged) self.limit_spinBox.valueChanged.connect(self.limitComboBoxChanged) # setting window size and position size = self.persepolis_setting.value('ProgressWindow/size', QSize(595, 274)) position = self.persepolis_setting.value('ProgressWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
def limitCheckBoxToggled(self, checkBoxes): if self.limit_checkBox.isChecked() == True: self.limit_frame.setEnabled(True) self.limit_pushButton.setEnabled(True) else: self.limit_frame.setEnabled(False) if self.status != 'scheduled': download.limitSpeed(self.gid, "0") else: download_info_file = download_info_folder + '/' + self.gid download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] add_link_dictionary['limit'] = '0' download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list)
def limitPushButtonPressed(self, button): self.limit_pushButton.setEnabled(False) if self.limit_comboBox.currentText() == "KB/S": limit = str(self.limit_spinBox.value()) + str("K") else: limit = str(self.limit_spinBox.value()) + str("M") #if download was started before , send the limit_speed request to aria2 . else save the request in download_information_file if self.status != 'scheduled': download.limitSpeed(self.gid, limit) else: download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] add_link_dictionary['limit'] = limit download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list)
def startTime(start_hour, start_minute, gid): print("Download starts at " + start_hour + ":" + start_minute) sigma_start = sigmaTime(start_hour, start_minute) sigma_now = nowTime() download_info_file = download_info_folder + "/" + gid status = 'scheduled' while sigma_start != sigma_now: time.sleep(1.1) sigma_now = nowTime() download_info_file_list = readList(download_info_file) if download_info_file_list[1] == 'stopped': status = 'stopped' break else: status = 'scheduled' return status
def __init__(self, parent, gid): super().__init__() self.parent = parent self.gid = gid self.status = None self.resume_pushButton.clicked.connect(self.resumePushButtonPressed) self.stop_pushButton.clicked.connect(self.stopPushButtonPressed) self.pause_pushButton.clicked.connect(self.pausePushButtonPressed) self.download_progressBar.setValue(0) self.limit_pushButton.clicked.connect(self.limitPushButtonPressed) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitCheckBoxToggled) self.after_frame.setEnabled(False) self.after_checkBox.toggled.connect(self.afterCheckBoxToggled) self.after_pushButton.clicked.connect(self.afterPushButtonPressed) #check if limit speed actived by user or not download_info_file_list_len = 1 while download_info_file_list_len != 10: download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) download_info_file_list_len = len(download_info_file_list) add_link_dictionary = download_info_file_list[9] limit = add_link_dictionary['limit'] if limit != 0: limit_number = limit[:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(int(limit_number)) if limit_unit == 'K': self.after_comboBox.setCurrentIndex(0) else: self.after_comboBox.setCurrentIndex(1) self.limit_checkBox.setChecked(True) self.after_comboBox.currentIndexChanged.connect( self.afterComboBoxChanged) self.limit_comboBox.currentIndexChanged.connect( self.limitComboBoxChanged) self.limit_spinBox.valueChanged.connect(self.limitComboBoxChanged)
def __init__(self,callback,gid): super().__init__() self.callback = callback self.gid = gid f = Open(setting_file) setting_file_lines = f.readlines() f.close() setting_dict_str = str(setting_file_lines[0].strip()) setting_dict = ast.literal_eval(setting_dict_str) global connections connections = int(setting_dict['connections']) #connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) self.download_folder_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.link_lineEdit.textChanged.connect(self.linkLineChanged) # connect OK and canel button self.cancel_pushButton.clicked.connect(self.cancelButtonPressed) self.ok_pushButton.clicked.connect(self.okButtonPressed) #frames and checkBoxes self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) self.start_frame.setEnabled(False) self.start_checkBox.toggled.connect(self.startFrame) self.end_frame.setEnabled(False) self.end_checkBox.toggled.connect(self.endFrame) #initialization self.connections_spinBox.setValue(connections) download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) self.add_link_dictionary = download_info_file_list[9] #disable folder_frame when download is complete status = download_info_file_list[1] if status == 'complete': self.folder_frame.setEnabled(False) #link self.link_lineEdit.setText(self.add_link_dictionary['link']) #ip_lineEdit initialization if self.add_link_dictionary['ip'] != None : self.proxy_checkBox.setChecked(True) self.ip_lineEdit.setText(self.add_link_dictionary['ip']) #port_spinBox initialization try: self.port_spinBox.setValue(int(self.add_link_dictionary['port'])) except : pass #proxy user lineEdit initialization try: self.proxy_user_lineEdit.setText(self.add_link_dictionary['proxy_user']) except : pass #proxy pass lineEdit initialization try: self.proxy_pass_lineEdit.setText(self.add_link_dictionary['proxy_passwd']) except : pass #download UserName initialization if self.add_link_dictionary['download_user'] != None : self.download_checkBox.setChecked(True) self.download_user_lineEdit.setText(self.add_link_dictionary['download_user']) #download PassWord initialization try: self.download_pass_lineEdit.setText(self.add_link_dictionary['download_passwd']) except : pass #folder_path if self.add_link_dictionary['final_download_path'] != None : self.download_folder_lineEdit.setText(str(self.add_link_dictionary['final_download_path'])) else: try: self.download_folder_lineEdit.setText(self.add_link_dictionary['download_path']) except: pass #connections try: self.connections_spinBox.setValue(int(self.add_link_dictionary['connections'])) except : pass #limit speed limit = str(self.add_link_dictionary['limit']) if limit != '0' : self.limit_checkBox.setChecked(True) limit_number = limit[0:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(int(limit_number)) if limit_unit == "K": self.limit_comboBox.setCurrentIndex(0) else : self.limit_comboBox.setCurrentIndex(1) #start_time if self.add_link_dictionary['start_hour'] != None : self.start_checkBox.setChecked(True) self.start_hour_spinBox.setValue(int(self.add_link_dictionary['start_hour'])) self.start_minute_spinBox.setValue(int(self.add_link_dictionary['start_minute'])) #end_time if self.add_link_dictionary['end_hour'] != None : self.end_checkBox.setChecked(True) self.end_hour_spinBox.setValue(int(self.add_link_dictionary['end_hour'])) self.end_minute_spinBox.setValue(int(self.add_link_dictionary['end_minute']))
def __init__(self, callback, gid, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.download_later_pushButton.hide() # hiding download_later_pushButton self.change_name_checkBox.hide() # hiding change_name_checkBox self.change_name_lineEdit.hide() # hiding change_name_lineEdit self.callback = callback self.gid = gid global connections connections = int( self.persepolis_setting.value('settings/connections')) # connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) self.download_folder_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.link_lineEdit.textChanged.connect(self.linkLineChanged) # connect OK and canel button self.cancel_pushButton.clicked.connect(self.close) self.ok_pushButton.clicked.connect(self.okButtonPressed) #frames and checkBoxes self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) self.start_frame.setEnabled(False) self.start_checkBox.toggled.connect(self.startFrame) self.end_frame.setEnabled(False) self.end_checkBox.toggled.connect(self.endFrame) # initialization self.connections_spinBox.setValue(connections) download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) self.add_link_dictionary = download_info_file_list[9] # disable folder_frame when download is complete status = download_info_file_list[1] if status == 'complete': self.folder_frame.setEnabled(False) # link self.link_lineEdit.setText(self.add_link_dictionary['link']) # ip_lineEdit initialization if self.add_link_dictionary['ip'] != None: self.proxy_checkBox.setChecked(True) self.ip_lineEdit.setText(self.add_link_dictionary['ip']) # port_spinBox initialization try: self.port_spinBox.setValue( int(self.add_link_dictionary['port'])) except: pass # proxy user lineEdit initialization try: self.proxy_user_lineEdit.setText( self.add_link_dictionary['proxy_user']) except: pass # proxy pass lineEdit initialization try: self.proxy_pass_lineEdit.setText( self.add_link_dictionary['proxy_passwd']) except: pass # download UserName initialization if self.add_link_dictionary['download_user'] != None: self.download_checkBox.setChecked(True) self.download_user_lineEdit.setText( self.add_link_dictionary['download_user']) # download PassWord initialization try: self.download_pass_lineEdit.setText( self.add_link_dictionary['download_passwd']) except: pass # folder_path if self.add_link_dictionary['final_download_path'] != None: self.download_folder_lineEdit.setText( str(self.add_link_dictionary['final_download_path'])) else: try: self.download_folder_lineEdit.setText( self.add_link_dictionary['download_path']) except: pass # connections try: self.connections_spinBox.setValue( int(self.add_link_dictionary['connections'])) except: pass # finding categories name and adding them to add_queue_comboBox self.add_queue_comboBox.addItem('Single Downloads') f_queues_list = Open(queues_list_file) queues_list_file_lines = f_queues_list.readlines() f_queues_list.close() for queue in queues_list_file_lines: queue_strip = queue.strip() self.add_queue_comboBox.addItem(str(queue_strip)) # finding current queue and setting it! self.current_category = str(download_info_file_list[12]) current_category_index = self.add_queue_comboBox.findText( self.current_category) self.add_queue_comboBox.setCurrentIndex(current_category_index) # add_queue_comboBox event self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged) # limit speed limit = str(self.add_link_dictionary['limit']) if limit != '0': self.limit_checkBox.setChecked(True) limit_number = limit[0:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(int(limit_number)) if limit_unit == "K": self.limit_comboBox.setCurrentIndex(0) else: self.limit_comboBox.setCurrentIndex(1) # start_time if self.add_link_dictionary['start_hour'] != None: self.start_checkBox.setChecked(True) self.start_hour_spinBox.setValue( int(self.add_link_dictionary['start_hour'])) self.start_minute_spinBox.setValue( int(self.add_link_dictionary['start_minute'])) # end_time if self.add_link_dictionary['end_hour'] != None: self.end_checkBox.setChecked(True) self.end_hour_spinBox.setValue( int(self.add_link_dictionary['end_hour'])) self.end_minute_spinBox.setValue( int(self.add_link_dictionary['end_minute'])) # setting window size and position size = self.persepolis_setting.value( 'PropertiesWindow/size', QSize(700, 500)) position = self.persepolis_setting.value( 'PropertiesWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
def downloadStatus(gid): try: download_status = server.aria2.tellStatus(gid, [ 'status', 'connections', 'errorCode', 'errorMessage', 'downloadSpeed', 'connections', 'dir', 'totalLength', 'completedLength', 'files' ]) except: download_status = { 'status': None, 'connections': None, 'errorCode': None, 'errorMessage': None, 'downloadSpeed': None, 'connections': None, 'dir': None, 'totalLength': None, 'completedLength': None, 'files': None } #file_status contains name of download file try: file_status = str(download_status['files']) file_status = file_status[1:-1] file_status = ast.literal_eval(file_status) path = file_status['path'] file_name = str(path.split("/")[-1]) if not (file_name): file_name = None except: file_name = None for i in download_status.keys(): if not (download_status[i]): download_status[i] = None try: file_size = float(download_status['totalLength']) except: file_size = None try: downloaded = float(download_status['completedLength']) except: downloaded = None if (downloaded != None and file_size != None and file_size != 0): file_size_back = file_size if int(file_size / 1073741824) != 0: file_size = file_size / 1073741824 size_str = str(round(file_size, 2)) + " GB" elif int(file_size / 1048576) != 0: size_str = str(int(file_size / 1048576)) + " MB" elif int(file_size / 1024) != 0: size_str = str(int(file_size / 1024)) + " KB" else: size_str = str(file_size) downloaded_back = downloaded if int(downloaded / 1073741824) != 0: downloaded = downloaded / 1073741824 downloaded_str = str(round(downloaded, 2)) + " GB" elif int((downloaded / 1048576)) != 0: downloaded_str = str(int(downloaded / 1048576)) + " MB" elif int(downloaded / 1024) != 0: downloaded_str = str(int(downloaded / 1024)) + " KB" else: downloaded_str = str(downloaded) file_size = file_size_back downloaded = downloaded_back percent = int(downloaded * 100 / file_size) percent_str = str(percent) + " %" else: percent_str = None size_str = None downloaded_str = None try: download_speed = int(download_status['downloadSpeed']) except: download_speed = 0 if (downloaded != None and download_speed != 0): estimate_time_left = int((file_size - downloaded) / download_speed) if int((download_speed / 1073741824)) != 0: download_speed = download_speed / 1073741824 download_speed_str = str(round(download_speed, 2)) + " GB/S" elif int((download_speed / 1048576)) != 0: download_speed_num = download_speed / 1048576 download_speed_str = str(round(download_speed_num, 2)) + " MB/S" elif int((download_speed / 1024)) != 0: download_speed_str = str(int(download_speed / 1024)) + " KB/S" else: download_speed_str = str(download_speed) eta = "" if estimate_time_left >= 3600: eta = eta + str(int(estimate_time_left / 3600)) + "h" estimate_time_left = estimate_time_left % 3600 eta = eta + str(int(estimate_time_left / 60)) + "m" estimate_time_left = estimate_time_left % 60 eta = eta + str(estimate_time_left) + "s" elif estimate_time_left >= 60: eta = eta + str(int(estimate_time_left / 60)) + "m" estimate_time_left = estimate_time_left % 60 eta = eta + str(estimate_time_left) + "s" else: eta = eta + str(estimate_time_left) + "s" estimate_time_left_str = eta else: download_speed_str = "0" estimate_time_left_str = None try: connections_str = str(download_status['connections']) except: connections_str = None try: status_str = str(download_status['status']) except: status_str = None download_info_file = download_info_folder + "/" + gid download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] download_path = add_link_dictionary['download_path'] final_download_path = add_link_dictionary['final_download_path'] #if final_download_path did not defined and download_path equaled to user default download folder then find final_download_path according to file extension if final_download_path == None: if file_name != None: #finding default download_path f = Open(setting_file) setting_file_lines = f.readlines() f.close() setting_dict_str = str(setting_file_lines[0].strip()) setting_dict = ast.literal_eval(setting_dict_str) if setting_dict['download_path'] == download_path: final_download_path = findDownloadPath(file_name, download_path) add_link_dictionary[ 'final_download_path'] = final_download_path #if download completed move file to the download folder if (status_str == "complete"): if final_download_path != None: download_path = final_download_path file_path = downloadCompleteAction(path, download_path, file_name) add_link_dictionary['file_path'] = file_path file_path_split = file_path.split('/') file_name = str(file_path_split[-1]) #rename active status to downloading if (status_str == "active"): status_str = "downloading" #rename removed status to stopped if (status_str == "removed"): status_str = "stopped" if (status_str == "error"): add_link_dictionary["error"] = str(download_status['errorMessage']) if (status_str == "None"): status_str = None download_info = [ file_name, status_str, size_str, downloaded_str, percent_str, connections_str, download_speed_str, estimate_time_left_str, None, add_link_dictionary ] for i in range(10): if download_info[i] != None: download_info_file_list[i] = download_info[i] writeList(download_info_file, download_info_file_list) return 'ready'
def downloadStatus(gid): try: download_status = server.aria2.tellStatus(gid, [ 'status', 'connections', 'errorCode', 'errorMessage', 'downloadSpeed', 'connections', 'dir', 'totalLength', 'completedLength', 'files' ]) except: download_status = { 'status': None, 'connections': None, 'errorCode': None, 'errorMessage': None, 'downloadSpeed': None, 'connections': None, 'dir': None, 'totalLength': None, 'completedLength': None, 'files': None } #file_status contains name of download file try: file_status = str(download_status['files']) file_status = file_status[1:-1] file_status = ast.literal_eval(file_status) path = str(file_status['path']) file_name = os.path.basename(path) if not (file_name): file_name = None except: file_name = None for i in download_status.keys(): if not (download_status[i]): download_status[i] = None try: file_size = float(download_status['totalLength']) except: file_size = None try: downloaded = float(download_status['completedLength']) except: downloaded = None if (downloaded != None and file_size != None and file_size != 0): file_size_back = file_size if int(file_size / 1073741824) != 0: file_size = file_size / 1073741824 size_str = str(round(file_size, 2)) + " GB" elif int(file_size / 1048576) != 0: size_str = str(int(file_size / 1048576)) + " MB" elif int(file_size / 1024) != 0: size_str = str(int(file_size / 1024)) + " KB" else: size_str = str(file_size) downloaded_back = downloaded if int(downloaded / 1073741824) != 0: downloaded = downloaded / 1073741824 downloaded_str = str(round(downloaded, 2)) + " GB" elif int((downloaded / 1048576)) != 0: downloaded_str = str(int(downloaded / 1048576)) + " MB" elif int(downloaded / 1024) != 0: downloaded_str = str(int(downloaded / 1024)) + " KB" else: downloaded_str = str(downloaded) file_size = file_size_back downloaded = downloaded_back percent = int(downloaded * 100 / file_size) percent_str = str(percent) + "%" else: percent_str = None size_str = None downloaded_str = None try: download_speed = int(download_status['downloadSpeed']) except: download_speed = 0 if (downloaded != None and download_speed != 0): estimate_time_left = int((file_size - downloaded) / download_speed) if int((download_speed / 1073741824)) != 0: download_speed = download_speed / 1073741824 download_speed_str = str(round(download_speed, 2)) + " GB/S" elif int((download_speed / 1048576)) != 0: download_speed_num = download_speed / 1048576 download_speed_str = str(round(download_speed_num, 2)) + " MB/S" elif int((download_speed / 1024)) != 0: download_speed_str = str(int(download_speed / 1024)) + " KB/S" else: download_speed_str = str(download_speed) eta = "" if estimate_time_left >= 3600: eta = eta + str(int(estimate_time_left / 3600)) + "h" estimate_time_left = estimate_time_left % 3600 eta = eta + str(int(estimate_time_left / 60)) + "m" estimate_time_left = estimate_time_left % 60 eta = eta + str(estimate_time_left) + "s" elif estimate_time_left >= 60: eta = eta + str(int(estimate_time_left / 60)) + "m" estimate_time_left = estimate_time_left % 60 eta = eta + str(estimate_time_left) + "s" else: eta = eta + str(estimate_time_left) + "s" estimate_time_left_str = eta else: download_speed_str = "0" estimate_time_left_str = None try: connections_str = str(download_status['connections']) except: connections_str = None try: status_str = str(download_status['status']) except: status_str = None download_info_file = os.path.join(download_info_folder, gid) download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] download_path = add_link_dictionary['download_path'] final_download_path = add_link_dictionary['final_download_path'] #if final_download_path did not defined and download_path equaled to user default download folder then this section is finding final_download_path according to file extension if final_download_path == None: if file_name != None: #finding default download_path persepolis_setting.sync() if persepolis_setting.value( 'settings/download_path') == download_path: final_download_path = findDownloadPath(file_name, download_path) add_link_dictionary[ 'final_download_path'] = final_download_path else: final_download_path = download_path add_link_dictionary[ 'final_download_path'] = final_download_path #if download has completed , then move file to the download folder if (status_str == "complete"): if final_download_path != None: download_path = final_download_path file_path = downloadCompleteAction(path, download_path, file_name) add_link_dictionary['file_path'] = file_path file_name = os.path.basename(file_path) #rename active status to downloading if (status_str == "active"): status_str = "downloading" #rename removed status to stopped if (status_str == "removed"): status_str = "stopped" if (status_str == "error"): add_link_dictionary["error"] = str(download_status['errorMessage']) if (status_str == "None"): status_str = None #setting firs_try_date and last_try_date date_list = add_link_dictionary['firs_try_date'] firs_try_date = str(date_list[0]) + '/' + str(date_list[1]) + '/' + str( date_list[2]) + ' , ' + str(date_list[3]) + ':' + str( date_list[4]) + ':' + str(date_list[5]) date_list = add_link_dictionary['last_try_date'] last_try_date = str(date_list[0]) + '/' + str(date_list[1]) + '/' + str( date_list[2]) + ' , ' + str(date_list[3]) + ':' + str( date_list[4]) + ':' + str(date_list[5]) download_info = [ file_name, status_str, size_str, downloaded_str, percent_str, connections_str, download_speed_str, estimate_time_left_str, None, add_link_dictionary, firs_try_date, last_try_date ] for i in range(12): if download_info[i] != None: download_info_file_list[i] = download_info[i] writeList(download_info_file, download_info_file_list) return 'ready'
def downloadAria(gid): #add_link_dictionary is a dictionary that contains user download request information download_info_file = os.path.join(download_info_folder, gid) download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] link = add_link_dictionary['link'] ip = add_link_dictionary['ip'] port = add_link_dictionary['port'] proxy_user = add_link_dictionary['proxy_user'] proxy_passwd = add_link_dictionary['proxy_passwd'] download_user = add_link_dictionary['download_user'] download_passwd = add_link_dictionary['download_passwd'] connections = add_link_dictionary['connections'] limit = add_link_dictionary['limit'] start_hour = add_link_dictionary['start_hour'] start_minute = add_link_dictionary['start_minute'] end_hour = add_link_dictionary['end_hour'] end_minute = add_link_dictionary['end_minute'] header = add_link_dictionary['header'] out = add_link_dictionary['out'] user_agent = add_link_dictionary['user-agent'] cookies = add_link_dictionary['load-cookies'] referer = add_link_dictionary['referer'] #setting time and date for last_try_date now_date_list = nowDate() add_link_dictionary['last_try_date'] = now_date_list #making header option header_list = [] if cookies != None: semicolon_split_cookies = cookies.split('; ') for i in semicolon_split_cookies: equal_split_cookie = i.split('=') join_cookie = ':'.join(equal_split_cookie) if i != '': header_list.append(join_cookie) if header != None: semicolon_split_header = header.split('; ') for i in semicolon_split_header: equal_split_header = i.split('=') join_header = ':'.join(equal_split_header) if i != '': header_list.append(join_header) if len(header_list) == 0: header_list = None if start_hour != None: download_info_file_list[1] = "scheduled" #writing new informations on download_info_file download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list) if ip: ip_port = str(ip) + ":" + str(port) else: ip_port = "" if start_hour != None: start_time_status = startTime(start_hour, start_minute, gid) else: start_time_status = "downloading" if start_time_status == "scheduled": #reading new limit option before starting download! perhaps user changed this in progress bar window download_info_file_list = readList(download_info_file) add_link_dictionary = download_info_file_list[9] limit = add_link_dictionary['limit'] #eliminating start_hour and start_minute! add_link_dictionary['start_hour'] = None add_link_dictionary['start_minute'] = None download_info_file_list[9] = add_link_dictionary writeList(download_info_file, download_info_file_list) #finding download_path_temp from persepolis_setting persepolis_setting.sync() download_path_temp = persepolis_setting.value( 'settings/download_path_temp') if start_time_status != 'stopped': #sending download request to aria2 if link[0:5] != "https": aria_dict = { 'gid': gid, 'max-tries': str(persepolis_setting.value('settings/max-tries')), 'retry-wait': int(persepolis_setting.value('settings/retry-wait')), 'timeout': int(persepolis_setting.value('settings/timeout')), 'header': header_list, 'out': out, 'user-agent': user_agent, 'referer': referer, 'all-proxy': ip_port, 'max-download-limit': limit, 'all-proxy-user': str(proxy_user), 'all-proxy-passwd': str(proxy_passwd), 'http-user': str(download_user), 'http-passwd': str(download_passwd), 'split': '16', 'max-connection-per-server': str(connections), 'min-split-size': '1M', 'continue': 'true', 'dir': str(download_path_temp) } else: aria_dict = { 'gid': gid, 'max-tries': str(persepolis_setting.value('settings/max-tries')), 'retry-wait': int(persepolis_setting.value('settings/retry-wait')), 'timeout': int(persepolis_setting.value('settings/timeout')), 'header': header_list, 'out': out, 'user-agent': user_agent, 'referer': referer, 'all-proxy': ip_port, 'max-download-limit': limit, 'all-proxy-user': str(proxy_user), 'all-proxy-passwd': str(proxy_passwd), 'split': '16', 'max-connection-per-server': str(connections), 'min-split-size': '1M', 'continue': 'true', 'dir': str(download_path_temp) } try: if ("http" in link[0:5]): answer = server.aria2.addUri([link], aria_dict) else: answer = server.aria2.addUri([link], aria_dict) print(answer + " Starts") if end_hour != None: endTime(end_hour, end_minute, gid) except: print("None Starts") #if request was unsuccessful return None! return 'None' else: #if start_time_status is "stopped" it means download Canceled by user print("Download Canceled")
def propertiesCallback(self,add_link_dictionary , gid ): download_info_file = download_info_folder + "/" + gid download_info_file_list = readList(download_info_file ) download_info_file_list [9] = add_link_dictionary writeList(download_info_file , download_info_file_list)
def checkDownloadInfo(self,gid): try: #get download information from download_info_file according to gid and write them in download_table cells download_info_file = config_folder + "/download_info/" + gid download_info_file_list = readList(download_info_file) download_info_file_list_string = readList(download_info_file ,'string') #finding row of this gid! for i in range(self.download_table.rowCount()): row_gid = self.download_table.item(i , 8).text() if gid == row_gid : row = i break for i in range(10): #check flag of download! #It's showing that selection mode is active or not! if i == 0 : flag = int(self.download_table.item(row , i).flags()) #remove gid of completed download from active downloads list file elif i == 1 : status = str(download_info_file_list[i]) status_download_table = str(self.download_table.item(row , 1 ) . text()) if status == "complete": f = Open(download_list_file_active) download_list_file_active_lines = f.readlines() f.close() f = Open(download_list_file_active , "w") for line in download_list_file_active_lines : if line.strip() != gid : f.writelines(line.strip() + "\n") f.close() #update download_table cells item = QTableWidgetItem(download_info_file_list_string[i]) #48 means that item is checkable and enabled if i == 0 and flag == 48: item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) if self.download_table.item(row , i).checkState() == 2: item.setCheckState(QtCore.Qt.Checked) else: item.setCheckState(QtCore.Qt.Unchecked) self.download_table.setItem(row , i , item) self.download_table.viewport().update() #update progresswindow try : #finding progress_window for gid member_number = self.progress_window_list_dict[gid] progress_window = self.progress_window_list[member_number] #link add_link_dictionary = download_info_file_list[9] link = "<b>Link</b> : " + str(add_link_dictionary ['link']) progress_window.link_label.setText(link) progress_window.link_label.setToolTip(link) #Save as final_download_path = add_link_dictionary['final_download_path'] if final_download_path == None : final_download_path = str(add_link_dictionary['download_path']) save_as = "<b>Save as</b> : " + final_download_path + "/" + str(download_info_file_list[0]) progress_window.save_label.setText(save_as) progress_window.save_label.setToolTip(save_as) #status progress_window.status = download_info_file_list[1] status = "<b>Status</b> : " + progress_window.status progress_window.status_label.setText(status) if progress_window.status == "downloading": progress_window.resume_pushButton.setEnabled(False) progress_window.stop_pushButton.setEnabled(True) progress_window.pause_pushButton.setEnabled(True) elif progress_window.status == "paused": progress_window.resume_pushButton.setEnabled(True) progress_window.stop_pushButton.setEnabled(True) progress_window.pause_pushButton.setEnabled(False) elif progress_window.status == "waiting": progress_window.resume_pushButton.setEnabled(False) progress_window.stop_pushButton.setEnabled(True) progress_window.pause_pushButton.setEnabled(False) elif progress_window.status == "scheduled": progress_window.resume_pushButton.setEnabled(False) progress_window.stop_pushButton.setEnabled(True) progress_window.pause_pushButton.setEnabled(False) elif progress_window.status == "stopped" or progress_window.status == "error" or progress_window.status == "complete" : #close progress_window if download status is stopped or completed or error progress_window.close() self.progress_window_list[member_number] = [] del self.progress_window_list_dict[gid] if progress_window.status == "stopped": notifySend("Download Stopped" , str(download_info_file_list[0]) , 10000 , 'no', systemtray = self.system_tray_icon ) elif progress_window.status == "error": notifySend("Error - " + add_link_dictionary['error'] , str(download_info_file_list[0]) , 10000 , 'fail', systemtray = self.system_tray_icon ) add_link_dictionary['start_hour'] = None add_link_dictionary['start_minute'] = None add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None add_link_dictionary['after_download'] = 'None' for i in range(10): if i == 9 : download_info_file_list[i] = add_link_dictionary download_info_file_list[9] = add_link_dictionary writeList(download_info_file , download_info_file_list ) #this section is sending shutdown signal to the shutdown script(if user select shutdown for after download) if os.path.isfile('/tmp/persepolis/shutdown/' + gid ) == True and progress_window.status != 'stopped': answer = download.shutDown() #KILL aria2c if didn't respond if answer == 'error': os.system('killall aria2c') f = Open('/tmp/persepolis/shutdown/' + gid , 'w') notifySend('Persepolis is shutting down','your system in 20 seconds' , 15000 ,'warning', systemtray = self.system_tray_icon ) f.writelines('shutdown') f.close() elif os.path.isfile('/tmp/persepolis/shutdown/' + gid ) == True and progress_window.status == 'stopped': f = Open('/tmp/persepolis/shutdown/' + gid , 'w') f.writelines('canceled') f.close() #showing download compelete dialog #check user's Preferences f = Open(setting_file) setting_file_lines = f.readlines() f.close() setting_dict_str = str(setting_file_lines[0].strip()) setting_dict = ast.literal_eval(setting_dict_str) if progress_window.status == "complete" and setting_dict['after-dialog'] == 'yes' : afterdownloadwindow = AfterDownloadWindow(download_info_file_list,setting_file) self.afterdownload_list.append(afterdownloadwindow) self.afterdownload_list[len(self.afterdownload_list) - 1].show() elif progress_window.status == "complete" and setting_dict['after-dialog'] == 'no' : notifySend("Download Complete" ,str(download_info_file_list[0]) , 10000 , 'ok' , systemtray = self.system_tray_icon ) #downloaded downloaded = "<b>Downloaded</b> : " + str(download_info_file_list[3]) + "/" + str(download_info_file_list[2]) progress_window.downloaded_label.setText(downloaded) #Transfer rate rate = "<b>Transfer rate</b> : " + str(download_info_file_list[6]) progress_window.rate_label.setText(rate) #Estimate time left estimate_time_left = "<b>Estimate time left</b> : " + str(download_info_file_list[7]) progress_window.time_label.setText(estimate_time_left) #Connections connections = "<b>Connections</b> : " + str(download_info_file_list[5]) progress_window.connections_label.setText(connections) #progressbar value = download_info_file_list[4] file_name = str(download_info_file_list[0]) if file_name != "***": windows_title = '(' + str(value) + ')' + str(file_name) progress_window.setWindowTitle(windows_title) value = value[:-1] progress_window.download_progressBar.setValue(int(value)) except : pass except: pass
def __init__(self): super().__init__() self.system_tray_icon = QSystemTrayIcon() self.system_tray_icon.setIcon(QIcon.fromTheme('persepolis',QIcon(':/icon.svg') )) system_tray_menu = QMenu() system_tray_menu.addAction(self.addlinkAction) system_tray_menu.addAction(self.pauseAllAction) system_tray_menu.addAction(self.stopAllAction) system_tray_menu.addAction(self.minimizeAction) system_tray_menu.addAction(self.exitAction) self.system_tray_icon.setContextMenu(system_tray_menu) self.system_tray_icon.activated.connect(self.systemTrayPressed) self.system_tray_icon.show() self.system_tray_icon.setToolTip('Persepolis Download Manager') f = Open(setting_file) setting_file_lines = f.readlines() f.close() setting_dict_str = str(setting_file_lines[0].strip()) setting_dict = ast.literal_eval(setting_dict_str) if setting_dict['tray-icon'] != 'yes': self.minimizeAction.setEnabled(False) self.trayAction.setChecked(False) self.system_tray_icon.hide() self.statusbar.showMessage('Please Wait ...') self.checkSelectedRow() #touch download_list_file if not(os.path.isfile(download_list_file)): f = Open(download_list_file , 'w') f.close() #touch download_list_file_active if not(os.path.isfile(download_list_file_active)): f = Open(download_list_file_active , 'w') f.close() #lock files perventing to access a file simultaneously #removing lock files in starting persepolis os.system("rm " + config_folder +"/*.lock" + " 2>/dev/null" ) os.system("rm " + download_info_folder + "/*.lock" + " 2>/dev/null" ) #threads self.threadPool=[] #starting aria start_aria = StartAria2Thread() self.threadPool.append(start_aria) self.threadPool[0].start() self.threadPool[0].ARIA2RESPONDSIGNAL.connect(self.startAriaMessage) #initializing #add downloads to the download_table f_download_list_file = Open(download_list_file) download_list_file_lines = f_download_list_file.readlines() f_download_list_file.close() for line in download_list_file_lines: gid = line.strip() self.download_table.insertRow(0) download_info_file = download_info_folder + "/" + gid download_info_file_list = readList(download_info_file,'string') for i in range(10): item = QTableWidgetItem(download_info_file_list[i]) self.download_table.setItem(0 , i , item) row_numbers = self.download_table.rowCount() for row in range(row_numbers): status = self.download_table.item(row , 1).text() if (status != "complete" and status != "error"): gid = self.download_table.item(row,8).text() add_link_dictionary_str = self.download_table.item(row,9).text() add_link_dictionary = ast.literal_eval(add_link_dictionary_str.strip()) add_link_dictionary['start_hour'] = None add_link_dictionary['start_minute'] = None add_link_dictionary['end_hour'] = None add_link_dictionary['end_minute'] = None add_link_dictionary['after_download'] = 'None' download_info_file = download_info_folder + "/" + gid download_info_file_list = readList(download_info_file,'string') for i in range(10): if i == 1 : download_info_file_list[i] = 'stopped' item = QTableWidgetItem('stopped') self.download_table.setItem(row , i , item ) download_info_file_list[9] = add_link_dictionary writeList(download_info_file , download_info_file_list) self.addlinkwindows_list = [] self.propertieswindows_list = [] self.progress_window_list = [] self.afterdownload_list = [] self.progress_window_list_dict = {} check_download_info = CheckDownloadInfoThread() self.threadPool.append(check_download_info) self.threadPool[1].start() self.threadPool[1].DOWNLOAD_INFO_SIGNAL.connect(self.checkDownloadInfo) check_selected_row = CheckSelectedRowThread() self.threadPool.append(check_selected_row) self.threadPool[2].start() self.threadPool[2].CHECKSELECTEDROWSIGNAL.connect(self.checkSelectedRow) check_flashgot = CheckFlashgot() self.threadPool.append(check_flashgot) self.threadPool[3].start() self.threadPool[3].CHECKFLASHGOTSIGNAL.connect(self.checkFlashgot) self.threadPool[3].SHOWMAINWINDOWSIGNAL.connect(self.showMainWindow) self.download_table.itemDoubleClicked.connect(self.openFile)
def spider(add_link_dictionary, gid): #getting user's download request from add_link_dictionary link = add_link_dictionary['link'] ip = add_link_dictionary['ip'] port = add_link_dictionary['port'] proxy_user = add_link_dictionary['proxy_user'] proxy_passwd = add_link_dictionary['proxy_passwd'] download_user = add_link_dictionary['download_user'] download_passwd = add_link_dictionary['download_passwd'] header = add_link_dictionary['header'] out = add_link_dictionary['out'] user_agent = add_link_dictionary['user-agent'] raw_cookies = add_link_dictionary['load-cookies'] referer = add_link_dictionary['referer'] if out == '***': out = None requests_session = requests.Session() #defining a requests Session if ip: ip_port = 'http://' + str(ip) + ":" + str(port) if proxy_user: ip_port = 'http://' + proxy_user + ':' + proxy_passwd + '@' + ip_port requests_session.proxies = { 'http': ip_port } #setting proxy to the session if download_user: requests_session.auth( download_user, download_passwd) #setting download user pass to the session if raw_cookies != None: #setting cookies cookie = SimpleCookie() cookie.load(raw_cookies) cookies = {key: morsel.value for key, morsel in cookie.items()} requests_session.cookies = cookiejar_from_dict(cookies) if referer != None: requests_session.headers.update({'referer': referer }) #setting referer to the session if user_agent != None: requests_session.headers.update({'user-agent': user_agent }) #setting user_agent to the session #finding headers response = requests_session.head(link) header = response.headers filename = '***' filesize = '***' if 'Content-Disposition' in header.keys( ): #checking if filename is available content_disposition = header['Content-Disposition'] if content_disposition.find('filename') != -1: filename_splited = content_disposition.split('filename=') filename_splited = filename_splited[-1] filename = filename_splited[ 1:-1] #getting file name in desired format if filename == '***': filename = link.split('/')[-1] if out != None: filename = out if 'Content-Length' in header.keys(): #checking if file_size is available file_size = int(header['Content-Length']) if int(file_size / 1073741824) != 0: #converting file_size to KB or MB or GB file_size = file_size / 1073741824 size_str = str(round(file_size, 2)) + " GB" elif int(file_size / 1048576) != 0: size_str = str(int(file_size / 1048576)) + " MB" elif int(file_size / 1024) != 0: size_str = str(int(file_size / 1024)) + " KB" else: size_str = str(file_size) filesize = size_str download_info_file = os.path.join(download_info_folder, gid) download_info_file_list = readList(download_info_file) download_info = [ filename, None, filesize, None, None, None, None, None, None, None, None, None, None ] for i in range(13): if download_info[i] != None: download_info_file_list[i] = download_info[i] writeList(download_info_file, download_info_file_list)