Spaces:
Paused
Paused
File size: 1,353 Bytes
da7bab3 d53de2e da7bab3 d53de2e da7bab3 d53de2e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import os
import json
CACHE_DIR = os.getenv("CACHE_DIR")
INDEX_FILE = os.getenv("INDEX_FILE")
def get_all_tv_shows(indexed_cache):
"""Get all TV shows from the indexed cache structure JSON file."""
tv_shows = {}
for directory in indexed_cache:
if directory['type'] == 'directory' and directory['path'] == 'tv':
for sub_directory in directory['contents']:
if sub_directory['type'] == 'directory':
show_title = sub_directory['path'].split('/')[-1]
tv_shows[show_title] = []
for season_directory in sub_directory['contents']:
if season_directory['type'] == 'directory':
season = season_directory['path'].split('/')[-1]
for episode in season_directory['contents']:
if episode['type'] == 'file':
tv_shows[show_title].append({
"season": season,
"episode": episode['path'].split('/')[-1],
"path": episode['path']
})
return tv_shows
with open(INDEX_FILE, 'r') as f:
file_structure = json.load(f)
print(get_all_tv_shows(file_structure)) |