Example #1
0
    def run(self):
        global remove_flag
        global shutdown_notification
        while True:

            while shutdown_notification == 0 and aria_startup_answer != 'ready':
                sleep (1)

            while shutdown_notification != 1:
            #if remove_flag is equal to 1, it means that user pressed remove or delete button . so checking download information must stop until removing done!
                if remove_flag == 1 :
                    remove_flag = 2
                    while remove_flag != 0 :
                        sleep(0.2)
                sleep(0.3)
                f = Open(download_list_file_active) 
                download_list_file_active_lines = f.readlines()
                f.close()
                if len(download_list_file_active_lines) != 0 :
                    for line in download_list_file_active_lines:
                        gid = line.strip()
                        try:
                            answer = download.downloadStatus(gid)
                        except:
                            answer = 'None'
                        if answer == 'ready' :
                            sleep(0.2)
                            download_info_file = download_info_folder + "/" + gid
                            if os.path.isfile(download_info_file) == True:
                                self.DOWNLOAD_INFO_SIGNAL.emit(gid)
            shutdown_notification = 2
            break
Example #2
0
    def okPushButtonPressed(self,button):
        self.setting_dict['max-tries'] = self.tries_spinBox.value()
        self.setting_dict['retry-wait'] = self.wait_spinBox.value()
        self.setting_dict['timeout'] = self.time_out_spinBox.value()
        self.setting_dict['connections'] = self.connections_spinBox.value()
        self.setting_dict['download_path'] = self.download_folder_lineEdit.text()
        self.setting_dict['download_path_temp'] = self.temp_download_lineEdit.text()
        self.setting_dict['sound-volume'] = self.volume_dial.value()
        self.setting_dict['style'] = self.style_comboBox.currentText()
        self.setting_dict['color-scheme'] = self.color_comboBox.currentText()
        self.setting_dict['icons'] = self.icon_comboBox.currentText()
        self.setting_dict['font-size'] = self.font_size_spinBox.value()
#this section  creates temporary download folder and download folder and download sub folders if they did not existed.
        download_path_temp  = self.setting_dict ['download_path_temp']
        download_path = self.setting_dict [ 'download_path']
        folder_list = [download_path_temp , download_path]
        for folder in [ 'Audios' , 'Videos', 'Others','Documents','Compressed' ]:
            folder_list.append(download_path + '/' + folder )

        for folder in folder_list :
            if os.path.isdir(folder) == False :
                os.mkdir(folder)


        if self.enable_notifications_checkBox.isChecked() == True :
            self.setting_dict['sound'] = 'yes'
        else:
            self.setting_dict['sound'] = 'no'

        f = Open(setting_file , 'w')
        f.writelines(str(self.setting_dict))
        f.close()

        self.close()
Example #3
0
def notifySend(message1, message2, time, sound, systemtray=None):
    if sound == 'ok':
        playNotification('notifications/ok.ogg')
    elif sound == 'fail':
        playNotification('notifications/fail.ogg')
    elif sound == 'warning':
        playNotification('notifications/you.ogg')
    elif sound == 'critical':
        playNotification('notifications/connection.ogg')

    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)

    enable_notification = str(setting_dict['notification'])

    time = str(time)
    message1 = str(message1)
    message2 = str(message2)

    #using Qt notification or Native system notification
    if enable_notification == 'QT notification':
        systemtray.showMessage(message1, message2, 1, 10000)
    else:
        os.system(
            "notify-send --icon='persepolis' --app-name='Persepolis Download Manager' --expire-time='"
            + time + "' '" + message1 + "' \ '" + message2 + "' ")
Example #4
0
 def afterCheckBoxToggled(self,checkBoxes): 
     if self.after_checkBox.isChecked() == True :
             self.after_frame.setEnabled(True)
     else :
         self.after_frame.setEnabled(False)
         f = Open('/tmp/persepolis/shutdown/' + self.gid , 'w')
         f.writelines('canceled')
         f.close()
Example #5
0
 def openDefaultDownloadFolder(self,menu):
     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) 
     download_path = setting_dict ['download_path']
     if os.path.isdir(download_path):
         os.system("xdg-open '" + download_path + "'" )
     else:
         notifySend(str(download_path) ,'Not Found' , 5000 , 'warning' , systemtray = self.system_tray_icon )
Example #6
0
 def gidGenerator(self):
     my_gid = hex(random.randint(1152921504606846976,18446744073709551615))
     my_gid = my_gid[2:18]
     my_gid = str(my_gid)
     f = Open(download_list_file_active)
     active_gid_list = f.readlines()
     f.close()
     while my_gid in active_gid_list :
         my_gid = self.gidGenerator()
     active_gids = download.activeDownloads()
     while my_gid in active_gids:
         my_gid = self.gidGenerator()
     
     return my_gid
Example #7
0
 def gidGenerator(self):
     my_gid = hex(random.randint(1152921504606846976,18446744073709551615))
     my_gid = my_gid[2:18]
     my_gid = str(my_gid)
     f = Open(download_list_file_active)
     active_gid_list = f.readlines()
     f.close()
     while my_gid in active_gid_list :
         my_gid = self.gidGenerator()
     active_gids = download.activeDownloads()
     while my_gid in active_gids:
         my_gid = self.gidGenerator()
     
     return my_gid
Example #8
0
    def pauseAllDownloads(self,menu):
#get active gid of downloads from aria
        active_gids = download.activeDownloads()
#check that if gid is in download_list_file_active
        f = Open(download_list_file_active)
        download_list_file_active_lines = f.readlines()
        f.close()
        for i in range(len(download_list_file_active_lines)):
            download_list_file_active_lines[i] = download_list_file_active_lines[i].strip()

        for gid in active_gids :
            if gid in download_list_file_active_lines :
                answer = download.downloadPause(gid)
                if answer == 'None':
                    notifySend("Aria2 did not respond!" , "Try agian!" , 10000 , 'critical' , systemtray = self.system_tray_icon )

                sleep(0.3)
Example #9
0
    def pauseAllDownloads(self,menu):
#get active gid of downloads from aria
        active_gids = download.activeDownloads()
#check that if gid is in download_list_file_active
        f = Open(download_list_file_active)
        download_list_file_active_lines = f.readlines()
        f.close()
        for i in range(len(download_list_file_active_lines)):
            download_list_file_active_lines[i] = download_list_file_active_lines[i].strip()

        for gid in active_gids :
            if gid in download_list_file_active_lines :
                answer = download.downloadPause(gid)
                if answer == 'None':
                    notifySend("Aria2 did not respond!" , "Try agian!" , 10000 , 'critical' )

                sleep(0.3)
Example #10
0
def playNotification(file):
    #getting user setting from setting file
    #setting_dict['sound'] >>> enable or disable sound
    #setting_dict['sound-volume'] >>>Specify volume of sound . between 0 to 100
    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)

    enable_notification = str(setting_dict['sound'])
    volume_percent = int(setting_dict['sound-volume'])
    #Paplay volume value must be between 0 (silent) and 65536 (100% volume)
    volume = int((65536 * volume_percent) / 100)

    if enable_notification == 'yes':
        os.system("paplay --volume='" + str(volume) + "' '" + file + "' &")
Example #11
0
def playNotification(file):
#getting user setting from setting file
#setting_dict['sound'] >>> enable or disable sound
#setting_dict['sound-volume'] >>>Specify volume of sound . between 0 to 100
    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) 

    enable_notification = str(setting_dict['sound'])
    volume_percent = int(setting_dict['sound-volume'])
#Paplay volume value must be between 0 (silent) and 65536 (100% volume)
    volume = int((65536 * volume_percent)/100)

    if enable_notification == 'yes':
        os.system("paplay --volume='"+ str(volume) + "' '" + file + "' &")
Example #12
0
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()
        f = Open(download_info_file)
        download_info_file_lines = f.readlines()
        f.close()
        if download_info_file_lines[1].strip() == 'stopped' :
            status = 'stopped'
            break
        else :
            status = 'scheduled'
    return status
Example #13
0
 def checkFlashgot(self):
     sleep(0.5)
     flashgot_file = Open("/tmp/persepolis-flashgot")
     flashgot_line = flashgot_file.readlines()
     flashgot_file.close()
     flashgot_file.remove()
     flashgot_add_link_dictionary_str = flashgot_line[0]
     flashgot_add_link_dictionary = ast.literal_eval(flashgot_add_link_dictionary_str) 
     self.flashgotAddLink(flashgot_add_link_dictionary)
Example #14
0
    def __init__(self,gid ):
        super().__init__()
        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_lines_len = 1
        while download_info_file_lines_len != 10 :
            f = Open(download_info_folder + "/" + self.gid) 
            download_info_file_lines = f.readlines()
            f.close()
            download_info_file_lines_len = len(download_info_file_lines)

        add_link_dictionary_str = str(download_info_file_lines[9].strip())
        add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
        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)
