Skip to content

src/utils.py

Validates the YouTube video list.

Returns:

Name Type Description
bool bool

True if validation is successful, False if any check fails.

Source code in src/utils.py
 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
def validate_yt_list() -> bool:
    """
    Validates the YouTube video list.

    Returns:
        bool: True if validation is successful, False if any check fails.
    """
    seen_ids = set()
    seen_title_artist = set()

    for item in yt_list:
        videoid = item.get("id")
        if not videoid:
            # None or Empty
            return False
        if videoid in seen_ids:
            # Duplicate
            return False
        seen_ids.add(videoid)

        metadata = item.get("metadata")
        if not metadata:
            # None or Empty
            return False

        title = metadata.get("title")
        if not title:
            # None or Empty
            return False

        artist = metadata.get("artist")
        if not artist:
            # None or Empty
            return False

        title_artist = title + artist
        if title_artist in seen_title_artist:
            # Duplicate
            return False
        seen_title_artist.add(title_artist)

        return True

Check video deletion.

Parameters:

Name Type Description Default
url str

Thumbnail Image URL

required

Returns:

Name Type Description
bool bool

True if the video is deleted, False otherwise.

Source code in src/utils.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def check_video_deletion(url) -> bool:
    """
    Check video deletion.

    Args:
        url (str): Thumbnail Image URL

    Returns:
        bool: True if the video is deleted, False otherwise.
    """
    resp = requests.head(url)
    if resp.status_code == 404:
        return True
    return False