示例#1
0
def startTime(start_hour, start_minute, gid):
    print("Download starts at " + start_hour + ":" + start_minute)
    logger.sendToLog("Download starts at " + start_hour + ":" + start_minute,
                     "INFO")
    sigma_start = sigmaTime(start_hour, start_minute)  # getting sima time
    sigma_now = nowTime()  # getting sigma now time
    # getting download_info_file path
    download_info_file = os.path.join(download_info_folder, gid)
    status = 'scheduled'  # defining status
    while sigma_start != sigma_now:  # this loop is countinuing until download time arrival!
        time.sleep(2.1)
        sigma_now = nowTime()
        try:  # this part is reading download informations for finding download status , perhaps user canceled download! try command used for avoiding some problems when readList reading files
            download_info_file_list = readList(download_info_file)
        except:
            download_info_file_list = ['some_name', 'scheduled']

        # if download_info_file_list[1] = stopped >> it means that user
        # canceled download , and loop is breaking!
        if download_info_file_list[1] == 'stopped':
            status = 'stopped'
            break
        else:
            status = 'scheduled'
    return status  # if user canceled download , then 'stopped' returns and if download time arrived then 'scheduled' returns!
示例#2
0
def downloadCompleteAction(path, download_path, file_name):
    i = 1
    file_path = os.path.join(download_path, file_name)

    # rename file if file already existed
    while os.path.isfile(file_path):
        file_name_split = file_name.split('.')
        extension_length = len(file_name_split[-1]) + 1

        new_name = file_name[0:-extension_length] + \
            '_' + str(i) + file_name[-extension_length:]
        file_path = os.path.join(download_path, new_name)
        i = i + 1

#move the file to the download folder
    try:
        shutil.copy(str(path), str(file_path))
        os.remove(path)

    except:
        print('Persepolis can not move file')
        logger.sendToLog('Persepolis can not move file', "ERROR")
        file_path = path

    return str(file_path)
示例#3
0
def limitSpeed(gid, limit):
    try:
        answer = server.aria2.changeOption(gid, {'max-download-limit': limit})
    except:
        str("None")
    print("Download speed is limited")
    logger.sendToLog("Download speed is limited", "INFO")
示例#4
0
def downloadStop(gid):
    download_info_file = os.path.join(download_info_folder, gid)
    download_info_file_list = readList(download_info_file)
    # if status is scheduled so download request is not sended to aria2 yet!
    status = download_info_file_list[1]
    if status != 'scheduled':
        try:
            # this section is sending request to aria2 to removing download.
            # see aria2 documentation for more informations
            answer = server.aria2.remove(gid)
            if status == 'downloading':
                server.aria2.removeDownloadResult(gid)
        except:
            answer = str("None")
        print(answer + " stopped")
        logger.sendToLog(answer + " stopped", "INFO")
    else:
        answer = 'stopped'

    if status != 'complete':
        add_link_dictionary = download_info_file_list[9]
        add_link_dictionary['start_hour'] = None
        add_link_dictionary['start_minute'] = None
        add_link_dictionary['end_hour'] = None
        add_link_dictionary['end_minute'] = None
        add_link_dictionary['after_download'] = 'None'

        download_info_file_list[1] = "stopped"
        download_info_file_list[9] = add_link_dictionary
        writeList(download_info_file, download_info_file_list)
    return answer
示例#5
0
文件: play.py 项目: sotoup/persepolis
def playNotification(file):
    # getting user setting from persepolis_setting
    persepolis_setting = QSettings('persepolis_download_manager', 'persepolis')

    # enbling or disabling notification sound in persepolis_setting
    enable_notification = str(persepolis_setting.value('settings/sound'))

    # volume of notification in persepolis_setting(an integer between 0 to 100)
    volume_percent = int(persepolis_setting.value('settings/sound-volume'))

    # Paplay volume value must be between 0 (silent) and 65536 (100% volume)
    volume = int((65536 * volume_percent) / 100)

    if enable_notification == 'yes':
        if os_type == 'Linux':
            os.system("paplay --volume='" + str(volume) + "' '" + file + "' &")

        elif os_type == 'Darwin':
            os.system("osascript -e 'set volume alert volume " + str(volume) +
                      "'")
            os.system("osascript -e 'beep 3' &")

        elif os_type == 'Windows':
            CREATE_NO_WINDOW = 0x08000000
            subprocess.Popen(['rundll32', 'user32.dll,MessageBeep'],
                             shell=False,
                             creationflags=CREATE_NO_WINDOW)

        elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
            print(
                'sorry!no notification sound available for now in FreeBSD and OpenBSD'
            )
            logger.sendToLog(
                "Sorry, no notification sound available for now in FreeBSD and OpenBSD",
                "WARNING")