Example #15
0
 def run(self):
     global shutdown_notification
     while True:
         while shutdown_notification != 1:
             sleep(0.2)
             f = Open(download_list_file_active) 
             download_list_file_active_lines = f.readlines()
             f.close()
             if len(download_list_file_active_lines) != 0 :
                 for line in download_list_file_active_lines:
                     gid = line.strip()
                     try:
                         answer = download.downloadStatus(gid)
                     except:
                         answer = 'None'
                     if answer == 'ready' :
                         sleep(0.2)
                         download_info_file = download_info_folder + "/" + gid
                         if os.path.isfile(download_info_file) == True:
                             self.DOWNLOAD_INFO_SIGNAL.emit(gid)
         shutdown_notification = 2
         break
Example #16
0
 def afterCheckBoxToggled(self, checkBoxes):
     if self.after_checkBox.isChecked() == True:
         self.after_frame.setEnabled(True)
     else:
         self.after_frame.setEnabled(False)
         f = Open('/tmp/persepolis/shutdown/' + self.gid, 'w')
         f.writelines('canceled')
         f.close()
Example #17
0
    def okPushButtonPressed(self, button):
        self.setting_dict['max-tries'] = self.tries_spinBox.value()
        self.setting_dict['retry-wait'] = self.wait_spinBox.value()
        self.setting_dict['timeout'] = self.time_out_spinBox.value()
        self.setting_dict['connections'] = self.connections_spinBox.value()
        self.setting_dict[
            'download_path'] = self.download_folder_lineEdit.text()
        self.setting_dict[
            'download_path_temp'] = self.temp_download_lineEdit.text()
        self.setting_dict['sound-volume'] = self.volume_dial.value()
        self.setting_dict['style'] = self.style_comboBox.currentText()
        self.setting_dict['color-scheme'] = self.color_comboBox.currentText()
        self.setting_dict['icons'] = self.icon_comboBox.currentText()
        self.setting_dict[
            'notification'] = self.notification_comboBox.currentText()
        self.setting_dict['font-size'] = self.font_size_spinBox.value()
        #if user select qt notification  >> enable_system_tray icon
        if self.setting_dict['notification'] == 'QT notification':
            self.enable_system_tray_checkBox.setChecked(True)
#enable_system_tray_checkBox
        if self.enable_system_tray_checkBox.isChecked() == True:
            self.setting_dict['tray-icon'] = 'yes'
            self.parent.system_tray_icon.show()
            self.parent.minimizeAction.setEnabled(True)
            self.parent.trayAction.setChecked(True)
        else:
            self.setting_dict['tray-icon'] = 'no'
            self.parent.system_tray_icon.hide()
            self.parent.minimizeAction.setEnabled(False)
            self.parent.trayAction.setChecked(False)
#after_download_checkBox
        if self.after_download_checkBox.isChecked() == True:
            self.setting_dict['after-dialog'] = 'yes'
        else:
            self.setting_dict['after-dialog'] = 'no'
#this section  creates temporary download folder and download folder and download sub folders if they did not existed.
        download_path_temp = self.setting_dict['download_path_temp']
        download_path = self.setting_dict['download_path']
        folder_list = [download_path_temp, download_path]
        for folder in [
                'Audios', 'Videos', 'Others', 'Documents', 'Compressed'
        ]:
            folder_list.append(download_path + '/' + folder)

        for folder in folder_list:
            if os.path.isdir(folder) == False:
                os.mkdir(folder)

        if self.enable_notifications_checkBox.isChecked() == True:
            self.setting_dict['sound'] = 'yes'
        else:
            self.setting_dict['sound'] = 'no'

        f = Open(setting_file, 'w')
        f.writelines(str(self.setting_dict))
        f.close()

        self.close()
Example #18
0
 def afterCheckBoxToggled(self, checkBoxes):
     if self.after_checkBox.isChecked() == True:
         self.after_frame.setEnabled(True)
     else:
         self.after_frame.setEnabled(False)
         shutdown_file = os.path.join(persepolis_tmp, 'shutdown', self.gid)
         f = Open(shutdown_file, 'w')
         f.writelines('canceled')
         f.close()
Example #19
0
 def checkFlashgot(self):
     sleep(0.5)
     flashgot_file = Open("/tmp/persepolis-flashgot")
     flashgot_line = flashgot_file.readlines()
     flashgot_file.close()
     flashgot_file.remove()
     flashgot_add_link_dictionary_str = flashgot_line[0]
     flashgot_add_link_dictionary = ast.literal_eval(flashgot_add_link_dictionary_str) 
     self.flashgotAddLink(flashgot_add_link_dictionary)
Example #20
0
    def queueChanged(self, combo):
        if str(self.add_queue_comboBox.currentText()) == 'Create new queue':
            new_queue = self.parent.createQueue(combo)
            if new_queue != None:
                # clearing comboBox
                self.add_queue_comboBox.clear()
                # loading queue list again!
                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))

                self.add_queue_comboBox.addItem('Single Downloads')

                self.add_queue_comboBox.addItem(QIcon(icons + 'add_queue'),
                                                'Create new queue')

                # finding index of new_queue and setting comboBox for it
                index = self.add_queue_comboBox.findText(str(new_queue))
                self.add_queue_comboBox.setCurrentIndex(index)
            else:
                self.add_queue_comboBox.setCurrentIndex(0)
    def chromiumPressed(self, browser):

        if os_type == 'Linux':
            exec_path = '/usr/bin/persepolis'

            if browser == 'chromium':
                native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/.config/google-chrome/NativeMessagingHosts'

        elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
            exec_path = '/usr/local/bin/persepolis'

            if browser == 'chromium':
                native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/.config/google-chrome/NativeMessagingHosts'

        elif os_type == 'Darwin':
            cwd = sys.argv[0]
            current_directory = os.path.dirname(cwd)

            exec_path = os.path.join(
                current_directory, 'Persepolis Download Manager')

            if browser == 'chromium':
                native_message_folder = home_address + \
                    '/Library/Application Support/Chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/Library/Application Support/Google/Chrome/NativeMessagingHosts'

        elif os_type == 'Windows':

            cwd = sys.argv[0]
            current_directory = os.path.dirname(cwd)

            exec_path = os.path.join(
                current_directory, 'Persepolis Download Manager.exe')

            # the execution path in jason file for Windows must in form of
            # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2
            # "\" in address
            exec_path = exec_path.replace('\\', r'\\')

            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager')

        json_file_lines = ['{', '    "name": "com.persepolis.pdmchromewrapper",', '    "description": "Integrate Persepolis with Google Chrome",', '    "path": "' +
                           str(exec_path) + '",', '    "type": "stdio",', '    "allowed_origins": [', '        "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/"', '    ]', '}']

        native_message_file = os.path.join(
            native_message_folder, 'com.persepolis.pdmchromewrapper.json')

        osCommands.makeDirs(native_message_folder)

        f = Open(native_message_file, 'w')
        for i in json_file_lines:
            f.writelines(str(i) + '\n')
        f.close()

        if os_type != 'Windows':
            os.system('chmod +x "' + str(native_message_file) + '"')
        else:
            CREATE_NO_WINDOW = 0x08000000
#             subprocess.Popen(['REG','ADD','"HKCU\\Software\\Google\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper.json"', '/ve' , '/t' , 'REG_SZ' ,'/d' , '"' + str(exec_path) + '"' , '/f'] , shell = False ,creationflags = CREATE_NO_WINDOW )
            os.system(r'REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.persepolis.pdmchromewrapper" /ve /t REG_SZ /d "' +
                      native_message_file + '" /f')

        if browser == 'chromium':
            self.chromium_label.setText('Done!')
        elif browser == 'chrome':
            self.chrome_label.setText('Done!')
Example #22
0
    def __init__(self , callback,flashgot_add_link_dictionary = {}):
        super().__init__()
        self.callback = callback
        self.flashgot_add_link_dictionary = flashgot_add_link_dictionary
#entry initialization            

        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'])
        global download_path
        download_path = str(setting_dict['download_path'])


        global init_file
        init_file = str(home_address) + "/.config/persepolis_download_manager/addlink_init_file"
        os.system("touch " + init_file)
        f = Open(init_file)
        init_file_lines = f.readlines()
        f.close()

#initialization
        self.connections_spinBox.setValue(connections)
        self.download_folder_lineEdit.setText(download_path)
        self.download_folder_lineEdit.setEnabled(False)

        self.ok_pushButton.setEnabled(False)
        self.link_lineEdit.textChanged.connect(self.linkLineChanged)
