Spaces:
Sleeping
Sleeping
Update providers/archive_provider.py
Browse files
providers/archive_provider.py
CHANGED
|
@@ -46,7 +46,6 @@ def search(query: str, has_transcript: bool = False):
|
|
| 46 |
logging.error(f"An error occurred during search in archive_provider: {e}")
|
| 47 |
return {"error": "Failed to perform search."}
|
| 48 |
|
| 49 |
-
|
| 50 |
def get_details(identifier: str):
|
| 51 |
"""
|
| 52 |
Retrieves key details for a single item from the Internet Archive, excluding the transcript.
|
|
@@ -56,20 +55,25 @@ def get_details(identifier: str):
|
|
| 56 |
return item
|
| 57 |
|
| 58 |
try:
|
| 59 |
-
# --- Find Thumbnail
|
| 60 |
thumbnail_file = next((f for f in item.files if f.get('name') == '__ia_thumb.jpg'), None) or \
|
| 61 |
next((f for f in item.files if f.get('format') == 'Item Tile'), None) or \
|
| 62 |
next((f for f in item.files if f.get('format') == 'Thumbnail'), None)
|
| 63 |
thumbnail_url = f"https://archive.org/download/{identifier}/{thumbnail_file['name']}" if thumbnail_file else None
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
video_file = next((f for f in item.files if f.get('name', '').lower().endswith('.mp4')), None)
|
| 69 |
-
|
| 70 |
-
# 2. المحاولة الثانية:
|
| 71 |
if not video_file:
|
| 72 |
video_file = next((f for f in item.files if 'MPEG4' in f.get('format', '') or 'h.264' in f.get('format', '').lower()), None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# --- Structure the final response ---
|
| 75 |
item_metadata = item.metadata
|
|
@@ -89,3 +93,8 @@ def get_details(identifier: str):
|
|
| 89 |
except Exception as e:
|
| 90 |
logging.error(f"An error occurred getting details in archive_provider for {identifier}: {e}")
|
| 91 |
return {"error": f"Failed to retrieve details for item {identifier}."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
logging.error(f"An error occurred during search in archive_provider: {e}")
|
| 47 |
return {"error": "Failed to perform search."}
|
| 48 |
|
|
|
|
| 49 |
def get_details(identifier: str):
|
| 50 |
"""
|
| 51 |
Retrieves key details for a single item from the Internet Archive, excluding the transcript.
|
|
|
|
| 55 |
return item
|
| 56 |
|
| 57 |
try:
|
| 58 |
+
# --- Find Thumbnail ---
|
| 59 |
thumbnail_file = next((f for f in item.files if f.get('name') == '__ia_thumb.jpg'), None) or \
|
| 60 |
next((f for f in item.files if f.get('format') == 'Item Tile'), None) or \
|
| 61 |
next((f for f in item.files if f.get('format') == 'Thumbnail'), None)
|
| 62 |
thumbnail_url = f"https://archive.org/download/{identifier}/{thumbnail_file['name']}" if thumbnail_file else None
|
| 63 |
|
| 64 |
+
# --- Find Video File ---
|
| 65 |
+
# 1. المحاولة الأولى: البحث بالامتداد .mp4
|
|
|
|
| 66 |
video_file = next((f for f in item.files if f.get('name', '').lower().endswith('.mp4')), None)
|
| 67 |
+
|
| 68 |
+
# 2. المحاولة الثانية: البحث في الـ Format
|
| 69 |
if not video_file:
|
| 70 |
video_file = next((f for f in item.files if 'MPEG4' in f.get('format', '') or 'h.264' in f.get('format', '').lower()), None)
|
| 71 |
+
|
| 72 |
+
video_url = f"https://archive.org/download/{identifier}/{video_file['name']}" if video_file else None
|
| 73 |
+
|
| 74 |
+
# --- Find Audio File ---
|
| 75 |
+
audio_file = next((f for f in item.files if f.get('format') == 'VBR MP3'), None)
|
| 76 |
+
audio_url = f"https://archive.org/download/{identifier}/{audio_file['name']}" if audio_file else None
|
| 77 |
|
| 78 |
# --- Structure the final response ---
|
| 79 |
item_metadata = item.metadata
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
logging.error(f"An error occurred getting details in archive_provider for {identifier}: {e}")
|
| 95 |
return {"error": f"Failed to retrieve details for item {identifier}."}
|
| 96 |
+
return response
|
| 97 |
+
|
| 98 |
+
except Exception as e:
|
| 99 |
+
logging.error(f"An error occurred getting details in archive_provider for {identifier}: {e}")
|
| 100 |
+
return {"error": f"Failed to retrieve details for item {identifier}."}
|