File size: 1,781 Bytes
151773c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re

def is_valid_url(url):
    """
    Validates the URL.

    Args:
        url (str): The URL to validate.

    Returns:
        bool: True if the URL is valid, False otherwise.
    """
    regex = re.compile(
        r'^(?:http|ftp)s?://'  # http:// or https://
        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  # domain...
        r'localhost|'  # localhost...
        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # ...or ipv4
        r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # ...or ipv6
        r'(?::\d+)?'  # optional port
        r'(?:/?|[/?]\S+)$', re.IGNORECASE)
    return re.match(regex, url) is not None

def convert_to_gb(space_str):
    """
    Converts a space string like '50 GB' or '3.33 GB' to a float representing the number of GB.

    Args:
        space_str (str): The space string to convert.

    Returns:
        float: The space in GB.
    """
    return float(space_str.split()[0])

def bytes_to_human_readable(num, suffix="B"):
    """
    Converts bytes to a human-readable format.

    Args:
        num (int): The number of bytes.
        suffix (str): The suffix to use (default is 'B').

    Returns:
        str: The human-readable string.
    """
    for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
        if abs(num) < 1024.0:
            return f"{num:3.1f} {unit}{suffix}"
        num /= 1024.0
    return f"{num:.1f} Y{suffix}"

def encode_episodeid(title, season, episode):
    """
    Encodes the episode ID based on title, season, and episode.

    Args:
        title (str): The title of the TV show.
        season (str): The season of the TV show.
        episode (str): The episode number.

    Returns:
        str: The encoded episode ID.
    """
    return f"{title}_{season}_{episode}"