#AddLink - checking clipboard for link!   
        if 'link' in self.flashgot_add_link_dictionary : 
            self.link_lineEdit.setText(str(self.flashgot_add_link_dictionary['link']))
            del self.flashgot_add_link_dictionary['link']
        else:    
            clipboard = QApplication.clipboard()
            text = clipboard.text()
            try:
                if ("tp:/" in text[2:6]) or ("tps:/" in text[2:7]) :
                    self.link_lineEdit.setText(str(text))
            except:
                pass

#ip_lineEdit initialization 
        try:
            self.ip_lineEdit.setText(init_file_lines[0].strip())
        except :
            pass

#proxy user lineEdit initialization 
        try:
            self.proxy_user_lineEdit.setText(init_file_lines[2].strip())
        except :
            pass

#port_spinBox initialization 
        try:
            self.port_spinBox.setValue(int(init_file_lines[1].strip()))
        except :
            pass


#download UserName initialization
        try:
            self.download_user_lineEdit.setText(init_file_lines[3].strip())
        except :
            pass
#connect folder_pushButton
        self.folder_pushButton.clicked.connect(self.changeFolder)

#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)

       
        self.show()
        'tray-icon': 'yes',
        'max-tries': 5,
        'retry-wait': 0,
        'timeout': 60,
        'connections': 16,
        'download_path_temp': download_path_temp,
        'download_path': download_path,
        'sound': 'yes',
        'sound-volume': 90,
        'style': 'Fusion',
        'color-scheme': 'Persepolis Dark Red',
        'icons': 'Archdroid-Red',
        'font': 'Ubuntu',
        'font-size': 9
    }
    f = Open(setting_file, 'w')
    f.writelines(str(default_setting))
    f.close()

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)

#this section  creates temporary download folder and download folder and download sub folders if they did not existed.
download_path_temp = setting_dict['download_path_temp']
download_path = setting_dict['download_path']
folder_list = [download_path_temp, download_path]
for folder in ['Audios', 'Videos', 'Others', 'Documents', 'Compressed']:
    folder_list.append(download_path + '/' + folder)
Example #24
0
    def removeButtonPressed(self,button):
        self.removeAction.setEnabled(False)
        selected_row_return = self.selectedRow()
        if selected_row_return != None:
            gid = self.download_table.item(selected_row_return , 8 ).text()
            try:
                file_name = self.download_table.item(selected_row_return , 0).text()
            except:
                file_name = None 
            sleep(0.5)
            self.download_table.removeRow(selected_row_return)

#remove gid of download from download list file
            f = Open(download_list_file)
            download_list_file_lines = f.readlines()
            f.close()
            f = Open(download_list_file , "w")
            for i in download_list_file_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove gid of download from active download list file
            f = Open(download_list_file_active)
            download_list_file_active_lines = f.readlines()
            f.close()
            f = Open(download_list_file_active , "w")
            for i in download_list_file_active_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove download_info_file
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file)
            f.close()
            f.remove()
#remove file of download form download temp folder
            if file_name != None :
                file_name_path = temp_download_folder + "/" +  str(file_name)
                os.system('rm "' + str(file_name_path) +'"')
                file_name_aria = file_name_path + str('.aria2')
                os.system('rm "' + str(file_name_aria) +'"')
        else:
            self.statusbar.showMessage("Please select an item first!")
        self.selectedRow()
Example #25
0
    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
            f = Open(download_info_file)
            download_info_file_lines = f.readlines()
            f.close()
#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):
#remove gid of completed download from active downloads list file
                if i == 1 :
                    status = download_info_file_lines[i].strip()
                    status = str(status)
                    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_lines[i].strip())
                self.download_table.setItem(row , i , item)
                self.download_table.viewport().update()
#update progresswindow
            try :
            
                member_number = self.progress_window_list_dict[gid]
                progress_window = self.progress_window_list[member_number]
                #link
                add_link_dictionary_str = str(download_info_file_lines[9].strip())
                add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
                link = "<b>Link</b> : " +  str(add_link_dictionary ['link'])
                progress_window.link_label.setText(link)
                progress_window.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_lines[0].strip())
                progress_window.save_label.setText(save_as)
                file_name = str(download_info_file_lines[0].strip())
                if file_name != "***":
                    progress_window.setWindowTitle(file_name ) 

                #status
                progress_window.status = download_info_file_lines[1].strip()
                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(False)
                    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" :
                    progress_window.close()
                    self.progress_window_list[member_number] = []
                    del self.progress_window_list_dict[gid]
                    if progress_window.status == "complete":
                        notifySend("Download Complete" ,str(download_info_file_lines[0])  , 10000 , 'ok' )
                    elif progress_window.status == "stopped":
                        notifySend("Download Stopped" , str(download_info_file_lines[0]) , 10000 , 'no')

                    elif progress_window.status == "error":
                        notifySend("Download Error" , str(download_info_file_lines[0]) , 10000 , 'fail')
               
                        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'

                        f = Open(download_info_file , "w")
                        for i in range(10):
                            if i == 9 :
                                f.writelines(str(add_link_dictionary) + "\n")
                            else:
                                f.writelines(download_info_file_lines[i].strip() + "\n")

                        f.close()
                    
                    if os.path.isfile('/tmp/persepolis/shutdown/' + gid ) == True and progress_window.status != 'stopped':
                        answer = download.shutDown()
                        if answer == 'error':
                            os.system('killall aria2c')
                        f = Open('/tmp/persepolis/shutdown/' + gid , 'w')
                        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()



             
                #downloaded
                downloaded = "<b>Downloaded</b> : " + str(download_info_file_lines[3].strip()) + "/" + str(download_info_file_lines[2].strip())
                progress_window.downloaded_label.setText(downloaded)

                #Transfer rate
                rate = "<b>Transfer rate</b> : " + str(download_info_file_lines[6].strip())
                progress_window.rate_label.setText(rate)

                #Estimate time left
                estimate_time_left = "<b>Estimate time left</b> : " + str(download_info_file_lines[7].strip()) 
                progress_window.time_label.setText(estimate_time_left)

                #Connections
                connections = "<b>Connections</b> : " + str(download_info_file_lines[5].strip())
                progress_window.connections_label.setText(connections)


                #progressbar
                value = download_info_file_lines[4].strip()
                value = value[:-1]
                progress_window.download_progressBar.setValue(int(value))
            except :
                pass
        except:
            pass
Example #26
0
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 :
                f = Open(download_info_file)
                download_info_file_lines = f.readlines()
                f.close()
                status_file = 'yes'
                status = download_info_file_lines[1].strip() 
            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")

        f = Open(download_info_file)
        download_info_file_lines = f.readlines()
        f.close()
        add_link_dictionary_str = str(download_info_file_lines[9].strip())
        add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
        add_link_dictionary['end_hour'] = None
        add_link_dictionary['end_minute'] = None

        f = Open(download_info_file , "w")
        for i in range(10):
            if i == 1 :
                f.writelines("stopped" + "\n")
            elif i == 9 :
                f.writelines(str(add_link_dictionary) + "\n")
            else:
                f.writelines(download_info_file_lines[i].strip() + "\n")


        f.close()
Example #27
0
def downloadStop(gid):
    download_info_file = download_info_folder + "/" + gid
    f = Open(download_info_file)
    download_info_file_lines = f.readlines()
    f.close()

    status = download_info_file_lines[1].strip() 
    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':
        add_link_dictionary_str = str(download_info_file_lines[9].strip())
        add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
        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'

        f = Open(download_info_file , "w")
        for i in range(10):
            if i == 1 :
                f.writelines("stopped" + "\n")
            elif i == 9 :
                f.writelines(str(add_link_dictionary) + "\n")
            else:
                f.writelines(download_info_file_lines[i].strip() + "\n")

        f.close()
    return answer
Example #28
0
    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
Example #29
0
    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)
Example #30
0
    def deleteSelected(self,menu):
        global remove_flag
        remove_flag = 1
        while remove_flag != 2 :
            sleep(0.1)

        gid_list = []
        for row in range(self.download_table.rowCount()):
            status = self.download_table.item(row , 1).text() 
            item = self.download_table.item(row , 0)
            if (item.checkState() == 2) and (status == 'complete' or status == 'error' or status == 'stopped' ):
                gid = self.download_table.item(row , 8 ).text()
                gid_list.append(gid)


        for gid in gid_list:        
            for i in range(self.download_table.rowCount()):
                row_gid = self.download_table.item(i , 8).text()
                if gid == row_gid :
                    row = i 
                    break
            file_name = self.download_table.item(row , 0).text()
            add_link_dictionary_str = self.download_table.item(row , 9).text() 
            add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 


            sleep(0.5)
            self.download_table.removeRow(row)
