Skip to content

Commit

Permalink
fix(backend): handle case when plex directory is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Feb 1, 2025
1 parent 5dcec14 commit 654c3f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/models/external/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub mod plex {
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct PlexMetadata {
pub metadata: Vec<PlexMetadataItem>,
pub metadata: Option<Vec<PlexMetadataItem>>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
18 changes: 15 additions & 3 deletions crates/services/importer/src/plex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ pub async fn import(input: DeployUrlAndKeyImportInput) -> Result<ImportResult> {
.await?
.json::<plex_models::PlexMediaResponse<plex_models::PlexMetadata>>()
.await?;
let total = items.media_container.metadata.len();
for (idx, item) in items.media_container.metadata.into_iter().enumerate() {
let Some(metadata) = items.media_container.metadata else {
failed_items.push(ImportFailedItem {
lot: Some(lot),
step: ImportFailStep::ItemDetailsFromSource,
identifier: format!("{} ({}) - {}", dir.title, lot, dir.key),
error: Some("No metadata found".to_string()),
});
continue;
};
let total = metadata.len();
for (idx, item) in metadata.into_iter().enumerate() {
let Some(_lv) = item.last_viewed_at else {
continue;
};
Expand Down Expand Up @@ -102,7 +111,10 @@ pub async fn import(input: DeployUrlAndKeyImportInput) -> Result<ImportResult> {
identifier: tmdb_id.to_string(),
..Default::default()
};
for leaf in leaves.media_container.metadata {
let Some(leafs) = leaves.media_container.metadata else {
continue;
};
for leaf in leafs {
if leaf.last_viewed_at.is_some() {
item.seen_history.push(ImportOrExportMetadataItemSeen {
show_episode_number: leaf.index,
Expand Down
5 changes: 4 additions & 1 deletion crates/services/integration/src/yank/plex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub async fn sync_to_owned_collection(base_url: String, token: String) -> Result
.await?
.json::<plex_models::PlexMediaResponse<plex_models::PlexMetadata>>()
.await?;
for (idx, item) in items.media_container.metadata.into_iter().enumerate() {
let Some(metadata) = items.media_container.metadata else {
continue;
};
for (idx, item) in metadata.into_iter().enumerate() {
ryot_log!(debug, "Processing item {}", idx + 1);
let gu_ids = item.guid.unwrap_or_default();
let Some(tmdb_id) = gu_ids
Expand Down

0 comments on commit 654c3f5

Please sign in to comment.