Exemplo n.º 1
0
 /// <summary>
 /// Crée un animé à partir d'un épisode
 /// </summary>
 /// <param name="ep">Episode source</param>
 /// <param name="filter">Filtre à utiliser</param>
 public AnimeEpisode(TvShowEpisode ep, string filter)
 {
     _name = ep.Name;
     _filepath = ep.FilePath;
     _title = ep.Title;
     Filter = filter;
     FillFromFileName();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Applique le filtre de renommage
        /// </summary>
        /// <param name="source">Episode à exploiter</param>
        /// <param name="filter">Filtre à appliquer</param>
        /// <returns>Retourne la chaîne correspondant au filtre appliqué.</returns>
        public static string ApplyFilter(TvShowEpisode source, string filter)
        {
            try
            {
                Regex reg = new Regex("%%(.+)%%");
                string pattern = reg.Match(filter).Groups[1].Value;
                IList<string> se = new List<string>();
                if (pattern != string.Empty)
                    foreach (string number in source.Numbers)
                    {
                        Regex reg2 = new Regex(@"%s\{(\d)\}");
                        string pattern2 = reg2.Match(pattern).Groups[1].Value;
                        reg2 = new Regex(@"%s\{\d\}");
                        pattern2 = reg2.Replace(pattern, source._season.PadLeft(Convert.ToInt16(pattern2), '0'));
                        se.Add(pattern2.Replace("%e", number.PadLeft(2, '0')));
                    }

                reg = new Regex("%%.+%%");
                filter = reg.Replace(filter, string.Join("-", se.ToArray<string>()));

                reg = new Regex(@"\[\[(.+)\]\]");
                pattern = reg.Match(filter).Groups[1].Value;
                reg = new Regex(@"\[\[.+\]\]");
                filter = reg.Replace(filter, (source.IsHD ? pattern : string.Empty));

                reg = new Regex(@"%s\{(\d)\}");
                MatchCollection Matches = reg.Matches(filter);
                foreach (Match mat in Matches)
                    for (int i = 1; i < mat.Groups.Count; i++)
                    {
                        pattern = mat.Groups[i].Value;
                        reg = new Regex(@"%s\{" + pattern + @"\}");
                        filter = reg.Replace(filter, source._season.PadLeft(Convert.ToInt16(pattern), '0'));
                    }

                return filter.Replace("%S", source.TvShow).Replace("%t", source.TvShow.Replace(" ", ".")).Replace("%e", string.Join("-", source.Numbers.ToArray<string>())).Replace("%T", source.Title).Replace("%E", source.Extension).Replace("%1", source.FirstPartOfName).Replace("%2", source.SecondPartOfName).Replace("%N", source.Name).Replace("..", ".");
            }
            catch
            {
                return string.Empty;
            }
        }
Exemplo n.º 3
0
        public void WriteLog(TvShowEpisode.Statuses stat)
        {
            XmlDocument doc;
            XmlElement root;
            XmlNode node;
            bool newfile = true;

            try
            {
                doc = new XmlDocument();

                if (File.Exists(TvShowEpisode.LogFile))
                    try
                    {
                        doc.Load(TvShowEpisode.LogFile);
                        newfile = false;
                    }
                    catch { }
                else
                {
                    string dir = Path.GetDirectoryName(TvShowEpisode.LogFile);
                    if (!Directory.Exists(dir))
                        MyExtensions.CreateDirectory(dir);
                }
                if (newfile)
                {
                    doc.AppendChild(doc.CreateNode(XmlNodeType.XmlDeclaration, "utf-8", string.Empty));
                    root = doc.CreateElement("history");
                    doc.AppendChild(root);
                }
                else root = doc.DocumentElement;

                node = root.SelectSingleNode("//history/subtitle[@name=\"" + FileName.ToXpathString() + "\"]");
                XmlAttribute attr;
                if (node == null)
                {
                    node = doc.CreateElement("subtitle");
                    attr = doc.CreateAttribute("name");
                    attr.InnerText = FileName;
                    node.Attributes.Append(attr);
                    root.AppendChild(node);
                }
                else attr = node.Attributes["name"];

                XmlNode InnerNode = node.SelectSingleNode("date");
                if (InnerNode == null)
                {
                    InnerNode = doc.CreateElement("date");
                    node.AppendChild(InnerNode);
                }
                InnerNode.InnerText = DateTime.Now.ToString("yyyyMMddHHmmss");

                InnerNode = node.SelectSingleNode("status");
                if (InnerNode == null)
                {
                    InnerNode = doc.CreateElement("status");
                    node.AppendChild(InnerNode);
                }
                InnerNode.InnerText = stat.ToString();

                doc.Save(TvShowEpisode.LogFile);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Exemplo n.º 4
0
 private void FillEpisodePossible(TvShowEpisode ep, bool reload)
 {
     try
     {
         IList<DestinationFolder> dest = new List<DestinationFolder>();
         foreach (DestinationFolder folder in ListDest.Items)
             dest.Add(folder);
         ep.FillPossibleFiles(dest);
         if (reload)
         {
             ClistAvailableFiles.Items.Clear();
             foreach (PossibleFile file in ep.PossibleFiles)
             {
                 file.ToCopy = true;
                 ClistAvailableFiles.Items.Add(file, true);
             }
         }
     }
     catch (Exception ex)
     {
         WriteLog(ex);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Génère l'aperçu de la série
 /// </summary>
 private void GenerateApercuSerie()
 {
     try
     {
         TvShowEpisode ep = new TvShowEpisode(_serie_exemple, TboxSeriesFilter.Text);
         TBoxSeriesApercu.Text = ep.ApplyFilter();
     }
     catch { }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Remplit les différents champs d'édition de l'épisode.
        /// </summary>
        /// <param name="ep"></param>
        private void FillEpisodeData(TvShowEpisode ep)
        {
            try
            {
                if (ep != null)
                {
                    TboxTitle.Text = ep.Title;
                    TboxName.Text = ep.Name;
                    TboxSerie.Text = ep.TvShow;
                    TboxSerieMatch.Text = ep.TvShowMatch;
                    TboxSaison.Text = ep.Season;
                    ClistAvailableFiles.Items.Clear();
                    if (ep.PossibleFiles == null)
                        FillEpisodePossible(ep, false);

                    foreach (PossibleFile file in ep.PossibleFiles)
                        ClistAvailableFiles.Items.Add(file, file.ToCopy);
                    TboxNumbers.Text = string.Join("-", ep.Numbers.ToArray<string>());
                    SetEditableFields(true);
                    lancerToolStripMenuItem.Enabled = ButGo.Enabled = ClistToCopy.CheckedItems.Count > 0;
                    if (ep.GetType() == typeof(AnimeEpisode))
                    {
                        AnimeEpisode an = (AnimeEpisode)ep;
                        TboxID.Text = string.Join("-", an.ID.ToArray<string>());
                        TboxApercuCopy.Text = ep.ApplyFilter();
                        ButSearchAnime.Enabled = CboxFoldersAnime.Enabled = TboxID.Enabled = true;
                    }
                    else
                    {
                        TboxID.Text = string.Empty;
                        TboxApercuCopy.Text = ep.ApplyFilter();
                        ButSearchAnime.Enabled = CboxFoldersAnime.Enabled = TboxID.Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Coche les éléments de la liste des éléments disponibles à la copie en ignorant le statut passé en paramètre
 /// </summary>
 /// <param name="ignored">Statut à ignorer</param>
 private void CheckItems(TvShowEpisode.Statuses ignored)
 {
     try
     {
         for (int i = 0; i < ClistToCopy.Items.Count; i++)
         {
             TvShowEpisode ep = (TvShowEpisode)ClistToCopy.Items[i];
             ClistToCopy.SetItemChecked(i, ep.Status != ignored);
         }
         lancerToolStripMenuItem.Enabled = ButGo.Enabled = ClistToCopy.CheckedItems.Count > 0;
     }
     catch (Exception ex)
     {
         WriteLog(ex);
     }
 }
Exemplo n.º 8
0
        private void LoadDirThread(object param)
        {
            try
            {
                ListDictionary parameters = (ListDictionary)param;
                bool IsToday = (bool)parameters["istoday"];

                List<TvShowEpisode> Episodes = new List<TvShowEpisode>();

                ClistToCopy.Items.Clear();
                foreach (SourceFolder source in ListSources.Items)
                    try
                    {
                        DirectoryInfo dir = new DirectoryInfo(source.FolderPath);
                        FileInfo[] files = { };
                        foreach (string extension in TvShowEpisode.AvailableExtensions)
                            files = files.Concat(dir.GetFiles("*." + extension, SearchOption.AllDirectories)).ToArray<FileInfo>();

                        foreach (FileInfo file in files)
                            if (!IsToday || (IsToday && file.LastWriteTime.ToString("ddMMyyyy") == DateTime.Now.ToString("ddMMyyyy")))
                                try
                                {
                                    TvShowEpisode ep = null;
                                    if (source.FolderType == SourceFolder.Type.Anime)
                                        ep = new AnimeEpisode(file.FullName, TboxAnimesFilter.Text, source.Keep);
                                    else ep = new TvShowEpisode(file.FullName, TboxSeriesFilter.Text, source.Keep);

                                    Episodes.Add(ep);
                                    ep.TvShowMatch = LoadMatch(ep.TvShow);
                                }
                                catch (Exception ex)
                                {
                                    WriteLog(ex);
                                }
                    }
                    catch
                    {
                        WriteLog("Impossible de trouver le dossier " + source.FolderPath);
                    }
                Episodes.Sort();

                foreach (TvShowEpisode ep in Episodes)
                {
                    FillEpisodePossible(ep, false);
                    ClistToCopy.Items.Add(ep);
                }
                SetEditableFields(false);
                EnableButFillAll(false);

                ((MainForm)parameters["form"]).AfterLoadDir((bool)parameters["checknew"]);
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }
Exemplo n.º 9
0
        private void bgWorkerRename_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DestinationFolder dest = new DestinationFolder(((SourceFolder)CboxRenameSource.SelectedItem).FolderPath);
            List<DestinationFolder> folder = new List<DestinationFolder>();
            folder.Add(dest);
            List<string> fold = new List<string>();
            fold.Add(dest.FolderPath);

            string[] files = new string[0];
            //string[] errors = new string[0];

            foreach (string ext in TvShowEpisode.AvailableExtensions)
                files = files.Concat(Directory.GetFiles(((SourceFolder)CboxRenameSource.SelectedItem).FolderPath, "*." + ext, SearchOption.AllDirectories)).ToArray();
            foreach (string file in files)
            {
                TvShowEpisode ep = new TvShowEpisode(file);
                ep.FillTitle(0, folder);
                ep.FillFromFilter(TboxOldFilter.Text);
                ep.Filter = TboxSeriesFilter.Text;
                ep.FillPossibleFiles(folder);
                ep.Move();
                //foreach (string error in ep.Rename())
                //    WriteLog(error);
            }

            files = new string[0];
            foreach (string ext in Subtitle.AvailableExtensions)
                files = files.Concat(Directory.GetFiles(((SourceFolder)CboxRenameSource.SelectedItem).FolderPath, "*." + ext, SearchOption.AllDirectories)).ToArray();
            foreach (string file in files)
            {
                Subtitle st = new Subtitle(file);
                st.FillFromFilter(TboxOldFilter.Text);
                st.FillSearchFilter(TboxSeriesFilter.Text);
                st.FindVideos(fold, true);
                st.Rename(true);
            }
        }
Exemplo n.º 10
0
 private void bgWorkerRenameLoad_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     TboxOldFilter.Enabled = CboxRenameSource.Enabled = false;
     string[] files = new string[0];
     foreach (string ext in TvShowEpisode.AvailableExtensions)
         files = files.Concat(Directory.GetFiles(((SourceFolder)CboxRenameSource.SelectedItem).FolderPath, "*." + ext, SearchOption.AllDirectories)).ToArray();
     if (files.Length > 0)
     {
         TvShowEpisode ep = new TvShowEpisode(files[0]);
         DestinationFolder dest = new DestinationFolder(((SourceFolder)CboxRenameSource.SelectedItem).FolderPath);
         List<DestinationFolder> folder = new List<DestinationFolder>();
         folder.Add(dest);
         //ep.FillTitle(0, folder);
         try
         {
             ep.FillFromFilter(TboxOldFilter.Text);
             ep.Filter = TboxSeriesFilter.Text;
             TboxApercuRename.Text = ep.ApplyFilter();
         }
         catch
         {
             TboxApercuRename.Text = ep.FileName;
         }
     }
 }