-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.js
102 lines (49 loc) · 1.6 KB
/
video.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// const API_key = `AIzaSyD4sRdD5tBlm2J-kIK3Fb8YlITcsG25hLE`;
// const API_key = `AIzaSyC63RHmWuZg9mYGoEQ2v-FHfJvPIUiyl_w`;
const video_details = document.getElementById("video_details")
const playVideo = () =>{
let {snippet,videoId} = JSON.parse(localStorage.getItem("clicked_item"))
// console.log(data);
let title = snippet.title;
let description = snippet.description;
let iframe = document.createElement("iframe");
let tit = document.createElement("h2");
tit.innerText = title;
let des = document.createElement("p");
des.innerText = description;
iframe.src= `https://www.youtube.com/embed/${videoId}?autoplay=1&mute=1`;
iframe.width = "90%";
iframe.height = "70%";
iframe.style.marginTop = "50px";
iframe.style.border = "3px solid black";
iframe.setAttribute("allowfullscreen",true);
video_details.append(iframe,tit,des);
};
async function ab(){
try{
let res = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&key=AIzaSyC63RHmWuZg9mYGoEQ2v-FHfJvPIUiyl_w&maxResults=3
`);
let data = await res.json();
let items = data.items;
console.log("item:",items )
appendVideo(items)
}catch(error){
console.log(error)
}
}
ab()
const appendVideo = (items) =>{
items.map((el)=>{
let {snippet,id:{videoId}}=el
console.log(snippet);
let iframe = document.createElement("iframe");
iframe.src = `https://www.youtube.com/embed/${videoId}?`;
iframe.height = "177px";
iframe.width = "100%";
iframe.margin = "auto";
iframe.style.border = "1px solid black";
let div = document.createElement("div");
div.append(iframe);
document.getElementById("recommend").append(div)
})
}