ChandimaPrabath commited on
Commit
b6642bd
·
1 Parent(s): a77c7cb
app.py CHANGED
@@ -19,7 +19,7 @@ CACHE_DIR = os.getenv("CACHE_DIR")
19
  if not os.path.exists(CACHE_DIR):
20
  os.makedirs(CACHE_DIR)
21
 
22
- indexer()
23
 
24
  if not os.path.exists(INDEX_FILE):
25
  raise FileNotFoundError(f"{INDEX_FILE} not found. Please make sure the file exists.")
@@ -53,7 +53,6 @@ def prefetch_metadata():
53
  def start_prefetching():
54
  prefetch_metadata()
55
 
56
-
57
  thread = Thread(target=start_prefetching)
58
  thread.daemon = True
59
  thread.start()
@@ -140,9 +139,10 @@ def film_page(title):
140
  else:
141
  return jsonify({'error': 'Metadata not found'}), 404
142
 
 
143
  return jsonify({
144
  'metadata': metadata,
145
- 'file_path': film_file_path
146
  })
147
 
148
  @app.route('/api/tv/<path:show_title>')
@@ -179,29 +179,31 @@ def get_metadata():
179
 
180
  return jsonify({'error': 'Metadata not found'}), 404
181
 
182
- @app.route('/film/<path:title>')
183
- def film_details(title):
184
- return render_template('film_details_page.html', title=title)
185
-
186
- @app.route('/film/<path:title>/play')
187
- def film_player(title):
188
  title = urllib.parse.unquote(title)
189
  film_file_path = get_film_file_path(title)
190
  if not film_file_path:
191
  return jsonify({'error': 'Film not found'}), 404
192
-
193
- cached_file_path = download_film_if_needed(film_file_path)
194
 
195
- return render_template('film_player.html', title=title)
 
 
 
 
 
 
 
196
 
197
- @app.route('/stream/<path:title>')
198
- def stream_film(title):
199
- title = urllib.parse.unquote(title)
200
- film_file_path = get_film_file_path(title)
201
- if not film_file_path:
202
- return jsonify({'error': 'Film not found'}), 404
203
 
204
- cached_file_path = download_film_if_needed(film_file_path)
 
 
 
 
205
 
206
  def generate():
207
  with open(cached_file_path, 'rb') as f:
 
19
  if not os.path.exists(CACHE_DIR):
20
  os.makedirs(CACHE_DIR)
21
 
22
+ #indexer()
23
 
24
  if not os.path.exists(INDEX_FILE):
25
  raise FileNotFoundError(f"{INDEX_FILE} not found. Please make sure the file exists.")
 
53
  def start_prefetching():
54
  prefetch_metadata()
55
 
 
56
  thread = Thread(target=start_prefetching)
57
  thread.daemon = True
58
  thread.start()
 
139
  else:
140
  return jsonify({'error': 'Metadata not found'}), 404
141
 
142
+ cached_url = f"/cached_films/{urllib.parse.quote(title)}"
143
  return jsonify({
144
  'metadata': metadata,
145
+ 'cached_url': cached_url
146
  })
147
 
148
  @app.route('/api/tv/<path:show_title>')
 
179
 
180
  return jsonify({'error': 'Metadata not found'}), 404
181
 
182
+ @app.route('/api/cache_film/<path:title>')
183
+ def cache_film(title):
 
 
 
 
184
  title = urllib.parse.unquote(title)
185
  film_file_path = get_film_file_path(title)
186
  if not film_file_path:
187
  return jsonify({'error': 'Film not found'}), 404
 
 
188
 
189
+ cached_file_path = os.path.join(CACHE_DIR, film_file_path)
190
+ if not os.path.exists(cached_file_path):
191
+ file_url = f"https://huggingface.co/{REPO}/resolve/main/{film_file_path}"
192
+ success = download_and_cache_file(file_url, TOKEN, cached_file_path, proxies=get_system_proxies())
193
+ if not success:
194
+ return jsonify({'error': 'Failed to cache film'}), 500
195
+
196
+ return jsonify({'success': True})
197
 
