Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Aug 18, 2024
1 parent 74d9fdf commit 1ccb93e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
4 changes: 3 additions & 1 deletion movie_collection_lib/src/imdb_episodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ impl ImdbEpisodes {

/// # Errors
/// Returns error if db query fails
pub async fn get_episodes_not_recorded_in_trakt(pool: &PgPool) -> Result<impl Stream<Item = Result<Self, PqError>>, Error> {
pub async fn get_episodes_not_recorded_in_trakt(
pool: &PgPool,
) -> Result<impl Stream<Item = Result<Self, PqError>>, Error> {
let query = query!(
r#"
SELECT ie.show, ir.title, ie.season, ie.episode, ie.airdate,
Expand Down
12 changes: 10 additions & 2 deletions movie_collection_lib/src/movie_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,22 @@ impl MovieCollection {
let conn = self.pool.get().await?;
let results: Vec<IndexPath> = query.fetch(&conn).await?;

for IndexPath {idx, path} in results {
for IndexPath { idx, path } in results {
let file_stem = Path::new(&path)
.file_stem()
.ok_or_else(|| format_err!("No file stem"))?
.to_string_lossy();
let (show, season, episode) = parse_file_stem(&file_stem);
let rating = ImdbRatings::get_show_by_link(&show, &self.pool).await?;
let episodes: Vec<ImdbEpisodes> = ImdbEpisodes::get_episodes_by_show_season_episode(&show, Some(season), Some(episode), &self.pool).await?.try_collect().await?;
let episodes: Vec<ImdbEpisodes> = ImdbEpisodes::get_episodes_by_show_season_episode(
&show,
Some(season),
Some(episode),
&self.pool,
)
.await?
.try_collect()
.await?;
let episode = episodes.first();
if let Some(rating) = &rating {
let query = query!(
Expand Down
10 changes: 8 additions & 2 deletions movie_collection_lib/src/plex_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,10 @@ mod tests {
use futures::TryStreamExt;
use stdout_channel::StdoutChannel;

use crate::{config::Config, imdb_episodes::ImdbEpisodes, movie_collection::MovieCollection, pgpool::PgPool, plex_events::PlexEvent};
use crate::{
config::Config, imdb_episodes::ImdbEpisodes, movie_collection::MovieCollection,
pgpool::PgPool, plex_events::PlexEvent,
};

use super::PlexMetadata;

Expand Down Expand Up @@ -1115,7 +1118,10 @@ mod tests {
let stdout = StdoutChannel::new();
let mc = MovieCollection::new(&config, &pool, &stdout);
mc.fix_collection_episode_id().await?;
let episodes: Vec<_> = ImdbEpisodes::get_episodes_not_recorded_in_trakt(&pool).await?.try_collect().await?;
let episodes: Vec<_> = ImdbEpisodes::get_episodes_not_recorded_in_trakt(&pool)
.await?
.try_collect()
.await?;
println!("{}", episodes.len());
assert!(false);
Ok(())
Expand Down
28 changes: 25 additions & 3 deletions src/trakt_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ use stdout_channel::StdoutChannel;
use tokio::time::{sleep, Duration};

use movie_collection_lib::{
config::Config, imdb_episodes::ImdbEpisodes, movie_collection::MovieCollection, pgpool::PgPool, plex_events::PlexMetadata, trakt_connection::TraktConnection, trakt_utils::{sync_trakt_with_db, trakt_app_parse, TraktActions, TraktCommands}
config::Config,
imdb_episodes::ImdbEpisodes,
movie_collection::MovieCollection,
pgpool::PgPool,
plex_events::PlexMetadata,
trakt_connection::TraktConnection,
trakt_utils::{sync_trakt_with_db, trakt_app_parse, TraktActions, TraktCommands},
};

#[allow(clippy::unnecessary_wraps)]
Expand Down Expand Up @@ -67,12 +73,28 @@ async fn trakt_app() -> Result<(), Error> {
sync_trakt_with_db(&trakt, &mc).await?;
mc.clear_plex_filename_bad_collection_id().await?;
mc.fix_plex_filename_collection_id().await?;
let episodes: Vec<_> = ImdbEpisodes::get_episodes_not_recorded_in_trakt(&pool).await?.try_collect().await?;
let episodes: Vec<_> = ImdbEpisodes::get_episodes_not_recorded_in_trakt(&pool)
.await?
.try_collect()
.await?;
for episode in episodes {
println!("episode {episode}");
let trakt_command = TraktCommands::Watched;
let trakt_action = TraktActions::Add;
match trakt_app_parse(&config, &trakt, &trakt_command, trakt_action, Some(episode.show.as_str()), None, episode.season, &[episode.episode], &stdout, &pool).await {
match trakt_app_parse(
&config,
&trakt,
&trakt_command,
trakt_action,
Some(episode.show.as_str()),
None,
episode.season,
&[episode.episode],
&stdout,
&pool,
)
.await
{
Ok(()) => println!("success"),
Err(e) => println!("failure {e:?}"),
}
Expand Down

0 comments on commit 1ccb93e

Please sign in to comment.