aliSaac510 commited on
Commit
d912220
·
verified ·
1 Parent(s): 74daece

Update providers/archive_provider.py

Browse files
Files changed (1) hide show
  1. providers/archive_provider.py +16 -7
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, Video, and Audio Files ---
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
- video_file = next((f for f in item.files if 'MPEG4' in f.get('format', '')), None)
66
- video_url = f"https://archive.org/download/{identifier}/{video_file['name']}" if video_file else None
67
-
68
  video_file = next((f for f in item.files if f.get('name', '').lower().endswith('.mp4')), None)
69
-
70
- # 2. المحاولة الثانية: إذا لم نجد، نبحث في خانة الـ Format (يحل مشكلة القوائم والأرشيف)
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}."}