File size: 1,104 Bytes
18fe5e3
0c936fa
4fb50a9
 
725c75e
 
 
 
 
 
 
 
0c936fa
4fb50a9
18fe5e3
 
 
 
 
 
4fb50a9
0c936fa
dab57e4
725c75e
 
dab57e4
 
6cc88fe
b35af45
6ae9b17
 
 
b35af45
 
 
7e5e159
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
import urllib
from Functions.db_connection import default_app


def get_youtube_player_html():
    """Returns the static HTML container for YouTube player (API loaded in page head)"""
    return """
<div style="margin:0 auto; width: fit-content;">
  <div id="yt-container" style="width: 640px; height: 360px;"></div>
</div>
"""


def youtube_link_to_id(link):
    try:
        from urllib.parse import urlparse, parse_qs
        parsed = urlparse(link)
        return parse_qs(parsed.query)['v'][0]
    except (KeyError, IndexError):
        raise ValueError(f"Invalid YouTube URL: {link}")


def get_video_embed_by_id(video_id):
    """Returns just the video ID - actual loading happens via JavaScript in main_page"""
    return video_id


def get_video_link_by_pointer(pointer):
    video = default_app.database().child("videos").child(str(pointer)).get().val()
    if video["complete"]:
        return None
    return video["url"]


def change_video_completion_status(is_complete, video_pointer):
    default_app.database().child("videos").child(str(video_pointer)).child("complete").set(is_complete)