示例#6
0
def aria2Version():
    try:
        answer = server.aria2.getVersion()
    except:
        print("aria2 not respond!")
        logger.sendToLog("Aria2 didn't respond!", "ERROR")
        answer = "did not respond"
    return answer
示例#7
0
 def run(self):
     try:
         filename = spider.queueSpider(self.add_link_dictionary)
         self.QUEUESPIDERRETURNEDFILENAME.emit(filename)
     except:
         print("Spider couldn't find download information")
         logger.sendToLog("Spider couldn't find download information",
                          "ERROR")
示例#8
0
 def run(self):
     try:
         filesize = spider.addLinkSpider(self.add_link_dictionary)
         self.ADDLINKSPIDERSIGNAL.emit(filesize)
     except Exception as e:
         print(str(e))
         print("Spider couldn't find download information")
         logger.sendToLog("Spider couldn't find download information",
                          "ERROR")
示例#9
0
def shutDown():
    try:
        answer = server.aria2.shutdown()
        print("Aria2 Shutdown : " + str(answer))
        logger.sendToLog("Aria2 Shutdown : " + str(answer), "INFO")
        return 'ok'
    except:
        print("Aria2 Shutdown Error")
        logger.sendToLog("Aria2 Shutdown Error", "ERROR")
        return 'error'
示例#10
0
def downloadPause(gid):
    download_info_file = os.path.join(download_info_folder, gid)
    readList(download_info_file)
    # this section is sending pause request to aira2 . see aria2 documentation
    # for more informations
    try:
        answer = server.aria2.pause(gid)
        version_answer = 'ok'
    except:
        answer = str("None")

    print(answer + " paused")
    logger.sendToLog(answer + " paused", "INFO")
    return answer
示例#11
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 ')
示例#12
0
def endTime(end_hour, end_minute, gid):
    time.sleep(1)
    print("end time is actived " + gid)
    logger.sendToLog("End time is activated " + gid, "INFO")
    sigma_end = sigmaTime(end_hour, end_minute)
    sigma_now = nowTime()
    download_info_file = os.path.join(download_info_folder, gid)

    while sigma_end != sigma_now:
        status_file = 'no'
        # waiting for start downloading :
        while status_file == 'no':
            time.sleep(0.5)
            try:
                download_info_file_list = readList(download_info_file)
                status_file = 'yes'
                status = download_info_file_list[1]
            except:
                status_file = 'no'
# checking download's status
        if status == 'downloading' or status == 'paused' or status == 'waiting':
            answer = 'continue'
        else:
            answer = 'end'
            print("Download ended before! " + str(gid))
            logger.sendToLog("Download has been finished! " + str(gid), "INFO")
            break

        sigma_now = nowTime()
        time.sleep(2.1)

    if answer != 'end':
        print("Time is Up")
        logger.sendToLog("Time is up!", "INFO")
        answer = downloadStop(gid)
        i = 0
        # trying to stop download 10 times
        while answer == 'None' and (i <= 9):
            time.sleep(1)
            answer = downloadStop(gid)
            i = i + 1
        if (answer == 'None') and (os_type != 'Windows'):
            os.system("killall aria2c")

        download_info_file_list = readList(download_info_file)
        add_link_dictionary = download_info_file_list[9]
        add_link_dictionary['end_hour'] = None
        add_link_dictionary['end_minute'] = None
        download_info_file_list[9] = add_link_dictionary
        download_info_file_list[1] = "stopped"
        writeList(download_info_file, download_info_file_list)
 import platform
+from pyogg import VorbisFile
+from ossaudiodev import open as ossOpen, AFMT_S16_NE
 
 os_type = platform.system()
 
@@ -36,18 +38,11 @@ def playNotification(file):
     if enable_notification == 'yes':
         if os_type == 'Linux' or os_type == 'FreeBSD' or os_type == 'OpenBSD':
 
-            pipe = subprocess.Popen(['paplay', '--volume=' + str(volume),
-                                     str(file)],
-                                    stderr=subprocess.PIPE,
-                                    stdout=subprocess.PIPE,
-                                    stdin=subprocess.PIPE,
-                                    shell=False)
-
-            answer = pipe.wait()
-
-            if answer != 0:
-                logger.sendToLog(
-                    "paplay not installed!Install it for playing sound notification", "WARNING")
+            sound = VorbisFile(file)
+            dsp = ossOpen('/dev/dsp', 'w')
+            dsp.setparameters(AFMT_S16_NE, sound.channels, sound.frequency)
+            dsp.write(sound.buffer)
+            dsp.close()
 
         elif os_type == 'Darwin':
 
