Spaces:
Paused
Paused
Commit
·
d451d18
1
Parent(s):
3f0fe86
fix app.py
Browse files
app.py
CHANGED
@@ -33,23 +33,23 @@ def prefetch_metadata():
|
|
33 |
for sub_item in item['contents']:
|
34 |
original_title = sub_item['path'].split('/')[-1]
|
35 |
media_type = 'series' if item['path'].startswith('tv') else 'movie'
|
36 |
-
title = original_title
|
37 |
-
year = None
|
38 |
-
|
39 |
-
match = re.search(r'\((\d{4})\)', original_title)
|
40 |
-
if match:
|
41 |
-
year_str = match.group(1)
|
42 |
-
if year_str.isdigit() and len(year_str) == 4:
|
43 |
-
title = original_title[:match.start()].strip()
|
44 |
-
year = int(year_str)
|
45 |
-
else:
|
46 |
-
parts = original_title.rsplit(' ', 1)
|
47 |
-
if len(parts) > 1 and parts[-1].isdigit() and len(parts[-1]) == 4:
|
48 |
-
title = parts[0].strip()
|
49 |
-
year = int(parts[-1])
|
50 |
|
51 |
fetch_and_cache_json(original_title, title, media_type, year)
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def get_film_file_path(title):
|
54 |
decoded_title = urllib.parse.unquote(title)
|
55 |
normalized_title = decoded_title.split(' (')[0].strip()
|
@@ -74,13 +74,10 @@ def get_tv_show_seasons(title):
|
|
74 |
if sub_item['type'] == 'directory' and title in sub_item['path']:
|
75 |
for season in sub_item['contents']:
|
76 |
if season['type'] == 'directory':
|
77 |
-
episodes = [
|
78 |
-
|
79 |
-
if episode['type'] == 'file'
|
80 |
-
|
81 |
-
"title": episode['path'].split('/')[-1],
|
82 |
-
"path": episode['path']
|
83 |
-
})
|
84 |
seasons.append({
|
85 |
"season": season['path'].split('/')[-1],
|
86 |
"episodes": episodes
|
@@ -102,8 +99,11 @@ def generate(file_url):
|
|
102 |
|
103 |
# Set up HLS streaming
|
104 |
token = TOKEN
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
107 |
|
108 |
thread = Thread(target=start_prefetching)
|
109 |
thread.daemon = True
|
@@ -211,7 +211,6 @@ def stream_video():
|
|
211 |
stream_id = generate(file_url)
|
212 |
|
213 |
if stream_id:
|
214 |
-
# Return the UUID for the client to use
|
215 |
return jsonify({'stream_id': stream_id})
|
216 |
|
217 |
return "Streaming error", 500
|
|
|
33 |
for sub_item in item['contents']:
|
34 |
original_title = sub_item['path'].split('/')[-1]
|
35 |
media_type = 'series' if item['path'].startswith('tv') else 'movie'
|
36 |
+
title, year = extract_title_and_year(original_title)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
fetch_and_cache_json(original_title, title, media_type, year)
|
39 |
|
40 |
+
def extract_title_and_year(original_title):
|
41 |
+
match = re.search(r'\((\d{4})\)', original_title)
|
42 |
+
if match:
|
43 |
+
year_str = match.group(1)
|
44 |
+
if year_str.isdigit() and len(year_str) == 4:
|
45 |
+
title = original_title[:match.start()].strip()
|
46 |
+
return title, int(year_str)
|
47 |
+
else:
|
48 |
+
parts = original_title.rsplit(' ', 1)
|
49 |
+
if len(parts) > 1 and parts[-1].isdigit() and len(parts[-1]) == 4:
|
50 |
+
return parts[0].strip(), int(parts[-1])
|
51 |
+
return original_title, None
|
52 |
+
|
53 |
def get_film_file_path(title):
|
54 |
decoded_title = urllib.parse.unquote(title)
|
55 |
normalized_title = decoded_title.split(' (')[0].strip()
|
|
|
74 |
if sub_item['type'] == 'directory' and title in sub_item['path']:
|
75 |
for season in sub_item['contents']:
|
76 |
if season['type'] == 'directory':
|
77 |
+
episodes = [
|
78 |
+
{"title": episode['path'].split('/')[-1], "path": episode['path']}
|
79 |
+
for episode in season['contents'] if episode['type'] == 'file'
|
80 |
+
]
|
|
|
|
|
|
|
81 |
seasons.append({
|
82 |
"season": season['path'].split('/')[-1],
|
83 |
"episodes": episodes
|
|
|
99 |
|
100 |
# Set up HLS streaming
|
101 |
token = TOKEN
|
102 |
+
output_path = ffmpeg_stream(file_url, token, output_dir=output_dir, stream_id=stream_id)
|
103 |
+
|
104 |
+
if output_path:
|
105 |
+
return stream_id
|
106 |
+
return None
|
107 |
|
108 |
thread = Thread(target=start_prefetching)
|
109 |
thread.daemon = True
|
|
|
211 |
stream_id = generate(file_url)
|
212 |
|
213 |
if stream_id:
|
|
|
214 |
return jsonify({'stream_id': stream_id})
|
215 |
|
216 |
return "Streaming error", 500
|
video.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import logging
|
3 |
import ffmpeg
|
4 |
-
import uuid
|
5 |
|
6 |
# Set up logging
|
7 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
@@ -37,15 +36,15 @@ def ffmpeg_stream(file_url, token, output_dir="tmp/cache/stream", stream_id=None
|
|
37 |
hls_segment_filename=segment_filename)
|
38 |
)
|
39 |
|
40 |
-
process.run()
|
41 |
|
42 |
# Check if the output file was created
|
43 |
if os.path.exists(output_path):
|
44 |
logging.info(f"HLS playlist created at {output_path}")
|
|
|
45 |
else:
|
46 |
logging.error(f"HLS playlist not created at {output_path}")
|
47 |
-
|
48 |
-
return output_path
|
49 |
|
50 |
except ffmpeg.Error as e:
|
51 |
error_message = e.stderr.decode('utf8') if e.stderr else str(e)
|
|
|
1 |
import os
|
2 |
import logging
|
3 |
import ffmpeg
|
|
|
4 |
|
5 |
# Set up logging
|
6 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
36 |
hls_segment_filename=segment_filename)
|
37 |
)
|
38 |
|
39 |
+
process.run(capture_stdout=True, capture_stderr=True)
|
40 |
|
41 |
# Check if the output file was created
|
42 |
if os.path.exists(output_path):
|
43 |
logging.info(f"HLS playlist created at {output_path}")
|
44 |
+
return output_path
|
45 |
else:
|
46 |
logging.error(f"HLS playlist not created at {output_path}")
|
47 |
+
return None
|
|
|
48 |
|
49 |
except ffmpeg.Error as e:
|
50 |
error_message = e.stderr.decode('utf8') if e.stderr else str(e)
|