Exemple #1
0
 public AnimeIndexer(AnimeLibrary existing)
 {
     InitializeComponent();
     if (existing != null)
     {
         textBox1.Text = existing.LibraryPath.FullName;
         OldLibrary    = existing;
     }
 }
Exemple #2
0
        private void indexLibraryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AnimeIndexer indexer = new AnimeIndexer(Library);

            indexer.ShowDialog();
            if (indexer.IsOK)
            {
                Library = indexer.Library;
                File.WriteAllText("library.json", Library.ExportToJson(true));
                ReloadUI();
            }
        }
Exemple #3
0
 private void Form1_Shown(object sender, EventArgs e)
 {
     if (File.Exists("library.json"))
     {
         string json = File.ReadAllText("library.json");
         Library = AnimeLibrary.ImportFromJson(json);
         ReloadUI();
     }
     else
     {
         MessageBox.Show("Welcome to AnimeLibraryInfo!\nThis program helps you sort your local anime library!\nTo start, go to File > Index library", "AnimeLibraryInfo");
     }
 }
Exemple #4
0
        private async void loadMALData()
        {
            MALManager manager = new MALManager(username, password);
            await manager.getAnimeList();

            currentlyWatchingModel = new Model(currentlyWatchingList);
            planToWatchModel       = new Model(planToWatchList);
            onHoldModel            = new Model(onHoldList);
            droppedModel           = new Model(droppedList);
            completedModel         = new Model(completedList);
            loadAnimeList(AnimeLibrary.getCurrentlyWatching(), currentlyWatchingModel);
            loadAnimeList(AnimeLibrary.getPlanToWatch(), planToWatchModel);
            loadAnimeList(AnimeLibrary.getOnHold(), onHoldModel);
            loadAnimeList(AnimeLibrary.getDropped(), droppedModel);
            loadAnimeList(AnimeLibrary.getCompleted(), completedModel);
        }
Exemple #5
0
    public async Task getAnimeList()
    {
        String result = await GET("https://myanimelist.net/malappinfo.php?status=all&type=anime&u=" + username);

        //Parse XML
        //Read the XML file returned by MAL
        using (XmlReader reader = XmlReader.Create(new StringReader(result)))
        {
            //Root node is "myanimelist"
            reader.ReadStartElement("myanimelist");
            if (reader.Name != "myanimelist")
            {
                //First internal node is "myinfo"
                reader.ReadStartElement("myinfo");
                while (reader.Name != "myinfo")
                {
                    XElement el = (XElement)XNode.ReadFrom(reader);
                    //We don't do anything with the myinfo elements yet.
                }
                reader.ReadEndElement();
            }
            //Until it hits the end tag "/myanimelist", read each individual "anime" node and add an element for each.
            while (reader.Name != "myanimelist")
            {
                reader.ReadStartElement("anime");
                Anime tempAnime = new Anime();
                while (reader.Name != "anime")
                {
                    XElement el = (XElement)XNode.ReadFrom(reader);
                    if (el.Name == "series_title")
                    {
                        tempAnime.Title = el.Value;
                    }
                    if (el.Name == "series_image")
                    {
                        tempAnime.PosterLink = el.Value;
                    }
                    if (el.Name == "my_status")
                    {
                        if (el.Value == "1")
                        {
                            AnimeLibrary.addCurrentlyWatching(tempAnime);
                        }
                        else if (el.Value == "3")
                        {
                            AnimeLibrary.addOnHold(tempAnime);
                        }
                        else if (el.Value == "6")
                        {
                            AnimeLibrary.addPlanToWatch(tempAnime);
                        }
                        else if (el.Value == "4")
                        {
                            AnimeLibrary.addDropped(tempAnime);
                        }
                        else if (el.Value == "2")
                        {
                            AnimeLibrary.addCompleted(tempAnime);
                        }
                    }
                }
                reader.ReadEndElement();
            }
            reader.ReadEndElement();
        }
    }