#remove gid of download from download list file
            f = Open(download_list_file)
            download_list_file_lines = f.readlines()
            f.close()
            f = Open(download_list_file , "w")
            for i in download_list_file_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove gid of download from active download list file
            f = Open(download_list_file_active)
            download_list_file_active_lines = f.readlines()
            f.close()
            f = Open(download_list_file_active , "w")
            for i in download_list_file_active_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()


#remove download_info_file
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file)
            f.close()
            f.remove()

#remove file of download form download temp folder
            if file_name != '***' and status != 'complete' :
                file_name_path = temp_download_folder + "/" +  str(file_name)
                os.system('rm "' + str(file_name_path) +'"')
                file_name_aria = file_name_path + str('.aria2')
                os.system('rm "' + str(file_name_aria) +'"')

#remove download file
            if status == 'complete':
                if 'file_path' in add_link_dictionary:
                    file_path = add_link_dictionary['file_path']
                    if os.path.isfile(file_path):
                        os.system("rm '" + file_path  + "'" )
                    else:
                        notifySend(str(file_path) ,'Not Found' , 5000 , 'warning' , systemtray = self.system_tray_icon )

        remove_flag = 0
Example #31
0
    def removeSelected(self,menu):
        global remove_flag
        remove_flag = 1
        while remove_flag != 2 :
            sleep(0.1)

        gid_list = []
        for row in range(self.download_table.rowCount()):
            status = self.download_table.item(row , 1).text() 
            item = self.download_table.item(row , 0)
            if (item.checkState() == 2) and (status == 'complete' or status == 'error' or status == 'stopped' ):
                gid = self.download_table.item(row , 8 ).text()
                gid_list.append(gid)


        for gid in gid_list:        
            for i in range(self.download_table.rowCount()):
                row_gid = self.download_table.item(i , 8).text()
                if gid == row_gid :
                    row = i 
                    break

           
            file_name = self.download_table.item(row , 0).text()
            sleep(0.5)
            self.download_table.removeRow(row)

#remove gid of download from download list file
            f = Open(download_list_file)
            download_list_file_lines = f.readlines()
            f.close()
            f = Open(download_list_file , "w")
            for i in download_list_file_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove gid of download from active download list file
            f = Open(download_list_file_active)
            download_list_file_active_lines = f.readlines()
            f.close()
            f = Open(download_list_file_active , "w")
            for i in download_list_file_active_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove download_info_file
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file)
            f.close()
            f.remove()
#remove file of download form download temp folder
            if file_name != '***' and status != 'complete' :
                file_name_path = temp_download_folder + "/" +  str(file_name)
                os.system('rm "' + str(file_name_path) +'"')
                file_name_aria = file_name_path + str('.aria2')
                os.system('rm "' + str(file_name_aria) +'"')

        remove_flag = 0
Example #32
0
def shutDown(gid, password=None):
    shutdown_notification_file = os.path.join(persepolis_tmp, 'shutdown', gid)
    f = Open(shutdown_notification_file, 'w')
    f.writelines('wait')
    f.close()

    shutdown_notification = "wait"

    while shutdown_notification == "wait":
        sleep(1)

        f = Open(shutdown_notification_file, 'r')
        shutdown_notification_file_lines = f.readlines()
        f.close()

        shutdown_notification = str(
            shutdown_notification_file_lines[0].strip())

    osCommands.remove(shutdown_notification_file)

    if shutdown_notification == "shutdown":

        print("shutdown in 20 seconds")
        logger.sendToLog("Shutting down in 20 seconds", "INFO")
        sleep(20)
        if os_type == 'Linux':
            os.system('echo "' + password + '" |sudo -S poweroff')

        elif os_type == 'Darwin':
            os.system('echo "' + password + '" |sudo -S shutdown -h now ')

        elif os_type == 'Windows':
            CREATE_NO_WINDOW = 0x08000000
            subprocess.Popen(['shutdown', '-S'],
                             shell=False,
                             creationflags=CREATE_NO_WINDOW)

        elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
            os.system('echo "' + password + '" |sudo -S shutdown -p now ')
Example #33
0
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
    f = Open(download_info_file)
    download_info_file_lines = f.readlines()
    f.close()

    add_link_dictionary_str = str(download_info_file_lines[9].strip())
    add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 

    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
        downloadCompleteAction(path , download_path ,file_name)
#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 == "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 , str(add_link_dictionary) ]

   
    f = Open(download_info_file , "w")
    for i in range(10):
        if download_info[i] != None:
            f.writelines(download_info[i] + "\n")
        else:
            f.writelines(download_info_file_lines[i].strip() + "\n")

    f.close()

    return 'ready'
Example #34
0
    def __init__(self):
        super().__init__()
        self.statusbar.showMessage('Please Wait ...')

#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
            f = Open(download_info_file)
            download_info_file_lines = f.readlines()
            f.close()
            for i in range(10):
                item = QTableWidgetItem(download_info_file_lines[i].strip())
                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
                f = Open(download_info_file)
                download_info_file_lines = f.readlines()
                f.close()

                f = Open(download_info_file , "w")
                for i in range(10):
                    if i == 1 :
                        f.writelines("stopped" + "\n")
                        item = QTableWidgetItem('stopped')
                        self.download_table.setItem(row , i , item )
                    elif i == 9 :
                        f.writelines(str(add_link_dictionary) + "\n")
                        item = QTableWidgetItem(str(add_link_dictionary))
                        self.download_table.setItem(row,i , item)
                    else:
                        f.writelines(download_info_file_lines[i].strip() + "\n")

                f.close()
        self.addlinkwindows_list = []
        self.propertieswindows_list = []
        self.progress_window_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.system_tray_icon = QSystemTrayIcon() 
        self.system_tray_icon.setIcon(QIcon('icon'))
        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()
Example #35
0
def downloadAria(gid):
#add_link_dictionary is a dictionary that contains user download request information
    download_info_file = download_info_folder + "/" + gid
    f = Open(download_info_file)
    download_info_file_lines = f.readlines()
    f.close()
    add_link_dictionary_str = str(download_info_file_lines[9].strip())
    add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 

    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']
    
    if start_hour != None :
        download_info_file_lines[1] = "scheduled"

    f = Open(download_info_file , "w")
    for i in range(10):
        f.writelines(download_info_file_lines[i].strip() + "\n")

    f.close()

    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":
#read new limit option before starting download! perhaps user changed this with progress bar window
        f = Open(download_info_file)
        download_info_file_lines = f.readlines()
        f.close()
        add_link_dictionary_str = str(download_info_file_lines[9].strip())
        add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
        
        limit = add_link_dictionary['limit']

#eliminate start_hour and start_minute!         
        add_link_dictionary['start_hour'] = None
        add_link_dictionary['start_minute'] = None

        f = Open(download_info_file , "w")
        for i in range(10):
            if i == 9 :
                f.writelines(str(add_link_dictionary) + "\n")
            else:
                f.writelines(download_info_file_lines[i].strip() + "\n")


        f.close()


#find download_path_temp from setting_file
    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) 

    download_path_temp = setting_dict ['download_path_temp' ] 



    if start_time_status != 'stopped':
