# Path: persepolis/scripts/useful_tools.py
# def humanReadableSize(size, input_type='file_size'): 
#     labels = ['KiB', 'MiB', 'GiB', 'TiB']
#     i = -1
#     if size < 1024:
#         return str(size) + ' B'
# 
#     while size >= 1024:
#         i += 1
#         size = size / 1024
#         
#     if input_type == 'speed':
#         j = 0
#     else:
#         j = 1
# 
#     if i > j:
#         return str(round(size, 2)) + ' ' + labels[i]
#     else:
#         return str(round(size, None)) + ' ' + labels[i]


from persepolis.scripts.useful_tools import humanReadableSize
from requests.cookies import cookiejar_from_dict
from http.cookies import SimpleCookie
from requests import Session
import requests

        # converting file_size to KiB or MiB or GiB
        file_size = humanReadableSize(file_size)

    # return results
    return filename, file_size


# this function finds and returns file name for links.
def queueSpider(add_link_dictionary):
    # get download information from add_link_dictionary
    for i in ['link', 'header', 'out', 'user_agent', 'load_cookies', 'referer']:
        if not (i in add_link_dictionary):
            add_link_dictionary[i] = None

    link = add_link_dictionary['link']
    header = add_link_dictionary['header']
    user_agent = add_link_dictionary['user_agent']
    raw_cookies = add_link_dictionary['load_cookies']
    referer = add_link_dictionary['referer']

    requests_session = requests.Session()  # defining a requests Session

    if raw_cookies:  # set cookies
        cookie = SimpleCookie()
        cookie.load(raw_cookies)

        cookies = {key: morsel.value for key, morsel in cookie.items()}
        requests_session.cookies = cookiejar_from_dict(cookies)


# Path: persepolis/scripts/useful_tools.py
# def humanReadableSize(size, input_type='file_size'): 
#     labels = ['KiB', 'MiB', 'GiB', 'TiB']
#     i = -1
#     if size < 1024:
#         return str(size) + ' B'
# 
#     while size >= 1024:
#         i += 1
#         size = size / 1024
#         
#     if input_type == 'speed':
#         j = 0
#     else:
#         j = 1
# 
#     if i > j:
#         return str(round(size, 2)) + ' ' + labels[i]
#     else:
#         return str(round(size, None)) + ' ' + labels[i]


# Path: persepolis/scripts/spider.py
from persepolis.scripts.useful_tools import humanReadableSize
from requests.cookies import cookiejar_from_dict
from http.cookies import SimpleCookie
from requests import Session
import requests


        # converting file_size to KiB or MiB or GiB
        file_size = humanReadableSize(file_size)

    # return results
    return filename, file_size


# this function finds and returns file name for links.
def queueSpider(add_link_dictionary):
    # get download information from add_link_dictionary
    for i in ['link', 'header', 'out', 'user_agent', 'load_cookies', 'referer']:
        if not (i in add_link_dictionary):
            add_link_dictionary[i] = None

    link = add_link_dictionary['link']
    header = add_link_dictionary['header']
    user_agent = add_link_dictionary['user_agent']
    raw_cookies = add_link_dictionary['load_cookies']
    referer = add_link_dictionary['referer']

    requests_session = requests.Session()  # defining a requests Session

    if raw_cookies:  # set cookies
        cookie = SimpleCookie()
        cookie.load(raw_cookies)

        cookies = {key: morsel.value for key, morsel in cookie.items()}
        requests_session.cookies = cookiejar_from_dict(cookies)


    if referer: