# 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
    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:
        # set referer to the session
        requests_session.headers.update({'referer': referer})

    if user_agent:
        # set user_agent to the session
        requests_session.headers.update({'user-agent': user_agent})

    # find headers
    try:
        response = requests_session.head(link)
        header = response.headers
    except:
        header = {}

    # find file size
    file_size = None
    if 'Content-Length' in header.keys():  # checking if file_size is available
        file_size = int(header['Content-Length'])

        # converting file_size to KiB or MiB or GiB

# 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

    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:
        # set referer to the session
        requests_session.headers.update({'referer': referer})

    if user_agent:
        # set user_agent to the session
        requests_session.headers.update({'user-agent': user_agent})

    # find headers
    try:
        response = requests_session.head(link)
        header = response.headers
    except:
        header = {}

    # find file size
    file_size = None
    if 'Content-Length' in header.keys():  # checking if file_size is available
        file_size = int(header['Content-Length'])

        # converting file_size to KiB or MiB or GiB

        file_size = str(humanReadableSize(file_size))