#send download request to aria2
        aria_dict = {'gid':gid ,'max-tries' : str(setting_dict['max-tries']) , 'retry-wait': int(setting_dict['retry-wait']) , 'timeout' : int(setting_dict['timeout']) , 'header': header ,'out': out , 'user-agent': user_agent , 'load-cookies': cookies , '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) } 
        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")
Example #36
0
    def __init__(self, parent):
        super().__init__(parent)
        self.parent = parent
        f = Open(setting_file)
        setting_file_lines = f.readlines()
        f.close()
        setting_dict_str = str(setting_file_lines[0].strip())
        self.setting_dict = ast.literal_eval(setting_dict_str)
        #initialization
        self.tries_spinBox.setValue(int(self.setting_dict['max-tries']))
        self.wait_spinBox.setValue(int(self.setting_dict['retry-wait']))
        self.time_out_spinBox.setValue(int(self.setting_dict['timeout']))
        self.connections_spinBox.setValue(int(
            self.setting_dict['connections']))

        self.download_folder_lineEdit.setText(
            str(self.setting_dict['download_path']))
        self.temp_download_lineEdit.setText(
            str(self.setting_dict['download_path_temp']))

        self.volume_label.setText('Volume : ' +
                                  str(self.setting_dict['sound-volume']))
        self.volume_dial.setValue(int(self.setting_dict['sound-volume']))
        #set style
        available_styles = QStyleFactory.keys()
        for style in available_styles:
            self.style_comboBox.addItem(style)

        self.style_comboBox.addItem('System')

        current_style_index = self.style_comboBox.findText(
            str(self.setting_dict['style']))
        if current_style_index != -1:
            self.style_comboBox.setCurrentIndex(current_style_index)
#set color_scheme
        color_scheme = [
            'System', 'Persepolis Dark Red', 'Persepolis Dark Blue',
            'Persepolis ArcDark Red', 'Persepolis ArcDark Blue'
        ]
        self.color_comboBox.addItems(color_scheme)

        current_color_index = self.color_comboBox.findText(
            str(self.setting_dict['color-scheme']))
        if current_color_index != -1:
            self.color_comboBox.setCurrentIndex(current_color_index)
#set icons
        icons = ['Archdroid-Red', 'Archdroid-Blue']
        self.icon_comboBox.addItems(icons)

        current_icons_index = self.icon_comboBox.findText(
            str(self.setting_dict['icons']))
        if current_icons_index != -1:
            self.icon_comboBox.setCurrentIndex(current_icons_index)
#set notification
        notifications = ['Native notification', 'QT notification']
        self.notification_comboBox.addItems(notifications)
        current_notification_index = self.notification_comboBox.findText(
            str(self.setting_dict['notification']))
        if current_notification_index != -1:
            self.notification_comboBox.setCurrentIndex(
                current_notification_index)
#set font
        font_setting = QFont()
        font_setting.setFamily(str(self.setting_dict['font']))
        self.fontComboBox.setCurrentFont(font_setting)

        self.font_size_spinBox.setValue(int(self.setting_dict['font-size']))

        #sound frame
        self.sound_frame.setEnabled(False)
        self.enable_notifications_checkBox.toggled.connect(self.soundFrame)
        if str(self.setting_dict['sound']) == 'yes':
            self.enable_notifications_checkBox.setChecked(True)
        else:
            self.enable_notifications_checkBox.setChecked(False)
#connect folder buttons
        self.download_folder_lineEdit.setEnabled(False)
        self.download_folder_pushButton.clicked.connect(
            self.downloadFolderPushButtonClicked)
        self.temp_download_lineEdit.setEnabled(False)
        self.temp_download_pushButton.clicked.connect(
            self.tempDownloadPushButtonClicked)
        #font change

        self.fontComboBox.currentFontChanged.connect(self.fontChanged)

        #dial
        self.volume_dial.setNotchesVisible(True)
        self.volume_dial.valueChanged.connect(self.dialChanged)

        #tray icon

        if str(self.setting_dict['tray-icon']) == 'yes':
            self.enable_system_tray_checkBox.setChecked(True)
        else:
            self.enable_notifications_checkBox.setChecked(False)

#after download dialog
        if str(self.setting_dict['after-dialog']) == 'yes':
            self.after_download_checkBox.setChecked(True)
        else:
            self.after_download_checkBox.setChecked(False)

#ok cancel default button
        self.cancel_pushButton.clicked.connect(self.cancelButtonPressed)
        self.defaults_pushButton.clicked.connect(
            self.defaultsPushButtonPressed)
        self.ok_pushButton.clicked.connect(self.okPushButtonPressed)
Example #37
0
    def __init__(self):
        super().__init__()

        f = Open(setting_file)
        setting_file_lines = f.readlines()
        f.close()
        setting_dict_str = str(setting_file_lines[0].strip())
        self.setting_dict = ast.literal_eval(setting_dict_str) 
#initialization
        self.tries_spinBox.setValue(int(self.setting_dict['max-tries']))
        self.wait_spinBox.setValue(int(self.setting_dict['retry-wait']))
        self.time_out_spinBox.setValue(int(self.setting_dict['timeout']))
        self.connections_spinBox.setValue(int(self.setting_dict['connections']))

        self.download_folder_lineEdit.setText(str(self.setting_dict['download_path']))
        self.temp_download_lineEdit.setText(str(self.setting_dict['download_path_temp']))
        
        self.volume_label.setText('Volume : ' + str(self.setting_dict['sound-volume']) )
        self.volume_dial.setValue(int(self.setting_dict['sound-volume']))
#set style 
        available_styles = QtWidgets.QStyleFactory.keys()
        for style in available_styles :
            self.style_comboBox.addItem(style)

        self.style_comboBox.addItem('System')
        
        current_style_index = self.style_comboBox.findText(str(self.setting_dict['style']))
        if current_style_index != -1 :
            self.style_comboBox.setCurrentIndex(current_style_index)
#set color_scheme
        color_scheme = ['System' , 'Persepolis Dark Red' , 'Persepolis Dark Blue']
        self.color_comboBox.addItems(color_scheme)
            
        current_color_index = self.color_comboBox.findText(str(self.setting_dict['color-scheme']))
        if current_color_index != -1 :
            self.color_comboBox.setCurrentIndex(current_color_index)
#set icons
        icons = ['Archdroid-Red' , 'Archdroid-Blue']
        self.icon_comboBox.addItems(icons)

        current_icons_index = self.icon_comboBox.findText(str(self.setting_dict['icons']))
        if current_icons_index != -1 :
            self.icon_comboBox.setCurrentIndex(current_icons_index)

#set font 
        font_setting = QFont() 
        font_setting.setFamily(str(self.setting_dict['font']))
        self.fontComboBox.setCurrentFont(font_setting)
    
        self.font_size_spinBox.setValue(int(self.setting_dict['font-size']))

#sound frame 
        self.sound_frame.setEnabled(False)
        self.enable_notifications_checkBox.toggled.connect(self.soundFrame)
        if str(self.setting_dict['sound']) == 'yes':
            self.enable_notifications_checkBox.setChecked(True) 
        else:
            self.enable_notifications_checkBox.setChecked(False)
#connect folder buttons
        self.download_folder_lineEdit.setEnabled(False)
        self.download_folder_pushButton.clicked.connect(self.downloadFolderPushButtonClicked)
        self.temp_download_lineEdit.setEnabled(False)
        self.temp_download_pushButton.clicked.connect(self.tempDownloadPushButtonClicked)
#font change 
        
        self.fontComboBox.currentFontChanged.connect(self.fontChanged)

#dial
        self.volume_dial.setNotchesVisible(True)
        self.volume_dial.valueChanged.connect(self.dialChanged)

#ok cancel default button
        self.cancel_pushButton.clicked.connect(self.cancelButtonPressed)
        self.defaults_pushButton.clicked.connect(self.defaultsPushButtonPressed)
        self.ok_pushButton.clicked.connect(self.okPushButtonPressed)
Example #38
0
#!/usr/bin/env python3

# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget, QSizePolicy
from PyQt5.QtGui import QIcon
import ast, os
from newopen import Open

home_address = os.path.expanduser("~")
config_folder = str(home_address) + "/.config/persepolis_download_manager"

#setting
setting_file = config_folder + '/setting'
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)

icons = ':/' + str(setting_dict['icons']) + '/'


class ProgressWindow_Ui(QWidget):
    def __init__(self):
        super().__init__()

        #window
        self.resize(595, 284)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
Example #39
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon
import ast , os
from newopen import Open

home_address = os.path.expanduser("~")
config_folder = str(home_address) + "/.config/persepolis_download_manager"

#setting
setting_file = config_folder + '/setting'
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) 

icons = str(setting_dict['icons']) + '/'



class Setting_Ui(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.resize(578, 465)
        icon = QtGui.QIcon()
        self.setWindowIcon(QIcon('icon'))
        self.setWindowTitle('Preferences')
Example #40
0
    def __init__(self,
                 parent,
                 callback,
                 persepolis_setting,
                 flashgot_add_link_dictionary={}):
        super().__init__(persepolis_setting)
        self.callback = callback
        self.flashgot_add_link_dictionary = flashgot_add_link_dictionary
        self.persepolis_setting = persepolis_setting
        self.parent = parent

        # entry initialization ->
        global connections
        connections = int(
            self.persepolis_setting.value('settings/connections'))
        global download_path
        download_path = str(
            self.persepolis_setting.value('settings/download_path'))

        # initialization ->
        self.connections_spinBox.setValue(connections)
        self.download_folder_lineEdit.setText(download_path)
        self.download_folder_lineEdit.setEnabled(False)

        self.ok_pushButton.setEnabled(False)
        self.download_later_pushButton.setEnabled(False)
        self.link_lineEdit.textChanged.connect(self.linkLineChanged)

        self.options_pushButton.clicked.connect(self.optionsButtonClicked)

        # AddLink - checking clipboard for link! ->
        if ('link' in self.flashgot_add_link_dictionary):
            self.link_lineEdit.setText(
                str(self.flashgot_add_link_dictionary['link']))

            # spider is finding file size
            new_spider = AddLinkSpiderThread(self.flashgot_add_link_dictionary)
            self.parent.threadPool.append(new_spider)
            self.parent.threadPool[len(self.parent.threadPool) - 1].start()
            self.parent.threadPool[len(self.parent.threadPool) -
                                   1].ADDLINKSPIDERSIGNAL.connect(
                                       partial(
                                           self.parent.addLinkSpiderCallBack,
                                           child=self))

        else:
            clipboard = QApplication.clipboard()
            text = clipboard.text()
            if (("tp:/" in text[2:6]) or ("tps:/" in text[2:7])):
                self.link_lineEdit.setText(str(text))

        # ip_lineEdit initialization ->
        settings_ip = self.persepolis_setting.value(
            'add_link_initialization/ip', None)
        if (settings_ip):
            self.ip_lineEdit.setText(str(settings_ip))

        # proxy user lineEdit initialization ->
        settings_proxy_user = self.persepolis_setting.value(
            'add_link_initialization/proxy_user', None)
        if (settings_proxy_user):
            self.proxy_user_lineEdit.setText(str(settings_proxy_user))

        # port_spinBox initialization ->
        settings_port = self.persepolis_setting.value(
            'add_link_initialization/port', 0)

        self.port_spinBox.setValue(int(int(settings_port)))

        # download UserName initialization ->
        settings_download_user = self.persepolis_setting.value(
            'add_link_initialization/download_user', None)
        if (settings_download_user):
            self.download_user_lineEdit.setText(str(settings_download_user))

        # finding queues 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))

        self.add_queue_comboBox.setCurrentIndex(0)

        # add_queue_comboBox event
        self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged)

        # connect folder_pushButton
        self.folder_pushButton.clicked.connect(self.changeFolder)

        # connect OK and canel download_later button ->
        self.cancel_pushButton.clicked.connect(self.close)
        self.ok_pushButton.clicked.connect(
            functools.partial(self.okButtonPressed, download_later='no'))
        self.download_later_pushButton.clicked.connect(
            functools.partial(self.okButtonPressed, download_later='yes'))

        # 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)

        self.change_name_lineEdit.setEnabled(False)
        self.change_name_checkBox.toggled.connect(self.changeName)

        # set focus to ok button
        self.ok_pushButton.setFocus()

        # check name of flashgot link ->
        if ('out' in self.flashgot_add_link_dictionary):
            self.change_name_lineEdit.setText(
                str(self.flashgot_add_link_dictionary['out']))
            self.change_name_checkBox.setChecked(True)

# setting window size and position
        size = self.persepolis_setting.value('AddLinkWindow/size',
                                             QSize(520, 265))
        position = self.persepolis_setting.value('AddLinkWindow/position',
                                                 QPoint(300, 300))
        self.resize(size)
        self.move(position)

        self.minimum_height = self.height()

        # more options widgets list
        self.more_options_widgets = [
            self.proxy_checkBox, self.proxy_frame, self.download_checkBox,
            self.download_frame, self.folder_frame, self.start_checkBox,
            self.start_frame, self.end_checkBox, self.end_frame,
            self.limit_checkBox, self.limit_frame, self.connections_frame
        ]
        #hiding more_options_widgets
        for widgets in self.more_options_widgets:
            widgets.hide()
Example #41
0
    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:
            f = Open(download_info_folder + "/" + self.gid) 
            download_info_file_lines = f.readlines()
            f.close()
            add_link_dictionary_str = str(download_info_file_lines[9].strip())
            add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
            add_link_dictionary['limit'] = limit

            f = Open(download_info_folder + "/" + self.gid , "w")
            for i in range(10):
                if i == 9 :
                    f.writelines(str(add_link_dictionary) + "\n")
                else:
                    f.writelines(download_info_file_lines[i].strip() + "\n")

            f.close()
Example #42
0
    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)
Example #43
0
    def limitCheckBoxToggled(self,checkBoxes): 
        if self.limit_checkBox.isChecked() == True :
            self.limit_frame.setEnabled(True)
            self.after_pushButton.setEnabled(True)
        else :
            self.limit_frame.setEnabled(False)
            if self.status != 'scheduled':
                download.limitSpeed(self.gid , "0" )
            else:
                f = Open(download_info_folder + "/" + self.gid) 
                download_info_file_lines = f.readlines()
                f.close()
                add_link_dictionary_str = str(download_info_file_lines[9].strip())
                add_link_dictionary = ast.literal_eval(add_link_dictionary_str) 
                add_link_dictionary['limit'] = '0'

                f = Open(download_info_folder + "/" + self.gid , "w")
                for i in range(10):
                    if i == 9 :
                        f.writelines(str(add_link_dictionary) + "\n")
                    else:
                        f.writelines(download_info_file_lines[i].strip() + "\n")

                f.close()
Example #44
0
    def __init__(self,
                 callback,
                 persepolis_setting,
                 flashgot_add_link_dictionary={}):
        super().__init__(persepolis_setting)
        self.callback = callback
        self.flashgot_add_link_dictionary = flashgot_add_link_dictionary
        self.persepolis_setting = persepolis_setting
        #entry initialization

        global connections
        connections = int(
            self.persepolis_setting.value('settings/connections'))
        global download_path
        download_path = str(
            self.persepolis_setting.value('settings/download_path'))

        #initialization
        self.connections_spinBox.setValue(connections)
        self.download_folder_lineEdit.setText(download_path)
        self.download_folder_lineEdit.setEnabled(False)

        self.ok_pushButton.setEnabled(False)
        self.download_later_pushButton.setEnabled(False)
        self.link_lineEdit.textChanged.connect(self.linkLineChanged)
        #AddLink - checking clipboard for link!
        if 'link' in self.flashgot_add_link_dictionary:
            self.link_lineEdit.setText(
                str(self.flashgot_add_link_dictionary['link']))
            del self.flashgot_add_link_dictionary['link']
        else:
            clipboard = QApplication.clipboard()
            text = clipboard.text()
            if ("tp:/" in text[2:6]) or ("tps:/" in text[2:7]):
                self.link_lineEdit.setText(str(text))

#ip_lineEdit initialization
        settings_ip = self.persepolis_setting.value(
            'add_link_initialization/ip', None)
        if settings_ip:
            self.ip_lineEdit.setText(str(settings_ip))

#proxy user lineEdit initialization
        settings_proxy_user = self.persepolis_setting.value(
            'add_link_initialization/proxy_user', None)
        if settings_proxy_user:
            self.proxy_user_lineEdit.setText(str(settings_proxy_user))

#port_spinBox initialization
        settings_port = self.persepolis_setting.value(
            'add_link_initialization/port', 0)

        self.port_spinBox.setValue(int(int(settings_port)))

        #download UserName initialization
        settings_download_user = self.persepolis_setting.value(
            'add_link_initialization/download_user', None)
        if settings_download_user:
            self.download_user_lineEdit.setText(str(settings_download_user))

#finding queues 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))

        self.add_queue_comboBox.setCurrentIndex(0)

        # add_queue_comboBox event
        self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged)

        #connect folder_pushButton
        self.folder_pushButton.clicked.connect(self.changeFolder)

        #connect OK and canel download_later button

        self.cancel_pushButton.clicked.connect(self.close)
        self.ok_pushButton.clicked.connect(
            functools.partial(self.okButtonPressed, download_later='no'))
        self.download_later_pushButton.clicked.connect(
            functools.partial(self.okButtonPressed, download_later='yes'))
        #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)

        self.change_name_lineEdit.setEnabled(False)
        self.change_name_checkBox.toggled.connect(self.changeName)

        #set focus to ok button
        self.ok_pushButton.setFocus()

        #check name of flashgot link
        if 'out' in self.flashgot_add_link_dictionary:
            self.change_name_lineEdit.setText(
                str(self.flashgot_add_link_dictionary['out']))
            self.change_name_checkBox.setChecked(True)
            del self.flashgot_add_link_dictionary['out']

#setting window size and position
        size = self.persepolis_setting.value('AddLinkWindow/size',
                                             QSize(520, 565))
        position = self.persepolis_setting.value('AddLinkWindow/position',
                                                 QPoint(300, 300))
        self.resize(size)
        self.move(position)