198
+ @app.route('/film/<path:title>')
199
+ def film_details(title):
200
+ return render_template('film_details_page.html', title=title)
 
 
 
201
 
202
+ @app.route('/cached_films/<path:title>')
203
+ def serve_cached_film(title):
204
+ cached_file_path = os.path.join(CACHE_DIR, urllib.parse.unquote(title))
205
+ if not os.path.exists(cached_file_path):
206
+ return jsonify({'error': 'Film not cached'}), 404
207
 
208
  def generate():
209
  with open(cached_file_path, 'rb') as f:
templates/film_details_page.html CHANGED
@@ -122,7 +122,7 @@
122
  <p id="film-overview">Film overview goes here...</p>
123
  <div class="genres" id="film-genres"></div>
124
  <div class="metadata-container" id="film-metadata"></div>
125
- <a href="#" class="play-button" id="play-button">Play</a>
126
  </div>
127
  </div>
128
  <script>
@@ -172,7 +172,22 @@
172
  metadataContainer.appendChild(createMetadataElement('Release Date', metadata.first_air_time));
173
 
174
  const playButton = document.getElementById('play-button');
175
- playButton.href = `/stream/${encodeURIComponent(title)}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  }
177
 
178
  const urlParams = new URLSearchParams(window.location.search);
 
122
  <p id="film-overview">Film overview goes here...</p>
123
  <div class="genres" id="film-genres"></div>
124
  <div class="metadata-container" id="film-metadata"></div>
125
+ <a href="#" class="play-button" id="play-button" onclick="playFilm()">Play</a>
126
  </div>
127
  </div>
128
  <script>
 
172
  metadataContainer.appendChild(createMetadataElement('Release Date', metadata.first_air_time));
173
 
174
  const playButton = document.getElementById('play-button');
175
+ playButton.href = `#`; // Will be handled by JavaScript
176
+ }
177
+
178
+ async function playFilm() {
179
+ const title = "{{ title }}";
180
+ try {
181
+ const response = await fetch(`/api/cache_film/${encodeURIComponent(title)}`);
182
+ const data = await response.json();
183
+ if (data.success) {
184
+ window.location.href = `/film_player/${encodeURIComponent(title)}`;
185
+ } else {
186
+ alert('Error caching film: ' + data.error);
187
+ }
188
+ } catch (error) {
189
+ alert('Error: ' + error.message);
190
+ }
191
  }
192
 
193
  const urlParams = new URLSearchParams(window.location.search);
templates/film_player.html CHANGED
@@ -3,39 +3,13 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Film Player</title>
7
- <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- margin: 0;
11
- padding: 0;
12
- display: flex;
13
- justify-content: center;
14
- align-items: center;
15
- height: 100vh;
16
- background-color: #f0f0f0;
17
- }
18
- .video-container {
19
- position: relative;
20
- width: 80%;
21
- max-width: 1200px;
22
- background: #000;
23
- border-radius: 8px;
24
- overflow: hidden;
25
- }
26
- video {
27
- width: 100%;
28
- height: auto;
29
- display: block;
30
- }
31
- </style>
32
  </head>
33
  <body>
34
- <div class="video-container">
35
- <video controls>
36
- <source src="{{ url_for('stream_film', title=title) }}" type="video/mp4">
37
- Your browser does not support the video tag.
38
- </video>
39
- </div>
40
  </body>
41
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>{{ title }}</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  </head>
8
  <body>
9
+ <h1>{{ title }}</h1>
10
+ <video controls width="100%" height="auto">
11
+ <source src="{{ cached_url }}" type="video/mp4">
12
+ Your browser does not support the video tag.
13
+ </video>
 
14
  </body>
15
  </html>