|
|
@ -243,6 +243,7 @@ class MaveRSSImporter: |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
created_podcasts_count = len(new_podcasts_to_create) |
|
|
created_podcasts_count = len(new_podcasts_to_create) |
|
|
|
|
|
created_guids_set = {p.rss_guid for p in new_podcasts_to_create} |
|
|
if new_podcasts_to_create: |
|
|
if new_podcasts_to_create: |
|
|
Podcast.objects.bulk_create(new_podcasts_to_create, batch_size=200) |
|
|
Podcast.objects.bulk_create(new_podcasts_to_create, batch_size=200) |
|
|
# Re-fetch the newly created podcasts to get their DB ids |
|
|
# Re-fetch the newly created podcasts to get their DB ids |
|
|
@ -254,6 +255,7 @@ class MaveRSSImporter: |
|
|
|
|
|
|
|
|
# Now process each season and link to its corresponding PodcastPlaylist |
|
|
# Now process each season and link to its corresponding PodcastPlaylist |
|
|
synced_playlists_info = [] |
|
|
synced_playlists_info = [] |
|
|
|
|
|
added_episodes_list: List[Dict[str, Any]] = [] |
|
|
target_playlist = playlist |
|
|
target_playlist = playlist |
|
|
|
|
|
|
|
|
# Sort seasons: 1, 2, 3... (None at end) |
|
|
# Sort seasons: 1, 2, 3... (None at end) |
|
|
@ -354,6 +356,20 @@ class MaveRSSImporter: |
|
|
if items_to_create: |
|
|
if items_to_create: |
|
|
PlaylistItem.objects.bulk_create(items_to_create, batch_size=200) |
|
|
PlaylistItem.objects.bulk_create(items_to_create, batch_size=200) |
|
|
|
|
|
|
|
|
|
|
|
newly_linked_pids = {it.podcast_id for it in items_to_create} |
|
|
|
|
|
for it in season_items: |
|
|
|
|
|
p_id = existing_guid_map.get(it["guid"]) |
|
|
|
|
|
if p_id and (it["guid"] in created_guids_set or p_id in newly_linked_pids): |
|
|
|
|
|
added_episodes_list.append({ |
|
|
|
|
|
"id": p_id, |
|
|
|
|
|
"title": it["title"], |
|
|
|
|
|
"season_number": s_num, |
|
|
|
|
|
"episode_number": it["episode_num"], |
|
|
|
|
|
"playlist_id": season_pl.id, |
|
|
|
|
|
"playlist_title": season_pl.title, |
|
|
|
|
|
"audio_time": str(it["audio_time"]) if it["audio_time"] else None, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
# Inherit categories from playlist to podcasts if any |
|
|
# Inherit categories from playlist to podcasts if any |
|
|
playlist_categories = list(season_pl.categories.all()) |
|
|
playlist_categories = list(season_pl.categories.all()) |
|
|
if playlist_categories: |
|
|
if playlist_categories: |
|
|
@ -389,6 +405,16 @@ class MaveRSSImporter: |
|
|
else (f"{len(synced_playlists_info)} Playlists Synced" if len(synced_playlists_info) > 1 else (synced_playlists_info[0]["title"] if synced_playlists_info else "")) |
|
|
else (f"{len(synced_playlists_info)} Playlists Synced" if len(synced_playlists_info) > 1 else (synced_playlists_info[0]["title"] if synced_playlists_info else "")) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
created_playlists = [ |
|
|
|
|
|
{ |
|
|
|
|
|
"id": p["id"], |
|
|
|
|
|
"title": p["title"], |
|
|
|
|
|
"season_number": p["season_number"], |
|
|
|
|
|
"episodes_count": p["episodes_count"], |
|
|
|
|
|
} |
|
|
|
|
|
for p in synced_playlists_info if p.get("is_new") |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
result = { |
|
|
result = { |
|
|
"status": "success", |
|
|
"status": "success", |
|
|
"playlist_id": target_playlist.id if target_playlist else (synced_playlists_info[0]["id"] if synced_playlists_info else None), |
|
|
"playlist_id": target_playlist.id if target_playlist else (synced_playlists_info[0]["id"] if synced_playlists_info else None), |
|
|
@ -396,6 +422,8 @@ class MaveRSSImporter: |
|
|
"total_feed_items": total_items_in_feed, |
|
|
"total_feed_items": total_items_in_feed, |
|
|
"created": created_podcasts_count, |
|
|
"created": created_podcasts_count, |
|
|
"skipped": skipped_count, |
|
|
"skipped": skipped_count, |
|
|
|
|
|
"created_playlists": created_playlists, |
|
|
|
|
|
"created_episodes": added_episodes_list, |
|
|
"playlists": synced_playlists_info, |
|
|
"playlists": synced_playlists_info, |
|
|
"synced_at": timezone.now().isoformat(), |
|
|
"synced_at": timezone.now().isoformat(), |
|
|
} |
|
|
} |
|
|
|