ChandimaPrabath commited on
Commit
97c0fdb
·
1 Parent(s): 5d51102

season metadata api update

Browse files
Files changed (3) hide show
  1. app.py +4 -4
  2. tvdb.py +1 -1
  3. tvdbApiClient.py +10 -10
app.py CHANGED
@@ -304,14 +304,14 @@ async def get_series_card_api(title: str):
304
  raise HTTPException(status_code=404, detail="Card not found")
305
 
306
 
307
- @app.get("/api/get/series/metadata/{series_id}/{season}")
308
- async def get_season_metadata_api(series_id: int, season: str):
309
- """Endpoint to get the TV show season metadata by id and season."""
310
  if not season:
311
  raise HTTPException(status_code=400, detail="Season must be provided and cannot be empty")
312
 
313
  # Convert series_id to string before joining the path
314
- json_cache_path = os.path.join(CACHE_DIR, "metadata", str(series_id), f"{season}.json")
315
  print(json_cache_path)
316
 
317
  if os.path.exists(json_cache_path):
 
304
  raise HTTPException(status_code=404, detail="Card not found")
305
 
306
 
307
+ @app.get("/api/get/series/metadata/{title}/{season}")
308
+ async def get_season_metadata_api(title: str, season: str):
309
+ """Endpoint to get the TV show season metadata by title and season."""
310
  if not season:
311
  raise HTTPException(status_code=400, detail="Season must be provided and cannot be empty")
312
 
313
  # Convert series_id to string before joining the path
314
+ json_cache_path = os.path.join(CACHE_DIR, "metadata", title, f"{season}.json")
315
  print(json_cache_path)
316
 
317
  if os.path.exists(json_cache_path):
tvdb.py CHANGED
@@ -117,7 +117,7 @@ async def fetch_and_cache_json(original_title, title, media_type, year=None):
117
  extended_url = f"{THETVDB_API_URL}/movies/{tvdb_id}/extended?meta=translations"
118
  elif media_type == 'series':
119
  extended_url = f"{THETVDB_API_URL}/series/{tvdb_id}/extended?meta=translations"
120
- await fetch_and_cache_seasons(tvdb_id)
121
  else:
122
  print(f"Unsupported media type: {media_type}")
123
  return
 
117
  extended_url = f"{THETVDB_API_URL}/movies/{tvdb_id}/extended?meta=translations"
118
  elif media_type == 'series':
119
  extended_url = f"{THETVDB_API_URL}/series/{tvdb_id}/extended?meta=translations"
120
+ await fetch_and_cache_seasons(tvdb_id, original_title)
121
  else:
122
  print(f"Unsupported media type: {media_type}")
123
  return
tvdbApiClient.py CHANGED
@@ -44,7 +44,7 @@ def filter_episode_data(episode):
44
 
45
 
46
 
47
- async def fetch_and_cache_seasons(series_id):
48
  """Fetch and cache episodes for a given series ID asynchronously."""
49
  series_info = get_series_info(series_id)
50
  if not series_info:
@@ -75,7 +75,7 @@ async def fetch_and_cache_seasons(series_id):
75
  all_seasons[season_key].append(filtered_data)
76
 
77
  # Create folder for the series
78
- series_folder = Path(SAVE_DIR) / str(series_id)
79
  series_folder.mkdir(parents=True, exist_ok=True)
80
 
81
  # Save episodes for each season in separate JSON files
@@ -84,12 +84,12 @@ async def fetch_and_cache_seasons(series_id):
84
  season_file = series_folder / f"{season_key}.json"
85
  await save_to_json(episodes_sorted, season_file)
86
 
87
- async def main(series_id):
88
- """Main function to fetch and cache episodes asynchronously."""
89
- await fetch_and_cache_seasons(series_id)
90
 
91
- if __name__ == "__main__":
92
- import asyncio
93
- # Replace with your series ID
94
- SERIES_ID = "315103"
95
- asyncio.run(main(SERIES_ID))
 
44
 
45
 
46
 
47
+ async def fetch_and_cache_seasons(series_id, original_title):
48
  """Fetch and cache episodes for a given series ID asynchronously."""
49
  series_info = get_series_info(series_id)
50
  if not series_info:
 
75
  all_seasons[season_key].append(filtered_data)
76
 
77
  # Create folder for the series
78
+ series_folder = Path(SAVE_DIR) / str(original_title)
79
  series_folder.mkdir(parents=True, exist_ok=True)
80
 
81
  # Save episodes for each season in separate JSON files
 
84
  season_file = series_folder / f"{season_key}.json"
85
  await save_to_json(episodes_sorted, season_file)
86
 
87
+ # async def main(series_id):
88
+ # """Main function to fetch and cache episodes asynchronously."""
89
+ # await fetch_and_cache_seasons(series_id)
90
 
91
+ # if __name__ == "__main__":
92
+ # import asyncio
93
+ # # Replace with your series ID
94
+ # SERIES_ID = "315103"
95
+ # asyncio.run(main(SERIES_ID))