Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watch_history() returning empty Series struct #21

Open
arnoldsmithson opened this issue Jul 1, 2023 · 3 comments
Open

watch_history() returning empty Series struct #21

arnoldsmithson opened this issue Jul 1, 2023 · 3 comments

Comments

@arnoldsmithson
Copy link

arnoldsmithson commented Jul 1, 2023

Hello, I'm trying to use watch_history() in my Crunchyroll program and for some reason it's returning empty series structs between the episodes I want to retrieve. Here is my sample code and a sample output:

use crunchyroll_rs::{Crunchyroll, MediaCollection};
use crunchyroll_rs::common::StreamExt;
use anyhow::Result;
use crunchyroll_rs::list::WatchHistoryEntry;
use std::fs::File;
use std::io::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // log in to crunchyroll with your username and password
    let crunchyroll = Crunchyroll::builder()
        .login_with_credentials("", "")
        .await?;

    let mut file = File::create("foo.txt")?;

    let mut total = 0;
    let mut history = crunchyroll.watch_history();
    while let Some(item) = history.next().await {
        match item? {
            WatchHistoryEntry {id: entry, parent_id, parent_type, date_played, playhead, fully_watched, panel} => {
                total += 1;
                let anime_title: String;
                let format: String;
                match panel {
                    MediaCollection::Series(series) => {
                        format = String::from("Series");
                        anime_title = series.availability_notes;
                    }
                    MediaCollection::Season(season) => {
                        format = String::from("Season");
                        anime_title = season.title;
                    }
                    MediaCollection::Episode(episode) => {
                        format = String::from("Episode");
                        anime_title = episode.title;
                    }
                    MediaCollection::MovieListing(movie_list) => {
                        format = String::from("Movie Listing");
                        anime_title = movie_list.title;
                    }
                    MediaCollection::Movie(movie) => {
                        format = String::from("Movie");
                        anime_title = movie.title;
                    }
                    MediaCollection::MusicVideo(amv) => {
                        format = String::from("Anime Music Video");
                        anime_title = amv.title;
                    }
                    MediaCollection::Concert(conc) => {
                        format = String::from("Concert");
                        anime_title = conc.title;
                    }
                }
                let line = format!("Entry {}:Type: {} \tTitle of entry: {}\n",total, format, anime_title);
                file.write_all(&*line.into_bytes())?;
            }
        }
    }

    Ok(())
}

And part of my output:

Entry 2684:Type: Episode 	Title of entry: Proof of Evolution Synchro Monster
Entry 2685:Type: Episode 	Title of entry: A New Threat
Entry 2686:Type: Series 	Title of entry: 
Entry 2687:Type: Series 	Title of entry: 
Entry 2688:Type: Series 	Title of entry: 
Entry 2689:Type: Series 	Title of entry: 
Entry 2690:Type: Series 	Title of entry: 
Entry 2691:Type: Series 	Title of entry: 
Entry 2692:Type: Series 	Title of entry: 
Entry 2693:Type: Series 	Title of entry: 
Entry 2694:Type: Series 	Title of entry: 
Entry 2695:Type: Series 	Title of entry: 
Entry 2696:Type: Series 	Title of entry: 
Entry 2697:Type: Series 	Title of entry: 
Entry 2698:Type: Episode 	Title of entry: Reunion and Turnabout  —  2nd Trial
Entry 2699:Type: Episode 	Title of entry: To Our Future!

When checking with my watch history, the episodes split by these empty entries are in order. If I removed the empty entries, the watch history would be uninterrupted. But these Series entries don't make sense to me. I tried grabbing other information from them, but I couldn't see anything. Any help you can provide would be fantastic, as these empty entries are preventing me from grabbing the entirety of my watch history (it's grabbing all but 20 episodes).

@arnoldsmithson arnoldsmithson changed the title Question watch_history() returning empty Series struct Jul 1, 2023
@bytedream
Copy link
Member

This is strange, I can't reproduce this behavior with my account. Also the number of empty entries is odd to be a library bug, so I assume that it is an issue with Crunchyroll (maybe they are delivering non-existing entries if the watch history is so large?).

The problem that the 20 episodes are not pulled got fixed in release v0.4.0.

@arnoldsmithson
Copy link
Author

Thank you for fixing the other part of my issue! Honestly, that's all I needed. I can work around the empty listings myself. But if you want to test further, I'm happy to give you my credentials to reproduce the bug for debug purposes. I use a password generator for all my stuff so I could just change my Crunchyroll password again once you're done. Just let me know!

@Derro8
Copy link
Contributor

Derro8 commented Feb 17, 2024

This is might be the reason but sometimes watch history entries won't have a panel so you'll have to use crunchyroll.media_from_id to get it. Would probably be a good idea to make a getPanel function for that instead of making them check if the panel exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants