maryna7679 commited on
Commit
71f443d
·
1 Parent(s): 0b014ac
Files changed (3) hide show
  1. Functions/temp.py +0 -13
  2. README.md +2 -2
  3. temp.py +58 -0
Functions/temp.py DELETED
@@ -1,13 +0,0 @@
1
- import urllib
2
-
3
-
4
- def youtube_link_to_id(link):
5
- try:
6
- from urllib.parse import urlparse, parse_qs
7
- parsed = urlparse(link)
8
- return parse_qs(parsed.query)['v'][0]
9
- except (KeyError, IndexError):
10
- raise ValueError(f"Invalid YouTube URL: {link}")
11
-
12
-
13
- print(youtube_link_to_id("https://www.youtube.com/watch?v=tkMg8g8vVUo&ab_channel=ASLTHAT"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -5,9 +5,9 @@ colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.49.1
8
- app_file: app.py
9
  pinned: false
10
- hf_oauth: true
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
5
  colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.49.1
8
+ app_file: temp.py
9
  pinned: false
10
+ hf_oauth: false
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
temp.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def get_youtube_player_html():
5
+ """Returns the static HTML container for YouTube player (API loaded in page head)"""
6
+ return """
7
+ <div style="margin:0 auto; width: fit-content;">
8
+ <div id="yt-container" style="width: 640px; height: 360px;"></div>
9
+ </div>
10
+ """
11
+
12
+
13
+ css = """
14
+ #yt-container {
15
+ }
16
+ """
17
+
18
+ yt_init_js = """
19
+ <script src="https://www.youtube.com/iframe_api"></script>
20
+ <script>
21
+ window.onYouTubeIframeAPIReady = function() {
22
+ window.ytPlayer = new YT.Player('yt-container', {
23
+ height: '360',
24
+ width: '640',
25
+ playerVars: {
26
+ origin: window.location.origin,
27
+ playsinline: 1
28
+ },
29
+ events: {
30
+ 'onReady': function(event) {
31
+ window.ytPlayerReady = true;
32
+ }
33
+ }
34
+ });
35
+ };
36
+ </script>
37
+ """
38
+
39
+
40
+ with gr.Blocks(css=css, head=yt_init_js) as demo:
41
+ video_embed = gr.HTML(value=get_youtube_player_html())
42
+ current_video_id = gr.Textbox(value="tkMg8g8vVUo", visible=False, interactive=False)
43
+
44
+ demo.load(
45
+ fn=None,
46
+ inputs=current_video_id,
47
+ outputs=None,
48
+ js="""(videoId) => {
49
+ const checkPlayer = setInterval(() => {
50
+ if (window.ytPlayer && window.ytPlayer.cueVideoById) {
51
+ clearInterval(checkPlayer);
52
+ window.ytPlayer.cueVideoById(videoId);
53
+ }
54
+ }, 100);
55
+ }"""
56
+ )
57
+
58
+ demo.launch()