Example #45
0
    def okButtonPressed(self, button):
        if self.proxy_checkBox.isChecked() == False:
            ip = None
            port = None
            proxy_user = None
            proxy_passwd = None
        else:
            ip = self.ip_lineEdit.text()
            if not(ip):
                ip = None
            port = str(self.port_spinBox.value())
            if not(port):
                port = None
            proxy_user = self.proxy_user_lineEdit.text()
            if not(proxy_user):
                proxy_user = None
            proxy_passwd = self.proxy_pass_lineEdit.text()
            if not(proxy_passwd):
                proxy_passwd = None

        if self.download_checkBox.isChecked() == False:
            download_user = None
            download_passwd = None
        else:
            download_user = self.download_user_lineEdit.text()
            if not(download_user):
                download_user = None
            download_passwd = self.download_pass_lineEdit.text()
            if not(download_passwd):
                download_passwd = None

        if self.limit_checkBox.isChecked() == False:
            limit = 0
        else:
            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 self.start_checkBox.isChecked() == False:
            start_hour = None
            start_minute = None
        else:
            start_hour = str(self.start_hour_spinBox.value())
            start_minute = str(self.start_minute_spinBox.value())

        if self.end_checkBox.isChecked() == False:
            end_hour = None
            end_minute = None
        else:
            end_hour = str(self.end_hour_spinBox.value())
            end_minute = str(self.end_minute_spinBox.value())

        link = self.link_lineEdit.text()
        connections = self.connections_spinBox.value()
        download_path = self.download_folder_lineEdit.text()

        self.add_link_dictionary['start_hour'] = start_hour
        self.add_link_dictionary['start_minute'] = start_minute
        self.add_link_dictionary['end_hour'] = end_hour
        self.add_link_dictionary['end_minute'] = end_minute
        self.add_link_dictionary['link'] = link
        self.add_link_dictionary['ip'] = ip
        self.add_link_dictionary['port'] = port
        self.add_link_dictionary['proxy_user'] = proxy_user
        self.add_link_dictionary['proxy_passwd'] = proxy_passwd
        self.add_link_dictionary['download_user'] = download_user
        self.add_link_dictionary['download_passwd'] = download_passwd
        self.add_link_dictionary['download_path'] = download_path
        self.add_link_dictionary['limit'] = limit
        self.add_link_dictionary['connections'] = connections

        new_category = str(self.add_queue_comboBox.currentText())
        if new_category != self.current_category:  # it means category changed
            # first download must eliminated form former category
            # reading current_category
            current_category_file = os.path.join(
                category_folder, self.current_category)

            f = Open(current_category_file)
            f_list = f.readlines()
            f.close()
            # eliminating gid of download from current_category_file
            f = Open(current_category_file, 'w')
            for line in f_list:
                gid = line.strip()
                if gid != self.gid:
                    f.writelines(gid + '\n')

            f.close()

            # adding download to the new category
            new_category_file = os.path.join(
                category_folder, str(new_category))

            f = Open(new_category_file, 'a')
            f.writelines(self.gid + '\n')
            f.close()

        self.callback(self.add_link_dictionary, self.gid, new_category)

        self.close()
Example #46
0
def downloadAria(gid):
    #add_link_dictionary is a dictionary that contains user download request information
    download_info_file = 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']

    #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"
        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":
        #read 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']

        #eliminate 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)


#find download_path_temp from setting_file
    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)

    download_path_temp = setting_dict['download_path_temp']

    if start_time_status != 'stopped':
        #send download request to aria2
        aria_dict = {
            'gid': gid,
            'max-tries': str(setting_dict['max-tries']),
            'retry-wait': int(setting_dict['retry-wait']),
            'timeout': int(setting_dict['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)
        }
        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")
Example #47
0
    def okButtonPressed(self,button):
        global init_file
        f = Open(init_file , "w")
#writing user's input data to init file
        for i in self.ip_lineEdit.text(),self.port_spinBox.value(),self.proxy_user_lineEdit.text(),self.download_user_lineEdit.text()  :
            f.writelines(str(i) + "\n")
        f.close()

        if self.proxy_checkBox.isChecked() == False :
            ip = None
            port = None
            proxy_user = None
            proxy_passwd = None
        else :
            ip = self.ip_lineEdit.text()
            if not(ip):
                ip = None
            port = self.port_spinBox.value()
            if not(port):
                port = None
            proxy_user = self.proxy_user_lineEdit.text()
            if not(proxy_user):
                proxy_user = None
            proxy_passwd = self.proxy_pass_lineEdit.text()
            if not(proxy_passwd):
                proxy_passwd = None

        if self.download_checkBox.isChecked() == False :
            download_user = None
            download_passwd = None
        else :
            download_user = self.download_user_lineEdit.text()
            if not(download_user):
                download_user = None
            download_passwd = self.download_pass_lineEdit.text()
            if not(download_passwd):
                download_passwd = None

        if self.limit_checkBox.isChecked() == False :
            limit = 0
        else :
            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 self.start_checkBox.isChecked() == False :
            start_hour = None
            start_minute = None
        else :
            start_hour = str(self.start_hour_spinBox.value())
            start_minute = str(self.start_minute_spinBox.value())

        if self.end_checkBox.isChecked() == False :
            end_hour = None
            end_minute = None
        else :
            end_hour = str(self.end_hour_spinBox.value())
            end_minute = str(self.end_minute_spinBox.value())
            

        link = self.link_lineEdit.text()

        connections = self.connections_spinBox.value()
        download_path = self.download_folder_lineEdit.text()

        if not ('referer' in self.flashgot_add_link_dictionary) :
            self.flashgot_add_link_dictionary['referer'] = None

        if not ('header' in self.flashgot_add_link_dictionary):
            self.flashgot_add_link_dictionary['header'] = None

        if not ('out' in self.flashgot_add_link_dictionary):
            self.flashgot_add_link_dictionary['out'] = None

        if not('user-agent' in self.flashgot_add_link_dictionary):
            self.flashgot_add_link_dictionary['user-agent'] = None

        if not('load-cookies' in self.flashgot_add_link_dictionary):
            self.flashgot_add_link_dictionary['load-cookies'] = None

        final_download_path = None
        self.add_link_dictionary = {'final_download_path':final_download_path , 'start_hour':start_hour ,'start_minute' : start_minute ,'end_hour' : end_hour ,'end_minute':end_minute , 'link':link , 'ip':ip , 'port':port , 'proxy_user':proxy_user , 'proxy_passwd' : proxy_passwd , 'download_user':download_user , 'download_passwd': download_passwd ,'connections':connections , 'limit':limit, 'download_path':download_path }
        for i in self.flashgot_add_link_dictionary.keys():
            self.add_link_dictionary[i] = self.flashgot_add_link_dictionary[i]

        self.callback(self.add_link_dictionary)


        self.close()
Example #48
0
    def callBack(self , add_link_dictionary):
        gid = self.gidGenerator()

        download_info_file_list = ['***','waiting','***','***','***','***','***','***',gid , str(add_link_dictionary)]
        download_info_file = config_folder + "/download_info/" + gid
        os.system("touch " + download_info_file )
        f = Open(download_info_file , "w")
        for i in range(10):
            f.writelines(download_info_file_list[i] + "\n")

        f.close()
        
        self.download_table.insertRow(0)
        j = 0
        for i in download_info_file_list :
            item = QTableWidgetItem(i)
            self.download_table.setItem(0,j,item)
            j = j + 1

        f = Open (download_list_file , "a")
        f.writelines(gid + "\n")
        f.close()


        f = Open (download_list_file_active , "a")
        f.writelines(gid + "\n")
        f.close()
        new_download = DownloadLink(gid)
        self.threadPool.append(new_download)
        self.threadPool[len(self.threadPool) - 1].start()
        self.progressBarOpen(gid) 
        if add_link_dictionary['start_hour'] == None :
            message = "Download Starts"
        else:
            message = "Download Scheduled"
        notifySend(message ,'' , 10000 , 'no')
Example #49
0
    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']))
Example #50
0
    def __init__(self, parent, flashgot_lines, callback, persepolis_setting):
        super().__init__(persepolis_setting)
        self.persepolis_setting = persepolis_setting
        self.callback = callback
        self.parent = parent
        self.flashgot_lines = flashgot_lines

        global icons
        icons = ':/' + \
            str(self.persepolis_setting.value('settings/icons')) + '/'

        self.flashgot_lines.reverse()

        k = 1
        for i in range(len(self.flashgot_lines)):
            flashgot_add_link_dictionary_str = flashgot_lines[i].strip()
            flashgot_add_link_dictionary = ast.literal_eval(
                flashgot_add_link_dictionary_str)

            # adding row to links_table
            self.links_table.insertRow(0)

            # file_name
            if 'out' in flashgot_add_link_dictionary:
                file_name = str(flashgot_add_link_dictionary['out'])
            else:
                file_name = '***'
                # spider is finding file name
                new_spider = QueueSpiderThread(flashgot_add_link_dictionary)
                self.parent.threadPool.append(new_spider)
                self.parent.threadPool[len(self.parent.threadPool) - 1].start()
                self.parent.threadPool[len(self.parent.threadPool) -
                                       1].QUEUESPIDERRETURNEDFILENAME.connect(
                                           partial(
                                               self.parent.queueSpiderCallBack,
                                               child=self,
                                               row_number=len(
                                                   self.flashgot_lines) - k))
            k = k + 1

            item = QTableWidgetItem(file_name)
            # adding checkbox to the item
            item.setFlags(QtCore.Qt.ItemIsUserCheckable
                          | QtCore.Qt.ItemIsEnabled)
            item.setCheckState(QtCore.Qt.Checked)

            # inserting file_name
            self.links_table.setItem(0, 0, item)

            # finding link
            link = str(flashgot_add_link_dictionary['link'])
            item = QTableWidgetItem(str(link))

            # inserting link
            self.links_table.setItem(0, 1, item)

            # inserting add_link_dictionary
            item = QTableWidgetItem(flashgot_add_link_dictionary_str)
            self.links_table.setItem(0, 2, item)

        # finding queues name and adding them to add_queue_comboBox
        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))

        self.add_queue_comboBox.addItem('Single Downloads')

        self.add_queue_comboBox.addItem(QIcon(icons + 'add_queue'),
                                        'Create new queue')

        # entry initialization

        global connections
        connections = int(
            self.persepolis_setting.value('settings/connections'))
        global download_path
        download_path = str(
            self.persepolis_setting.value('settings/download_path'))

        # initialization
        self.connections_spinBox.setValue(connections)
        self.download_folder_lineEdit.setText(download_path)
        self.download_folder_lineEdit.setEnabled(False)

        # ip_lineEdit initialization
        settings_ip = self.persepolis_setting.value(
            'add_link_initialization/ip', None)
        if settings_ip:
            self.ip_lineEdit.setText(str(settings_ip))

