-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
249 lines (216 loc) · 10.3 KB
/
index.html
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VidSrc Viewer</title>
<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
/* Custom styles for the left pane */
#leftPane {
border-right: 1px solid #ccc;
height: 100vh;
overflow-y: auto;
}
#listItems {
margin-top: 20px;
}
</style>
</head>
<body class="bg-dark text-light">
<div class="container-fluid">
<div class="row">
<!-- Left Pane -->
<div id="leftPane" class="col-md-3">
<h2>My List</h2>
<div class="input-group mb-3">
<input type="text" id="imdbInput" class="form-control" placeholder="Add IMDb ID (e.g., tt0417299)">
<div class="input-group-append">
<button class="btn btn-primary" id="addButton">Add</button>
</div>
</div>
<div id="listItems">
<!-- List items will be added here -->
</div>
<ul id="imdbList" class="list-group">
<!-- IMDb IDs will be displayed here -->
</ul>
</div>
<div class="col-md-9">
<h2 class="my-4 text-center">VidSrc Viewer</h2>
<div class="row justify-content-center mb-4">
<div class="col-md-8">
<div class="input-group mb-3">
<input type="text" id="vidSrcUrl" class="form-control" placeholder="VidSrc Url (e.g., vidsrc.me)" value="vidsrc.me">
</div>
<div class="input-group mb-3">
<input type="text" id="imdbId" class="form-control" placeholder="IMDb ID (e.g., tt0417299)" value="tt0417299">
</div>
<div class="row mb-3">
<div class="input-group col-md-6">
<input type="number" id="season" class="form-control" placeholder="Season" min="1" value="2">
</div>
<div class="input-group col-md-6">
<input type="number" id="episode" class="form-control" placeholder="Episode" min="1" value="2">
</div>
</div>
</div>
</div>
<div class="row justify-content-center col-md-12">
<div class="col-md-9">
<div id="iframeContainer" class="embed-responsive embed-responsive-16by9">
<!-- Video iframe will load here -->
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS and dependencies (Popper.js and jQuery) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/@supabase/[email protected]/dist/umd/supabase.js"></script>
<script type="module">
// Initialize Supabase client
import { createClient } from "https://cdn.skypack.dev/@supabase/supabase-js";
const supabaseUrl = 'https://nlpqnilzcamieqcyvrtm.supabase.co'; // Replace with your Supabase URL
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im5scHFuaWx6Y2FtaWVxY3l2cnRtIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjU4NzE3NjksImV4cCI6MjA0MTQ0Nzc2OX0.yAJKEBru2J-y-hx2pv2SnM7a_CBa8B9ll8HSQqxYVHM'; // Replace with your Supabase public API key
const omdbApiKey = 'd786eb7';
const supabase = createClient(supabaseUrl, supabaseKey);
// Function to generate and load the iframe
async function generateIframe(event) {
const vidSrcUrl = document.getElementById('vidSrcUrl').value;
const imdbId = document.getElementById('imdbId').value;
const season = document.getElementById('season').value;
const episode = document.getElementById('episode').value;
// Save and update data in Supabase
if (event !== undefined && event.isTrusted) {
await updateData(imdbId, season, episode);
}
// Build the iframe URL
const iframeUrl = `https://${vidSrcUrl}/embed/tv?imdb=${imdbId}&season=${season}&episode=${episode}`;
// Embed the iframe
const iframe = `<iframe src="${iframeUrl}" class="embed-responsive-item" frameborder="0" allowfullscreen></iframe>`;
document.getElementById('iframeContainer').innerHTML = iframe;
}
// Update data in Supabase
async function updateData(imdbId, season, episode) {
try {
// Upsert data in Supabase
const { data, error } = await supabase
.from('episodes')
.upsert([
{ imdb: imdbId, season: parseInt(season, 10), episode: parseInt(episode, 10) }
], { onConflict: ['imdb'] });
if (error) throw error;
console.log('Data updated:', data);
} catch (error) {
console.error('Error updating data:', error);
}
}
// Fetch data from Supabase
async function fetchData(imdbId) {
try {
// Fetch data from Supabase
const { data, error } = await supabase
.from('episodes')
.select('season, episode')
.eq('imdb', imdbId)
.single();
if (error) throw error;
if (data) {
document.getElementById('season').value = data.season || 1;
document.getElementById('episode').value = data.episode || 1;
} else {
// Set default values if no data is found
document.getElementById('season').value = 1;
document.getElementById('episode').value = 1;
}
} catch (error) {
console.error('Error fetching data:', error);
}
}
// Function to add IMDb ID to Supabase
async function addImdbId(imdbId) {
try {
const { data, error } = await supabase
.from('my_list')
.insert([{ imdb_id: imdbId }]);
if (error) throw error;
console.log('IMDb ID added:', data);
fetchImdbList(); // Refresh list after adding
} catch (error) {
console.error('Error adding IMDb ID:', error);
}
}
// Event listener for adding IMDb ID
document.getElementById('addButton').addEventListener('click', () => {
const imdbId = document.getElementById('imdbInput').value;
if (imdbId) {
addImdbId(imdbId);
document.getElementById('imdbInput').value = ''; // Clear input field
}
});
// Function to fetch poster from OMDb API
async function fetchTitle(imdbId) {
console.log(imdbId);
try {
const response = await fetch(`https://www.omdbapi.com/?i=${imdbId}&apikey=${omdbApiKey}`);
const data = await response.json();
if (data.Response === 'True') {
return data.Title;
} else {
console.error('Poster not found:', data.Error);
}
} catch (error) {
console.error('Error fetching poster:', error);
}
return imdbId;
}
// Function to fetch and display IMDb IDs from Supabase
async function fetchImdbList() {
try {
const { data, error } = await supabase
.from('my_list')
.select('imdb_id');
if (error) throw error;
const imdbList = document.getElementById('imdbList');
imdbList.innerHTML = ''; // Clear current list
data.forEach(item => {
const listItem = document.createElement('li');
listItem.className = 'list-group-item text-dark';
var title = fetchTitle(item.imdb_id).then((title) => {
listItem.textContent = title
listItem.addEventListener('click', () => {
document.getElementById('imdbId').value = item.imdb_id;
generateIframe(); // Optionally regenerate the iframe
});
imdbList.appendChild(listItem);
});
});
} catch (error) {
console.error('Error fetching IMDb list:', error);
}
}
// Load previous values from local storage
window.onload = function() {
fetchImdbList();
const lastImdb = localStorage.getItem('lastImdb');
if (lastImdb) document.getElementById('imdbId').value = lastImdb;
fetchData(lastImdb);
setTimeout(generateIframe, 1000);
}
// Automatically generate the iframe and fetch data when IMDb ID changes
document.getElementById('imdbId').addEventListener('input', function() {
const imdbId = document.getElementById('imdbId').value;
localStorage.setItem('lastImdb', imdbId);
fetchData(imdbId); // Fetch and update fields based on IMDb ID
generateIframe(); // Update iframe based on new values
});
document.getElementById('vidSrcUrl').addEventListener('input', generateIframe);
document.getElementById('season').addEventListener('input', generateIframe);
document.getElementById('episode').addEventListener('input', generateIframe);
</script>
</body>
</html>