示例#14
0
def downloadAria(gid):
    # add_link_dictionary is a dictionary that contains user download request
    # information
    download_info_file = os.path.join(download_info_folder, gid)
    download_info_file_list = readList(download_info_file)
    add_link_dictionary = download_info_file_list[9]

    link = add_link_dictionary['link']
    ip = add_link_dictionary['ip']
    port = add_link_dictionary['port']
    proxy_user = add_link_dictionary['proxy_user']
    proxy_passwd = add_link_dictionary['proxy_passwd']
    download_user = add_link_dictionary['download_user']
    download_passwd = add_link_dictionary['download_passwd']
    connections = add_link_dictionary['connections']
    limit = add_link_dictionary['limit']
    start_hour = add_link_dictionary['start_hour']
    start_minute = add_link_dictionary['start_minute']
    end_hour = add_link_dictionary['end_hour']
    end_minute = add_link_dictionary['end_minute']
    header = add_link_dictionary['header']
    out = add_link_dictionary['out']
    user_agent = add_link_dictionary['user-agent']
    cookies = add_link_dictionary['load-cookies']
    referer = add_link_dictionary['referer']

    # setting time and date for last_try_date
    now_date_list = nowDate()
    add_link_dictionary['last_try_date'] = now_date_list

    # making header option
    header_list = []
    if cookies != None:
        semicolon_split_cookies = cookies.split('; ')
        for i in semicolon_split_cookies:
            equal_split_cookie = i.split('=')
            join_cookie = ':'.join(equal_split_cookie)
            if i != '':
                header_list.append(join_cookie)

    if header != None:
        semicolon_split_header = header.split('; ')
        for i in semicolon_split_header:
            equal_split_header = i.split('=')
            join_header = ':'.join(equal_split_header)
            if i != '':
                header_list.append(join_header)

    if len(header_list) == 0:
        header_list = None

    if start_hour != None:
        download_info_file_list[1] = "scheduled"

    # writing new informations on download_info_file
    download_info_file_list[9] = add_link_dictionary
    writeList(download_info_file, download_info_file_list)

    if ip:
        ip_port = str(ip) + ":" + str(port)
    else:
        ip_port = ""

    if start_hour != None:
        start_time_status = startTime(start_hour, start_minute, gid)
    else:
        start_time_status = "downloading"

    if start_time_status == "scheduled":
        # reading new limit option before starting download! perhaps user
        # changed this in progress bar window
        download_info_file_list = readList(download_info_file)
        add_link_dictionary = download_info_file_list[9]

        limit = add_link_dictionary['limit']

        # eliminating start_hour and start_minute!
        add_link_dictionary['start_hour'] = None
        add_link_dictionary['start_minute'] = None
        download_info_file_list[9] = add_link_dictionary
        writeList(download_info_file, download_info_file_list)


# finding download_path_temp from persepolis_setting
    persepolis_setting.sync()
    download_path_temp = persepolis_setting.value(
        'settings/download_path_temp')

    if start_time_status != 'stopped':
        # sending download request to aria2
        if link[0:5] != "https":
            aria_dict = {
                'gid': gid,
                'max-tries':
                str(persepolis_setting.value('settings/max-tries')),
                'retry-wait':
                int(persepolis_setting.value('settings/retry-wait')),
                'timeout': int(persepolis_setting.value('settings/timeout')),
                'header': header_list,
                'out': out,
                'user-agent': user_agent,
                'referer': referer,
                'all-proxy': ip_port,
                'max-download-limit': limit,
                'all-proxy-user': str(proxy_user),
                'all-proxy-passwd': str(proxy_passwd),
                'http-user': str(download_user),
                'http-passwd': str(download_passwd),
                'split': '16',
                'max-connection-per-server': str(connections),
                'min-split-size': '1M',
                'continue': 'true',
                'dir': str(download_path_temp)
            }
        else:
            aria_dict = {
                'gid': gid,
                'max-tries':
                str(persepolis_setting.value('settings/max-tries')),
                'retry-wait':
                int(persepolis_setting.value('settings/retry-wait')),
                'timeout': int(persepolis_setting.value('settings/timeout')),
                'header': header_list,
                'out': out,
                'user-agent': user_agent,
                'referer': referer,
                'all-proxy': ip_port,
                'max-download-limit': limit,
                'all-proxy-user': str(proxy_user),
                'all-proxy-passwd': str(proxy_passwd),
                'split': '16',
                'max-connection-per-server': str(connections),
                'min-split-size': '1M',
                'continue': 'true',
                'dir': str(download_path_temp)
            }

        try:
            if ("http" in link[0:5]):
                answer = server.aria2.addUri([link], aria_dict)
            else:
                answer = server.aria2.addUri([link], aria_dict)

            print(answer + " Starts")
            logger.sendToLog(answer + " Starts", 'INFO')
            if end_hour != None:
                endTime(end_hour, end_minute, gid)

        except:
            print("None Starts")
            logger.sendToLog("None Starts", "INFO")
            # if request was unsuccessful return None!
            return 'None'
    else:
        # if start_time_status is "stopped" it means download Canceled by user
        print("Download Canceled")
        logger.sendToLog("Download Canceled", "INFO")