# proxy user lineEdit initialization
        settings_proxy_user = self.persepolis_setting.value(
            'add_link_initialization/proxy_user', None)
        if settings_proxy_user:
            self.proxy_user_lineEdit.setText(str(settings_proxy_user))

# port_spinBox initialization
        settings_port = self.persepolis_setting.value(
            'add_link_initialization/port', 0)

        self.port_spinBox.setValue(int(int(settings_port)))

        # download UserName initialization
        settings_download_user = self.persepolis_setting.value(
            'add_link_initialization/download_user', None)
        if settings_download_user:
            self.download_user_lineEdit.setText(str(settings_download_user))

# connect folder_pushButton
        self.folder_pushButton.clicked.connect(self.changeFolder)

        # connect OK and canel button

        self.cancel_pushButton.clicked.connect(self.close)
        self.ok_pushButton.clicked.connect(self.okButtonPressed)

        # connect select_all_pushButton  deselect_all_pushButton
        self.select_all_pushButton.clicked.connect(self.selectAll)

        self.deselect_all_pushButton.clicked.connect(self.deselectAll)

        #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)

        # set focus to ok button
        self.ok_pushButton.setFocus()

        # add_queue_comboBox event
        self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged)

        # setting window size and position
        size = self.persepolis_setting.value('TextQueue/size', QSize(700, 500))
        position = self.persepolis_setting.value('TextQueue/position',
                                                 QPoint(300, 300))
        self.resize(size)
        self.move(position)
Example #51
0
    def callBack(self , add_link_dictionary):
        gid = self.gidGenerator()

        download_info_file_list = ['***','waiting','***','***','***','***','***','***',gid , add_link_dictionary]
        download_info_file = config_folder + "/download_info/" + gid
        os.system("touch " + download_info_file )
         
        writeList(download_info_file , download_info_file_list)
        
        self.download_table.insertRow(0)
        j = 0
        download_info_file_list[9] = str(download_info_file_list[9])
        for i in download_info_file_list :
            item = QTableWidgetItem(i)
            self.download_table.setItem(0,j,item)
            j = j + 1

        if self.selectAction.isChecked() == True:
            item = self.download_table.item(0 , 0)
            item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
            item.setCheckState(QtCore.Qt.Unchecked)
 
        f = Open (download_list_file , "a")
        f.writelines(gid + "\n")
        f.close()


        f = Open (download_list_file_active , "a")
        f.writelines(gid + "\n")
        f.close()
        new_download = DownloadLink(gid)
        self.threadPool.append(new_download)
        self.threadPool[len(self.threadPool) - 1].start()
        self.progressBarOpen(gid) 
        if add_link_dictionary['start_hour'] == None :
            message = "Download Starts"
        else:
            message = "Download Scheduled"
        notifySend(message ,'' , 10000 , 'no', systemtray = self.system_tray_icon )
Example #52
0
    def removeButtonPressed(self,button):
        self.removeAction.setEnabled(False)
        global remove_flag
        if remove_flag !=3 :
            remove_flag = 1
            while remove_flag != 2 :
                sleep(0.1)
        selected_row_return = self.selectedRow()
        if selected_row_return != None:
            gid = self.download_table.item(selected_row_return , 8 ).text()
            file_name = self.download_table.item(selected_row_return , 0).text()
            status = self.download_table.item(selected_row_return , 1).text()
            sleep(0.5)
            self.download_table.removeRow(selected_row_return)

#remove gid of download from download list file
            f = Open(download_list_file)
            download_list_file_lines = f.readlines()
            f.close()
            f = Open(download_list_file , "w")
            for i in download_list_file_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove gid of download from active download list file
            f = Open(download_list_file_active)
            download_list_file_active_lines = f.readlines()
            f.close()
            f = Open(download_list_file_active , "w")
            for i in download_list_file_active_lines:
                if i.strip() != gid:
                    f.writelines(i.strip() + "\n")
            f.close()
#remove download_info_file
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file)
            f.close()
            f.remove()
#remove file of download form download temp folder
            if file_name != '***' and status != 'complete' :
                file_name_path = temp_download_folder + "/" +  str(file_name)
                os.system('rm "' + str(file_name_path) +'"')
                file_name_aria = file_name_path + str('.aria2')
                os.system('rm "' + str(file_name_aria) +'"')
        else:
            self.statusbar.showMessage("Please select an item first!")
        remove_flag = 0
        self.selectedRow()
Example #53
0
def compatibility():
    if os.path.isdir(download_info_folder) == True:
        f = Open(download_list_file)
        download_list_file_lines = f.readlines()
        f.close()

        for line in download_list_file_lines:
            gid = line.strip()
            download_info_file = download_info_folder + "/" + gid
            f_download_info_file = Open(download_info_file)
            download_info_file_lines = f_download_info_file.readlines()
            f_download_info_file.close()
            if len(download_info_file_lines) == 10:
                list = []
                for i in range(10):
                    line_strip = download_info_file_lines[i].strip()
                    if i == 9:
                        line_strip = ast.literal_eval(line_strip)
                    list.append(line_strip)
                dictionary = {'list': list}
                os.system('echo "' + str(dictionary) + '"  >  "' +
                          str(download_info_file) + '"')
                f_download_info_file = Open(download_info_file, 'w')
                f_download_info_file.writelines(str(dictionary))
                f_download_info_file.close()

#compatibility between version 2.2 and version 2.3
        date_list = []
        for i in ['%Y', '%m', '%d', '%H', '%M', '%S']:
            date_list.append(time.strftime(i))

        for line in download_list_file_lines:
            gid = line.strip()
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file, 'r')
            f_string = f.readline()
            f.close()
            dictionary = ast.literal_eval(f_string.strip())
            list = dictionary['list']

            if len(list) == 10:
                add_link_dictionary = list[9]
                add_link_dictionary['firs_try_date'] = date_list
                add_link_dictionary['last_try_date'] = date_list

                list[9] = add_link_dictionary

                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])

                list.append(try_date)
                list.append(try_date)
                list.append('Single Downloads')

                dictionary = {'list': list}
                f = Open(download_info_file, 'w')
                f.writelines(str(dictionary))
                f.close()

                print(str(dictionary))

                f = Open(download_list_file)
                f_lines = f.readlines()
                f.close()

                f = Open(single_downloads_list_file, 'w')
                for line in f_lines:
                    f.writelines(line)

                f.close()
            elif len(list) == 12:
                list.append('Single Downloads')
                dictionary = {'list': list}
                f = Open(download_info_file, 'w')
                f.writelines(str(dictionary))
                f.close()

                f = Open(download_list_file)
                f_lines = f.readlines()
                f.close()

                f = Open(single_downloads_list_file, 'w')
                for line in f_lines:
                    gid = line.strip()
                    f.writelines(gid + '\n')

                f.close()
Example #54
0
    def propertiesCallback(self,add_link_dictionary , gid ):
        download_info_file = download_info_folder + "/" + gid
        f = Open(download_info_file)
        download_info_file_lines = f.readlines()
        f.close()
        f = Open(download_info_file , "w")
        for i in range(10):
            if i == 9 :
                f.writelines(str(add_link_dictionary) + "\n")
            else:
                f.writelines(download_info_file_lines[i].strip() + "\n")

        f.close()