Exemple #6
0
        void Index()
        {
            string path = textBox1.Text;

            if (!Directory.Exists(path))
            {
                MessageBox.Show("The specified directory does not exist");
                return;
            }
            try
            {
                Library = new AnimeLibrary(new DirectoryInfo(path), false);
                List <AnimeSeason> Seasons = new List <AnimeSeason>();
                foreach (DirectoryInfo d in Library.LibraryPath.ToDirectoryInfo().EnumerateDirectories())
                {
                    long size = 0;
                    List <AnimeEpisode> episodes = new List <AnimeEpisode>();
                    foreach (FileInfo i in d.EnumerateFiles())
                    {
                        listBox1.Invoke(new Log(() => { listBox1.Items.Add("Scanned " + i.FullName); listBox1.TopIndex = listBox1.Items.Count - 1; }));
                        if (i.Extension.Equals(".mp4") || i.Extension.Equals(".mkv")) //check if it's a video file
                        {
                            TagLib.File             file   = TagLib.File.Create(i.FullName);
                            TagLib.Mpeg.VideoHeader header = new TagLib.Mpeg.VideoHeader();
                            foreach (ICodec codec in file.Properties.Codecs)
                            {
                                if (codec is TagLib.Mpeg.VideoHeader)
                                {
                                    header = (TagLib.Mpeg.VideoHeader)codec;
                                }
                            }
                            SerializableFileInfo info = new SerializableFileInfo(i.FullName);
                            episodes.Add(new AnimeEpisode
                            {
                                EpisodePath = info,
                                EpisodeInfo = header
                            });
                            size += info.Length;
                        }
                    }
                    //order episodes by number
                    //this is tricky but not that hard to do
                    string[] remove = { "144p", "240p", "360p", "480p", "720p", "1080p", "1440p", "2160p", "mp4" };
                    SortedDictionary <int, AnimeEpisode> episodes2 = new SortedDictionary <int, AnimeEpisode>();
                    foreach (AnimeEpisode e in episodes)
                    {
                        string name = e.EpisodePath.Name;
                        foreach (string s in remove)
                        {
                            name = name.Replace(s, "");
                        }
                        episodes2.Add(int.Parse(String.Join("", name.Where(char.IsDigit))), e);
                    }
                    episodes.Clear();
                    episodes.AddRange(episodes2.Values);

                    Seasons.Add(new AnimeSeason()
                    {
                        Episodes   = episodes,
                        SeasonPath = new SerializableDirectoryInfo(d.FullName),
                        Size       = size
                    });
                    Library.LibrarySize += size;
                }

                //sort per series

                //get all names
                string[] names = new string[Seasons.Count];
                for (int i = 0; i < Seasons.Count; i++)
                {
                    names[i] = Seasons[i].SeasonPath.Name;
                }

                //remove "OVA" from all names because it can hurt consistency
                for (int i = 0; i < names.Length; i++)
                {
                    names[i].Replace(" OVA", ""); //remove with the space at the beginning
                }

                bool               done         = false;
                int                currentIndex = 0;
                List <string>      nameList     = new List <string>(names);
                List <AnimeSeason> seasons      = Seasons;
                while (!done)
                {
                    Tuple <AnimeSeries, int> current = GenerateTree(names[currentIndex], nameList.ToArray(), seasons);
                    nameList.RemoveAt(0);
                    seasons.RemoveAt(0);
                    currentIndex += current.Item2;
                    Library.Library.Add(current.Item1);
                    if (currentIndex >= names.Length)
                    {
                        done = true;
                    }
                }
                //remove empty animes
                List <AnimeSeries> nodesToRemove = new List <AnimeSeries>();
                foreach (AnimeSeries t in Library.Library)
                {
                    if (t.Seasons.Count == 0)
                    {
                        nodesToRemove.Add(t);
                    }
                }
                foreach (AnimeSeries t in nodesToRemove)
                {
                    Library.Library.Remove(t);
                }

                //mark episodes as completed
                if (OldLibrary != null)
                {
                    foreach (AnimeSeries series in OldLibrary.Library)
                    {
                        foreach (AnimeSeason season in series.Seasons)
                        {
                            foreach (AnimeEpisode e in season.Episodes)
                            {
                                for (int i = 0; i < Library.Library.Count; i++)
                                {
                                    for (int j = 0; j < Library.Library[i].Seasons.Count; j++)
                                    {
                                        for (int w = 0; w < Library.Library[i].Seasons[j].Episodes.Count; w++)
                                        {
                                            if (Library.Library[i].Seasons[j].Episodes[w].EpisodePath.FullName.Equals(e.EpisodePath.FullName))
                                            {
                                                AnimeEpisode ep = Library.Library[i].Seasons[j].Episodes[w];
                                                ep.Watched       = e.Watched;
                                                ep.EpisodeNumber = w + 1;
                                                Library.Library[i].Seasons[j].Episodes[w] = ep;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                IsOK = true;
                Invoke(new Log(() => { MessageBox.Show("Done indexing!", "AnimeLibraryInfo", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); }));
            }
            catch (Exception e)
            {
                MessageBox.Show("The folder structure isn't set up correctly.\nCan't index library.", "AnimeLibraryInfo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }