Inheritance: INotifyPropertyChanged
Beispiel #1
0
 public FileInfoFetchedArgs(AnimeEntry anime, EpisodeEntry episode, FileEntry file)
 {
     Anime = anime;
     Episode = episode;
     File = file;
 }
Beispiel #2
0
        public void File(FileEntry entry)
        {
            Action fileInfo = new Action(delegate
            {
                APIResponse response = Execute(String.Format("FILE fid={0}&fmask=78006A28B0&amask=F0E0F0C0", entry.fid));

                if (response.Code == RETURN_CODE.FILE)
                    ParseFileData(entry, response.Message);
            });

            PrioritizedCommand(fileInfo);
        }
Beispiel #3
0
        private bool SetFileLocation(FileEntry entry)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "Video Files|" + String.Join(";", allowedVideoFiles) + "|All Files|*.*";
            dlg.Title = String.Format("Browsing for {0} Episode {1}", m_myList.SelectAnimeFromFile(entry.fid).title, entry.epno);

            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                entry.path = dlg.FileName;
                MylistTreeListView.Refresh();

                return true;
            }

            return false;
        }
Beispiel #4
0
        public static MylistEntry FromFile(FileEntry entry)
        {
            MylistEntry m_entry = new MylistEntry();
            TimeSpan length = TimeSpan.FromSeconds(entry.length);

            m_entry.OriginalEntry = entry;
            m_entry.ID = entry.fid;

            string fileInfo = String.Empty;

            if (!string.IsNullOrEmpty(entry.vres) || !string.IsNullOrEmpty(entry.source) ||
                !string.IsNullOrEmpty(entry.vcodec) || !string.IsNullOrEmpty(entry.acodec))
                fileInfo = String.Format(" ({0} {1} {2} {3})", entry.vres, entry.source, entry.vcodec, "- " + entry.acodec);

            if (!entry.generic)
                m_entry.Col0 = String.Format("[{0}]{1}", entry.Group.group_abbr, fileInfo.Replace("  ", " "));
            else
                m_entry.Col0 = "generic file";

            if (entry.watcheddate != null)
                m_entry.Col2 = String.Format("{0} {1}", entry.watcheddate.ToDateTime().ToShortDateString(),
                                                        entry.watcheddate.ToDateTime().ToShortTimeString());
            m_entry.Col4 = length.ToFormattedLength();
            m_entry.Col5 = entry.size.ToFormattedBytes();

            return m_entry;
        }
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            List<AnimeEntry> m_aList = new List<AnimeEntry>();

            double totalProcessedFiles = 0;
            double totalFiles = int.Parse(new XPathDocument(xmlPath).CreateNavigator().Evaluate("count(//file)").ToString()) * 2;

            using (XmlReader reader = XmlReader.Create(xmlPath))
            {
                reader.ReadToFollowing("mylist");
                if (reader["template"] != "mini")
                {
                    Dispatcher.Invoke(new Action(delegate
                    {
                        MessageBox.Show("Please ensure you selected a mylist export file that used the xml-mini template.",
                            "Invalid xml template!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }));

                    xmlWorker.CancelAsync();
                    return;
                }

                // <anime>
                while (reader.ReadToFollowing("anime"))
                {
                    while (closePending) Thread.Sleep(500);

                    AnimeEntry entry = new AnimeEntry();

                    entry.aid = int.Parse(reader["aid"]);
                    entry.type = reader["type"];
                    entry.year = reader["year"];

                    // <titles>
                    reader.ReadToFollowing("default");
                    entry.romaji = reader.ReadElementContentAsString();
                    Dispatcher.BeginInvoke(new Action(delegate { importFilePath.Text = String.Format("Reading: {0}", entry.title); }));

                    reader.ReadToFollowing("nihongo");
                    entry.nihongo = reader.ReadElementContentAsString().FormatNullable();

                    reader.ReadToFollowing("english");
                    entry.english = reader.ReadElementContentAsString().FormatNullable();
                    // </titles>

                    // <episodes>
                    if (!reader.ReadToFollowing("episodes"))
                        goto Finish;

                    entry.eps_total = int.Parse(reader["total"]);

                    XmlReader episodesReader = reader.ReadSubtree();
                    // <episode>
                    while (episodesReader.ReadToFollowing("episode"))
                    {
                        while (closePending) Thread.Sleep(500);

                        EpisodeEntry episode = new EpisodeEntry();

                        episode.eid = int.Parse(episodesReader["eid"]);

                        episode.airdate = episodesReader["aired"] == "-" ? null :
                                          UnixTimestamp.FromDateTime(DateTime.Parse(episodesReader["aired"],
                                          System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")));
                        episode.watched = Convert.ToBoolean(int.Parse(episodesReader["watched"]));

                        if (Regex.IsMatch(episodesReader["epno"].Substring(0, 1), @"\D"))
                            episode.spl_epno = episodesReader["epno"];
                        else
                            episode.epno = int.Parse(episodesReader["epno"]);

                        // <titles>
                        episodesReader.ReadToDescendant("english");
                        episode.english = episodesReader.ReadElementContentAsString();

                        episodesReader.ReadToFollowing("nihongo");
                        episode.nihongo = episodesReader.ReadElementContentAsString().FormatNullable();

                        episodesReader.ReadToFollowing("romaji");
                        episode.romaji = episodesReader.ReadElementContentAsString().FormatNullable();
                        // </titles>

                        // <files>
                        if (!episodesReader.ReadToFollowing("files"))
                            goto Finish;

                        XmlReader filesReader = episodesReader.ReadSubtree();
                        // <file>
                        while (filesReader.ReadToFollowing("file"))
                        {
                            while (closePending) Thread.Sleep(500);

                            FileEntry file = new FileEntry();

                            file.fid = int.Parse(filesReader["fid"]);
                            file.lid = int.Parse(filesReader["lid"]);
                            file.watcheddate = filesReader["watched"] == "-" ? null :
                                               UnixTimestamp.FromDateTime(DateTime.Parse(episodesReader["watched"],
                                               System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")));
                            file.watched = file.watcheddate != null;
                            file.generic = episodesReader["generic"] != null;

                            if (!file.generic) // generic entries do not have this information
                            {
                                int gid = 0;

                                if (filesReader["gid"] != null)
                                    gid = int.Parse(filesReader["gid"]);

                                file.ed2k = filesReader["ed2k"];
                                file.length = double.Parse(filesReader["length"]);
                                file.size = double.Parse(filesReader["size"]);
                                file.source = filesReader["source"].FormatNullable();
                                file.acodec = ExtensionMethods.FormatAudioCodec(filesReader["acodec"].FormatNullable());
                                file.vcodec = ExtensionMethods.FormatVideoCodec(filesReader["vcodec"].FormatNullable());
                                file.vres = filesReader["vres"].FormatNullable();

                                if (gid != 0)
                                {
                                    // <group_name>
                                    filesReader.ReadToFollowing("group_name");
                                    string group_name = filesReader.ReadElementContentAsString();
                                    // </group_name>

                                    // <group_abbr>
                                    filesReader.ReadToFollowing("group_abbr");
                                    string group_abbr = filesReader.ReadElementContentAsString();
                                    // </group_abbr>

                                    file.Group = new GroupEntry
                                    {
                                        gid = gid,
                                        group_name = group_name,
                                        group_abbr = group_abbr
                                    };
                                }
                            }

                            episode.Files.Add(file);
                            importProgressBar.Dispatcher.BeginInvoke(new Action<double, double>((total, processed) =>
                            {
                                importProgressBar.Value = Math.Ceiling(processed / total * 100);
                            }), totalFiles, ++totalProcessedFiles);
                        // </file>
                        }
                        // </files>
                        filesReader.Close();
                        entry.Episodes.Add(episode);
                    // </episode>
                    }
                    // </episodes>
                    episodesReader.Close();

                Finish:
                    m_aList.Add(entry);

                // </anime>
                }
             // </mylist>
            }

            m_myList.OnEntryInserted += (aTitle) =>
            {
                importProgressBar.Dispatcher.BeginInvoke(new Action(delegate
                {
                    importFilePath.Text = String.Format("Writing: {0}", aTitle);
                    importProgressBar.Value = Math.Ceiling(++totalProcessedFiles / totalFiles * 100);
                }));
            };

            m_myList.InsertFromImport(m_aList);
        }