Spaces:
Paused
Paused
Commit
·
4e15391
1
Parent(s):
710f611
patch
Browse files- app.py +4 -1
- templates/index.html +34 -35
app.py
CHANGED
@@ -140,13 +140,16 @@ def play(file_path):
|
|
140 |
@app.route('/get_image')
|
141 |
def get_image():
|
142 |
title = request.args.get('title')
|
|
|
|
|
|
|
143 |
cache_path = os.path.join(CACHE_DIR, f"{urllib.parse.quote(title)}.jpg")
|
144 |
|
145 |
if os.path.exists(cache_path):
|
146 |
return send_file(cache_path, mimetype='image/jpeg')
|
147 |
|
148 |
# If image is not found in cache, return a placeholder
|
149 |
-
return
|
150 |
|
151 |
if __name__ == '__main__':
|
152 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
140 |
@app.route('/get_image')
|
141 |
def get_image():
|
142 |
title = request.args.get('title')
|
143 |
+
if not title:
|
144 |
+
return jsonify({'error': 'No title provided'}), 400
|
145 |
+
|
146 |
cache_path = os.path.join(CACHE_DIR, f"{urllib.parse.quote(title)}.jpg")
|
147 |
|
148 |
if os.path.exists(cache_path):
|
149 |
return send_file(cache_path, mimetype='image/jpeg')
|
150 |
|
151 |
# If image is not found in cache, return a placeholder
|
152 |
+
return send_file('path/to/placeholder.jpg', mimetype='image/jpeg') # Ensure you have a placeholder image
|
153 |
|
154 |
if __name__ == '__main__':
|
155 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
templates/index.html
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
<head>
|
|
|
|
|
4 |
<title>Media Library</title>
|
5 |
<style>
|
6 |
body {
|
@@ -102,14 +104,14 @@
|
|
102 |
}
|
103 |
}
|
104 |
|
105 |
-
async function fetchImage(title
|
106 |
try {
|
107 |
-
const response = await fetch(`/get_image?title=${encodeURIComponent(title)}
|
108 |
-
if (response.
|
109 |
-
const data = await response.json();
|
110 |
-
return `https://via.placeholder.com/200x300?text=${title}`;
|
111 |
-
} else {
|
112 |
return response.url;
|
|
|
|
|
|
|
113 |
}
|
114 |
} catch (error) {
|
115 |
console.error('Image fetch error:', error);
|
@@ -122,41 +124,38 @@
|
|
122 |
card.className = 'card';
|
123 |
|
124 |
const title = item.path.split('/').pop();
|
125 |
-
const mediaType = item.path.includes('tv') ? 'series' : 'movie'; // Determine media type
|
126 |
const img = document.createElement('img');
|
127 |
-
img.src = await fetchImage(title
|
128 |
card.appendChild(img);
|
129 |
|
130 |
const titleElement = document.createElement('h3');
|
131 |
titleElement.textContent = title;
|
132 |
card.appendChild(titleElement);
|
133 |
-
|
134 |
if (item.contents) {
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
}
|
144 |
-
|
145 |
-
return card;
|
146 |
}
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
</body>
|
162 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Media Library</title>
|
7 |
<style>
|
8 |
body {
|
|
|
104 |
}
|
105 |
}
|
106 |
|
107 |
+
async function fetchImage(title) {
|
108 |
try {
|
109 |
+
const response = await fetch(`/get_image?title=${encodeURIComponent(title)}`);
|
110 |
+
if (response.ok) {
|
|
|
|
|
|
|
111 |
return response.url;
|
112 |
+
} else {
|
113 |
+
console.error('Image fetch error:', response.statusText);
|
114 |
+
return `https://via.placeholder.com/200x300?text=${title}`;
|
115 |
}
|
116 |
} catch (error) {
|
117 |
console.error('Image fetch error:', error);
|
|
|
124 |
card.className = 'card';
|
125 |
|
126 |
const title = item.path.split('/').pop();
|
|
|
127 |
const img = document.createElement('img');
|
128 |
+
img.src = await fetchImage(title);
|
129 |
card.appendChild(img);
|
130 |
|
131 |
const titleElement = document.createElement('h3');
|
132 |
titleElement.textContent = title;
|
133 |
card.appendChild(titleElement);
|
|
|
134 |
if (item.contents) {
|
135 |
+
const p = document.createElement('p');
|
136 |
+
p.textContent = `Contains ${item.contents.length} items`;
|
137 |
+
card.appendChild(p);
|
138 |
+
} else {
|
139 |
+
const link = document.createElement('a');
|
140 |
+
link.href = `/play/${encodeURIComponent(item.path)}`;
|
141 |
+
link.textContent = 'Play';
|
142 |
+
card.appendChild(link);
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
+
return card;
|
146 |
+
}
|
147 |
+
|
148 |
+
async function loadSection(endpoint, containerId) {
|
149 |
+
const data = await fetchData(endpoint);
|
150 |
+
const container = document.getElementById(containerId);
|
151 |
+
container.innerHTML = ''; // Clear previous content
|
152 |
+
for (const item of data) {
|
153 |
+
container.appendChild(await createCard(item));
|
154 |
+
}
|
155 |
+
}
|
156 |
|
157 |
+
document.addEventListener('DOMContentLoaded', () => {
|
158 |
+
loadSection('/films', 'films-grid');
|
159 |
+
loadSection('/tv', 'tv-grid');
|
160 |
+
});
|
161 |
+
</script>
|
|
|
|