-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.js
230 lines (117 loc) · 4.47 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import nvbr from "./componnents/navbar.js"
document.getElementById("navbar").innerHTML=nvbr()
let child1=document.getElementById("first-child")
import filterbtn from "./componnents/filter.js"
document.getElementById("filtersdiv").innerHTML=filterbtn()
let data= JSON.parse(localStorage.getItem("video_data"))
console.log(data)
let bag = "";
let tag = data.snippet.tags;
let g =0;
for(let el of tag){
if(g<5){
bag+="#"+el+" "
}
else{
break
}
g++
}
let video_id = data.id.videoId || data.id
let channel_picture = await channel(data.snippet.channelId)
child1.innerHTML=`
<iframe width="100%" height="100%" src="https://www.youtube.com/embed/${video_id}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
`
let display_data=data.snippet
let info_container=document.getElementById("container")
info_container.innerHTML=`
<div id="video_heading2">${bag}</div>
<div id="video_heading">${display_data.title}</div>
<div id="info-section">
<div id="section-1">
<div id="channel_image"> <img src="${channel_picture}" class="channel-icon" alt=""></div>
<div id="channel_name"><p id="chnlname">${display_data.channelTitle}</p>
<p id="subscribers"><span>99.7k</span>subscribers</p>
</div>
<div id="sunscribbtn">
<button>Subscribe</button>
</div>
</div>
<div id="section-2">
<button id="like"><i class="fa-regular fa-thumbs-up"></i> Like</button>
<button id="dislike"><i class="fa-regular fa-thumbs-down"></i></button>
<button><i class="fa-solid fa-share"></i> Share</button>
<button><i class="fa-solid fa-circle-down"></i> Download</button>
<button><i class="fa-solid fa-ellipsis"></i></button>
</div>
</div>
<div id="decription">
PUBLISH AT : ${data.snippet.publishedAt}
<br>
${display_data.description}
</div>
`
import jump from "./componnents/redirect.js"
document.getElementById("searchbtn").addEventListener("click" , jump())
const show= async ()=>{
let API_KEYS =["AIzaSyASPLAWmjCPDRoiMtt1AHGQ0TGyRx9wTRU","AIzaSyASPLAWmjCPDRoiMtt1AHGQ0TGyRx9wTRU","AIzaSyBihnXKUmx9h6DHAlTNkrZ-6znzrz3ME1M","AIzaSyA8HVQEsyROLmeZ4P3GhKRCU2BajTnJUNc","AIzaSyAgE8JOY06kJSUxBYYXCGKhQnhx1qD8jdA"]
let num= Math.floor(Math.random()*2)
let API_KEY = API_KEYS[num]
let search = localStorage.getItem("search_term")
let data = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=${search}&key=${API_KEY}`)
data = await data.json()
let actual_data = data.items
content_show(actual_data)
}
show()
const change =async (el)=>{
let value=el.innerHTML
let data = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=${value}&key=AIzaSyCGz_8bE32q4NAkjdAXjpAiigBS6z9ZASU`)
data = await data.json()
let actual_data = data.items
content_show(actual_data)
console.log(el)
}
let arr = document.querySelectorAll("#filtersdiv>button")
for(let el of arr){
el.addEventListener("click",function(){
change(el)
})
}
function content_show(data){
let parent = document.querySelector("#append_data")
document.querySelector("#append_data").innerHTML=null
for(let el of data){
let child = document.createElement("div")
child.id="datahere"
child.addEventListener("click",function(){
store(el)
})
child.innerHTML = `
<div id="chnl_image">
<img src="${el.snippet.thumbnails.medium.url}" alt="">
</div>
<div id="infohere">
<h4>${el.snippet.title}</h4>
<p>${el.snippet.channelTitle}</p>
</div> `
parent.append(child)
}
}
const store =(el)=>{
localStorage.setItem("video_data",JSON.stringify(el))
window.location.href="video.html"
}
const channel= async (channelid)=>{
let g= await fetch ( ` https://www.googleapis.com/youtube/v3/channels?part=snippet&id=${channelid}&key=AIzaSyA8HVQEsyROLmeZ4P3GhKRCU2BajTnJUNc` )
g = await g.json()
let url = await g.items[0].snippet.thumbnails.high.url
return await url
}
// `
// let iframe = document.createElement("iframe")
// iframe.src=`https://www.youtube.com/embed/${video_id}`
// iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture;allowfullscreen"
// child1.append(iframe)
// ` <iframe width="560" height="315" src="https://www.youtube.com/${video_id}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen> </iframe>`
// console.log(video_id)