Example #1
0
 protected virtual void OnListEpisode(Episode ep)
 {
     ListEpisodeHandler handler = ListEpisode;
     if (handler != null) {
         handler.Invoke(ep);
     }
 }
Example #2
0
        public void addSeriesLocation(Episode ep)
        {
            if (ep.special) return;

            FileInfo fi = new FileInfo(ep.filename);
            String fileLocation = fi.DirectoryName;

            if (locations.ContainsKey(ep.series)) {
                LocationData loc = (LocationData)this.locations[ep.series];
                if (!loc.locMap.ContainsKey(ep.season.ToString())) {
                    loc.locMap[ep.season.ToString()] = fileLocation;
                }
            }
            else {
                LocationData loc = new LocationData();
                loc.Series = ep.series;
                loc.locMap[ep.season] = fileLocation;
                this.locations.Add(ep.series, loc);
            }
        }
Example #3
0
        public override bool getSeriesData(ref showClass show, ref Episode ep)
        {
            WebClient cli = new WebClient();
            XmlDocument xml = new XmlDocument();

            if (!File.Exists(episodeCache)) {
                if (show.ID != null && show.Year > 0) {
                    //I know which series - just download it
                    cli.DownloadFile(String.Format(detailUrl, show.ID, ep.season, show.Year, show.Lang),
                        episodeCache);
                    xml.Load(episodeCache);
                }
                else {
                    // Search for series
                    cli.DownloadFile(String.Format(queryUrl, ep.series, ep.season), searchCache);
                    xml.Load(searchCache);

                    List<showClass> shows = new List<showClass>();
                    XmlNodeList nodes;
                    // Shows found on episodeworld.com
                    if (xml.DocumentElement.Name == "search") {
                        nodes = xml.GetElementsByTagName("found");
                        foreach (XmlNode node in nodes) {
                            showClass sc = new showClass();
                            sc.ID = node.Attributes["id"].Value;
                            sc.Name = node.Attributes["name"].Value;
                            sc.Year = Int32.Parse(node.Attributes["year"].Value);
                            shows.Add(sc);
                        }

                        if (ep.series != ep.altSeries) {
                            // Check altSeries list as well
                            cli.DownloadFile(String.Format(queryUrl, ep.altSeries, ep.season), searchCache);
                            xml.Load(searchCache);

                            if ((xml.DocumentElement.ChildNodes.Count > 0) &&
                            (xml.DocumentElement.Name == "search")) {
                                nodes = xml.GetElementsByTagName("found");
                                foreach (XmlNode node in nodes) {
                                    showClass sc = new showClass();
                                    sc.ID = node.Attributes["id"].Value;
                                    sc.Name = node.Attributes["name"].Value;
                                    sc.Year = Int32.Parse(node.Attributes["year"].Value);
                                    shows.Add(sc);
                                }
                            }
                        }
                    }

                    if (xml.DocumentElement.Name == "series") {
                        // Found series directly.
                        FileInfo fi = new FileInfo(searchCache);
                        fi.MoveTo(episodeCache);
                    }
                    else {
                        show = chooseSeries(ep, shows);
                        if (show != null) {
                            cli.DownloadFile(
                                String.Format(detailUrl, show.ID, ep.season, show.Year, show.Lang), episodeCache
                                );
                        }
                        shows.Clear();
                    }
                }
            }

            // Check if cache is outdated
            if (File.Exists(episodeCache)) {
                DateTime dt = File.GetLastWriteTime(episodeCache);
                if (DateTime.Now.Subtract(dt).TotalDays > 3) {
                    // Log.Add( i18n.t( "oparse_older", ep.series) );
                    File.Delete(episodeCache);
                    cli.DownloadFile(String.Format(detailUrl, show.ID, ep.season, show.Year, show.Lang),
                        episodeCache);
                }
                if (File.Exists(episodeCache)) {
                    xml.Load(episodeCache);
                }

                if (xml.DocumentElement.Attributes.Count > 1) {
                    if (show.Lang == "") {
                        List<String> languages = new List<String>();
                        XmlNodeList nodes = xml.GetElementsByTagName("episode");
                        foreach (XmlNode node in nodes) {
                            String lang = node.Attributes["language"].Value;
                            if (!languages.Contains(lang)) {
                                languages.Add(lang);
                            }
                        }

                        if (languages.Count > 1) {
                            List<showClass> shows = new List<showClass>();
                            foreach (String lang in languages) {
                                showClass showTemp = new showClass();
                                showTemp.ID = xml.DocumentElement.Attributes["id"].Value;
                                showTemp.Name = xml.DocumentElement.Attributes["name"].Value;
                                showTemp.Year = Int32.Parse(xml.DocumentElement.Attributes["year"].Value);
                                showTemp.Lang = lang;
                                shows.Add(showTemp);
                            }
                            show = chooseSeries(ep, shows);
                        }
                        else {
                            show.ID = xml.DocumentElement.Attributes["id"].Value;
                            show.Name = xml.DocumentElement.Attributes["name"].Value;
                            show.Year = Int32.Parse(xml.DocumentElement.Attributes["year"].Value);
                            show.Lang = languages[0];
                        }
                    }
                    ep.language = show.Lang;
                    ep.series = show.Name;
                }
            }

            cli.Dispose();

            if (ep.language == null || ep.language == "")
                ep.language = "english";

            // Find title for episode
            XmlNodeList episodes = xml.GetElementsByTagName("episode");
            if (episodes.Count > 0) {
                bool foundEp = false;
                // Search episode
                foreach (XmlNode node in episodes) {
                    if ((node.Attributes["season"].Value == ep.season.ToString()) &&
                         (node.Attributes["episode"].Value == ep.episode.ToString()) &&
                         (node.Attributes["language"].Value == ep.language.ToString()) &&
                         (node.Attributes["special"].Value == "false")
                        ) {
                        foundEp = true;
                        ep.title = node.Attributes["title"].Value;
                        break;
                    }
                }

                if (!foundEp) {
                    // Not found - maybe special episode after all ?
                    foreach (XmlNode node in episodes) {
                        if ((node.Attributes["season"].Value == ep.season.ToString()) &&
                             (node.Attributes["episode"].Value == ep.episode.ToString()) &&
                             (node.Attributes["language"].Value == ep.language.ToString()) &&
                             (node.Attributes["special"].Value == "true")
                            ) {
                            foundEp = true;
                            ep.title = node.Attributes["title"].Value;
                            break;
                        }
                    }
                }

                if (foundEp) {
                    if (ep.episodes.Length > 1) {
                        if (ep.title.EndsWith(")")) {
                            ep.title = ep.title.Substring(0, ep.title.LastIndexOf("("));
                        }
                    }
                    ep.title = ep.title.Replace(".i.", "");
                    if (ep.title.IndexOf("aka") > 0) {
                        ep.title = Eregi.replace("\\(aka([^)]*)\\)", "", ep.title);
                    }
                    return true;
                }
            }

            return false;
            // Done
        }
Example #4
0
        public String getEpisodePath(Episode ep)
        {
            if (this.locations.ContainsKey(ep.series)) {
                LocationData loc = (LocationData)this.locations[ep.series];
                if (loc.locMap.ContainsKey(ep.season.ToString())) {
                    String path = loc.locMap[ep.season.ToString()].ToString();
                    if (!Directory.Exists(path)) {
                        loc.locMap.Remove(ep.season.ToString());
                        this.saveLocations();
                        return null;
                    }
                    return path;
                }
                else if (loc.locMap.Count > 1) {
                    Char[] previous = null;
                    Char[] generic = null;
                    foreach (String path in loc.locMap.Values) {
                        if (previous == null) {
                            previous = path.ToCharArray();
                            generic = path.ToCharArray();
                        }
                        if (previous.Length < path.Length) {
                            Array.Resize<Char>(ref previous, path.Length);
                            Array.Resize<Char>(ref generic, path.Length);
                        }
                        for (int i = 0; i < path.Length; ++i) {
                            if (path[i].Equals(previous[i])) {
                                generic[i] = path[i];
                            }
                            else {
                                generic[i] = '|';
                            }
                        }
                    }
                    String seasonPath = new String(generic);
                    seasonPath = seasonPath.Replace("||", "|");
                    seasonPath = seasonPath.Replace("|", ep.season.ToString());
                    if (!Directory.Exists(seasonPath)) {
                        Directory.CreateDirectory(seasonPath);
                    }
                    return seasonPath;
                }
                else if (loc.locMap.Count == 1) {
                    foreach (String path in loc.locMap.Values) {
                        String seasonPath = path;
                        if (ep.season > 1) {
                            String previousSeason = (ep.season - 1).ToString();
                            int pos = path.LastIndexOf(previousSeason);
                            if (pos > 0) {
                                seasonPath = seasonPath.Remove(pos, previousSeason.Length);
                                seasonPath = seasonPath.Insert(pos, ep.season.ToString());
                            }
                            if (!Directory.Exists(seasonPath)) {
                                Directory.CreateDirectory(seasonPath);
                                loc.locMap[ep.season.ToString()] = seasonPath;
                                this.saveLocations();
                            }
                        }
                        return seasonPath;
                    }
                }
            }

            return null;
        }
        public override bool getSeriesData(ref showClass show, ref Episode ep)
        {
            XmlDocument xml = new XmlDocument();
            String url = "";

            episodeCache = String.Format(baseCache, seriesHash, "all");

            // Fix if older information is received
            if (show.Lang.Length > 2) {
                show.Lang = (String)languages[show.Lang.ToString()];
            }

            if (show.ID == String.Empty) {
                File.Delete(episodeCache);
            }

            if (!File.Exists(episodeCache)) {
                if (show.ID != String.Empty) {
                    //I know which series - just download it
                    url = String.Format(detailUrl, randomMirror(), show.ID, show.Lang);
                    downloadAndExtract(url, show.Lang);
                    xml.Load(episodeCache);
                }
                else {
                    // Search for series
                    xml.LoadXml(searchQuery(ep.series));

                    List<showClass> shows = new List<showClass>();
                    XmlNodeList nodes = xml.GetElementsByTagName("Series");
                    // Shows found on thetvdb.com
                    if (nodes.Count != 1) {
                        foreach (XmlNode node in nodes) {
                            showClass sc = new showClass();
                            sc.ID = node.SelectSingleNode("seriesid").InnerText;
                            sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                            if (node.SelectSingleNode("FirstAired") == null)
                                continue;
                            sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                            sc.Lang = node.SelectSingleNode("language").InnerText;
                            shows.Add(sc);
                        }

                        // Check altSeries list as well
                        if (ep.series != ep.altSeries) {
                            xml.LoadXml(searchQuery(ep.altSeries));

                            nodes = xml.GetElementsByTagName("Series");

                            if (nodes.Count > 1) {
                                foreach (XmlNode node in nodes) {
                                    showClass sc = new showClass();
                                    sc.ID = node.SelectSingleNode("seriesid").InnerText;
                                    sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                                    sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                                    sc.Lang = node.SelectSingleNode("language").InnerText;
                                    shows.Add(sc);
                                }
                            }
                        }
                    }

                    if (nodes.Count != 1 && shows.Count == 0) {
                        while (true) {
                            InputDialog input = new InputDialog("Couldn't find the matching series - please enter a valid series name:", Application.ProductName, ep.series);
                            if (input.ShowDialog() == DialogResult.OK) {
                                String seriesName = input.value;
                                xml.LoadXml(searchQuery(seriesName));
                                nodes = xml.GetElementsByTagName("Series");
                                if (nodes.Count > 0) {
                                    foreach (XmlNode node in nodes) {
                                        showClass sc = new showClass();
                                        sc.ID = node.SelectSingleNode("seriesid").InnerText;
                                        sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                                        if (node.SelectSingleNode("FirstAired") == null)
                                            continue;
                                        sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                                        sc.Lang = node.SelectSingleNode("language").InnerText;
                                        shows.Add(sc);
                                    }
                                    break;
                                }
                            }
                            else {
                                break;
                            }
                        }
                    }

                    if (nodes.Count == 1) {
                        // Found series directly.
                        show.ID = xml.SelectSingleNode("//Data/Series/seriesid").InnerText;
                        show.Name = xml.SelectSingleNode("//Data/Series/SeriesName").InnerText;
                        XmlNode showNode = xml.SelectSingleNode("//Data/Series/FirstAired");
                        if (showNode != null) {
                            show.Year = Int32.Parse(showNode.InnerText.Substring(0, 4));
                        }
                        show.Lang = xml.SelectSingleNode("//Data/Series/language").InnerText;
                        shows.Add(show);
                    }

                    show = chooseSeries(ep, shows);
                    if (show != null) {
                        ep.language = show.Lang;
                        ep.series = show.Name;
                        url = String.Format(detailUrl, randomMirror(), show.ID, ep.language);
                        downloadAndExtract(url, show.Lang);
                    }
                    shows.Clear();
                }
            }

            // Check if cache is available
            if (File.Exists(episodeCache)) {
                DateTime dt = File.GetLastWriteTime(episodeCache);
                // Check if cache is outdated
                if (DateTime.Now.Subtract(dt).TotalDays > 5) {
                    try {
                        url = String.Format(detailUrl, randomMirror(), show.ID, show.Lang);
                        downloadAndExtract(url, show.Lang);
                    }
                    catch (Exception E) {
                        Thread.Sleep(1000);
                        #if DEBUG
                        Log.Error("Could not download updated episode file for " + ep.ToString(), E);
                        #endif
                    }
                }
                if (File.Exists(episodeCache)) {
                    xml.Load(episodeCache);
                }
            }

            if (ep.language == null || ep.language == "")
                ep.language = show.Lang;

            show.Name = xml.SelectSingleNode("//Data/Series/SeriesName").InnerText;
            show.ID = xml.SelectSingleNode("//Data/Series/id").InnerText;
            XmlNode yearNode = xml.SelectSingleNode("//Data/Series/FirstAired");
            if (yearNode != null && yearNode.InnerText != String.Empty && yearNode.InnerText.Length >= 4) {
                show.Year = Int32.Parse(yearNode.InnerText.Substring(0, 4));
            }

            // Find title for episode
            XmlNodeList episodes = xml.GetElementsByTagName("Episode");
            if (episodes.Count > 0) {
                // Search episode
                foreach (XmlNode episodeXml in episodes) {
                    Int32 season = Int32.Parse(episodeXml.SelectSingleNode("SeasonNumber").InnerText);
                    Int32 episode = Int32.Parse(episodeXml.SelectSingleNode("EpisodeNumber").InnerText);

                    if (season == ep.season && episode == ep.episode) {
                        ep.title = episodeXml.SelectSingleNode("EpisodeName").InnerText;

                        if (ep.episodes.Length > 1) {
                            if (ep.title.EndsWith(")")) {
                                ep.title = ep.title.Substring(0, ep.title.LastIndexOf("("));
                            }
                        }
                        ep.title = ep.title.Replace(".i.", "");
                        if (ep.title.IndexOf("aka") > 0) {
                            ep.title = Eregi.replace("\\(aka([^)]*)\\)", "", ep.title);
                        }

                        return true;
                    }
                }
            }

            return false;
            // Done
        }
Example #6
0
        void series_ListEpisode(Episode ep)
        {
            if (InvokeRequired) {
                Invoke(new ListEpisodeHandler(series_ListEpisode), ep);
                return;
            }
            ListViewItem node = new ListViewItem(ep.series);
            node.SubItems.Add(ep.season.ToString());
            String episodes = "";
            for (int i = 0; i < ep.episodes.Length; i++) {
                episodes += ep.episodes[i].ToString();
                if (i < (ep.episodes.Length - 1)) {
                    episodes += ", ";
                }
            }
            node.SubItems.Add(episodes);
            node.SubItems.Add(ep.title);
            FileInfo fi = new FileInfo(ep.filename);
            node.SubItems.Add(fi.Name);
            node.SubItems.Add(ep.modifiedName());
            node.Tag = ep;

            scanSeriesList.Items.Add(node);
        }
        internal void renameGeneric(ref Episode ep)
        {
            FileInfo fi = new FileInfo(ep.filename);

            String fname = fi.Name;
            Regex brack = new Regex("\\[([0-9A-Za-z-]*)\\]");
            MatchCollection mcol = brack.Matches(fname);
            if (mcol.Count > 0) {
                for (int i = 0; i < mcol.Count; i++) {
                    fname = fname.Replace(mcol[i].Groups[0].Captures[0].Value, "");
                }
            }

            Regex epId = new Regex("([0-9]{2,})");
            Match m = epId.Match(fname);
            int episodeId = 0;
            if (m.Success) {
                episodeId = Int32.Parse(m.Groups[0].Captures[0].Value);
            }

            String file = fi.Name;
            file = file.Replace(fi.Extension, "");
            file = file.Replace('.', ' ');
            file = file.Replace('_', ' ');
            file = file.Substring(file.LastIndexOf(" - ") + 3);
            ep.title = file;
        }
        public void getEpisodeData(ref Episode ep)
        {
            try {
                showClass show = new showClass();
                show.Name = ep.series;
                String seriesOld = ep.series.ToLower();

                if (seriesList.ContainsKey(seriesOld)) {
                    show = (showClass)seriesList[seriesOld];
                    ep.series = show.Name;
                }
                else if (seriesList.ContainsKey(ep.altSeries.ToLower())) {
                    show = (showClass)seriesList[ep.altSeries.ToLower()];
                    ep.series = show.Name;
                }
                else {
                    // No data found yet.
                }
                seriesHash = MD5.createHash(show.Name);
                episodeCache = String.Format(baseCache, seriesHash, ep.season);

                if (ep.special) return;

                bool hr = getSeriesData(ref show, ref ep);

                if (show != null && show.ID != "") {
                    bool listChanged = false;
                    if (!seriesList.ContainsKey(ep.series.ToLower())) {
                        seriesList.Add(ep.series.ToLower(), show);
                        listChanged = true;
                    }
                    if (!seriesList.ContainsKey(seriesOld)) {
                        seriesList.Add(seriesOld, show);
                        listChanged = true;
                    }
                    if (!seriesList.ContainsKey(show.Name.ToLower())) {
                        seriesList.Add(show.Name.ToLower(), show);
                        listChanged = true;
                    }
                    if (listChanged)
                        Settings.SetValue(parserDataCache, seriesList);
                }

                /*if (!hr)
                {
                    this.renameGeneric(ref ep);
                }*/

                MatchCollection mcol = null;
                Match m = null;
                Regex uni = new Regex("&#([0-9]+);");
                mcol = uni.Matches(ep.title);
                if (mcol.Count > 0) {
                    Regex real = new Regex("\\(([-a-zA-Z0-9.,%:;!?'\"+() ]{5,})\\)");
                    m = real.Match(ep.title);
                    if (m.Success) {
                        ep.title = m.Groups[1].Captures[0].Value;
                    }
                }
            }
            catch (Exception E) {
                #if DEBUG
                Log.Error("Error fetching online data for:\n" +
                    ep.filename + "\n" +
                    ep.series + " " + ep.season + "x" + ep.episode + " " + ep.title,
                    E);
                #endif
            }
        }
        internal showClass chooseSeries(Episode ep, List<showClass> shows)
        {
            if (shows.Count == 0) return null;
            if (shows.Count == 1) {
                return shows[0];
            }
            SelectShow showDlg = new SelectShow();

            showDlg.Text = String.Format("Select series for {0}", ep.series);
            showDlg.setEpisodeData(ep);
            showDlg.addShows(shows);

            if (showDlg.ShowDialog() == DialogResult.OK) {
                return showDlg.selectedShow;
            }
            else {
                return null;
            }
        }
Example #10
0
 public abstract bool getSeriesData(ref showClass show, ref Episode ep);
Example #11
0
        override public bool getSeriesData(ref showClass show, ref Episode ep)
        {
            XmlDocument xml = new XmlDocument();
            String      url = "";

            episodeCache = String.Format(baseCache, seriesHash, "all");

            // Fix if older information is received
            if (show.Lang.Length > 2)
            {
                show.Lang = (String)languages[show.Lang.ToString()];
            }

            if (show.ID == String.Empty)
            {
                File.Delete(episodeCache);
            }

            if (!File.Exists(episodeCache))
            {
                if (show.ID != String.Empty)
                {
                    //I know which series - just download it
                    url = String.Format(detailUrl, randomMirror(), show.ID, show.Lang);
                    downloadAndExtract(url, show.Lang);
                    xml.Load(episodeCache);
                }
                else
                {
                    // Search for series
                    xml.LoadXml(searchQuery(ep.series));

                    List <showClass> shows = new List <showClass>();
                    XmlNodeList      nodes = xml.GetElementsByTagName("Series");
                    // Shows found on thetvdb.com
                    if (nodes.Count != 1)
                    {
                        foreach (XmlNode node in nodes)
                        {
                            showClass sc = new showClass();
                            sc.ID   = node.SelectSingleNode("seriesid").InnerText;
                            sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                            if (node.SelectSingleNode("FirstAired") == null)
                            {
                                continue;
                            }
                            sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                            sc.Lang = node.SelectSingleNode("language").InnerText;
                            shows.Add(sc);
                        }

                        // Check altSeries list as well
                        if (ep.series != ep.altSeries)
                        {
                            xml.LoadXml(searchQuery(ep.altSeries));

                            nodes = xml.GetElementsByTagName("Series");

                            if (nodes.Count > 1)
                            {
                                foreach (XmlNode node in nodes)
                                {
                                    showClass sc = new showClass();
                                    sc.ID   = node.SelectSingleNode("seriesid").InnerText;
                                    sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                                    sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                                    sc.Lang = node.SelectSingleNode("language").InnerText;
                                    shows.Add(sc);
                                }
                            }
                        }
                    }

                    if (nodes.Count != 1 && shows.Count == 0)
                    {
                        while (true)
                        {
                            InputDialog input = new InputDialog("Couldn't find the matching series - please enter a valid series name:", Application.ProductName, ep.series);
                            if (input.ShowDialog() == DialogResult.OK)
                            {
                                String seriesName = input.value;
                                xml.LoadXml(searchQuery(seriesName));
                                nodes = xml.GetElementsByTagName("Series");
                                if (nodes.Count > 0)
                                {
                                    foreach (XmlNode node in nodes)
                                    {
                                        showClass sc = new showClass();
                                        sc.ID   = node.SelectSingleNode("seriesid").InnerText;
                                        sc.Name = node.SelectSingleNode("SeriesName").InnerText;
                                        if (node.SelectSingleNode("FirstAired") == null)
                                        {
                                            continue;
                                        }
                                        sc.Year = Int32.Parse(node.SelectSingleNode("FirstAired").InnerText.Substring(0, 4));
                                        sc.Lang = node.SelectSingleNode("language").InnerText;
                                        shows.Add(sc);
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (nodes.Count == 1)
                    {
                        // Found series directly.
                        show.ID   = xml.SelectSingleNode("//Data/Series/seriesid").InnerText;
                        show.Name = xml.SelectSingleNode("//Data/Series/SeriesName").InnerText;
                        XmlNode showNode = xml.SelectSingleNode("//Data/Series/FirstAired");
                        if (showNode != null)
                        {
                            show.Year = Int32.Parse(showNode.InnerText.Substring(0, 4));
                        }
                        show.Lang = xml.SelectSingleNode("//Data/Series/language").InnerText;
                        shows.Add(show);
                    }

                    show = chooseSeries(ep, shows);
                    if (show != null)
                    {
                        ep.language = show.Lang;
                        ep.series   = show.Name;
                        url         = String.Format(detailUrl, randomMirror(), show.ID, ep.language);
                        downloadAndExtract(url, show.Lang);
                    }
                    shows.Clear();
                }
            }

            // Check if cache is available
            if (File.Exists(episodeCache))
            {
                DateTime dt = File.GetLastWriteTime(episodeCache);
                // Check if cache is outdated
                if (DateTime.Now.Subtract(dt).TotalDays > 5)
                {
                    try {
                        url = String.Format(detailUrl, randomMirror(), show.ID, show.Lang);
                        downloadAndExtract(url, show.Lang);
                    }
                    catch (Exception E) {
                        Thread.Sleep(1000);
                        #if DEBUG
                        Log.Error("Could not download updated episode file for " + ep.ToString(), E);
                        #endif
                    }
                }
                if (File.Exists(episodeCache))
                {
                    xml.Load(episodeCache);
                }
            }


            if (ep.language == null || ep.language == "")
            {
                ep.language = show.Lang;
            }

            show.Name = xml.SelectSingleNode("//Data/Series/SeriesName").InnerText;
            show.ID   = xml.SelectSingleNode("//Data/Series/id").InnerText;
            XmlNode yearNode = xml.SelectSingleNode("//Data/Series/FirstAired");
            if (yearNode != null && yearNode.InnerText != String.Empty && yearNode.InnerText.Length >= 4)
            {
                show.Year = Int32.Parse(yearNode.InnerText.Substring(0, 4));
            }

            // Find title for episode
            XmlNodeList episodes = xml.GetElementsByTagName("Episode");
            if (episodes.Count > 0)
            {
                // Search episode
                foreach (XmlNode episodeXml in episodes)
                {
                    Int32 season  = Int32.Parse(episodeXml.SelectSingleNode("SeasonNumber").InnerText);
                    Int32 episode = Int32.Parse(episodeXml.SelectSingleNode("EpisodeNumber").InnerText);

                    if (season == ep.season && episode == ep.episode)
                    {
                        ep.title = episodeXml.SelectSingleNode("EpisodeName").InnerText;

                        if (ep.episodes.Length > 1)
                        {
                            if (ep.title.EndsWith(")"))
                            {
                                ep.title = ep.title.Substring(0, ep.title.LastIndexOf("("));
                            }
                        }
                        ep.title = ep.title.Replace(".i.", "");
                        if (ep.title.IndexOf("aka") > 0)
                        {
                            ep.title = Eregi.replace("\\(aka([^)]*)\\)", "", ep.title);
                        }

                        return(true);
                    }
                }
            }

            return(false);
            // Done
        }
Example #12
0
 public void setEpisodeData(Episode ep)
 {
     labelEpisode.Text = "Season " + ep.season + " Episode " + ep.episode + ": " + ep.title;
     FileInfo fi = new FileInfo(ep.filename);
     labelFile.Text = fi.Directory.Parent.Name + @"\" + fi.Directory.Name + @"\" + fi.Name;
 }
Example #13
0
        /// <summary>
        /// Parses a filename for episode information
        /// </summary>
        /// <param name="file">complete filename</param>
        /// <returns>filled Episode class</returns>
        public static Episode parseFile(String file)
        {
            Episode ep = new Episode(file);
            FileInfo fi = new FileInfo(file);
            try {
                String dir = "";
                dir = fi.Directory.FullName;
                while (true) {
                    if (dir == null) break;
                    DirectoryInfo di = new DirectoryInfo(dir);
                    // Skip those folders since they probably contain no episodes but extras/bonus material
                    if ((di.Name.ToLower().IndexOf("season") != 0) &&
                        (di.Name.ToLower().IndexOf("series") != 0) &&
                        (di.Name.ToLower().IndexOf("extra") != 0) &&
                        (di.Name.ToLower().IndexOf("special") != 0) &&
                        (di.Name.ToLower().IndexOf("bonus") != 0) &&
                        (di.Name.ToLower().IndexOf("dvd") != 0)
                        ) {
                        ep.series = di.Name;
                        Regex reg = new Regex("([0-9]{4})");
                        Match m = null;
                        m = reg.Match(ep.series);
                        if (m.Success) {
                            int year = Int32.Parse(m.Groups[1].Captures[0].Value);
                            if (year <= DateTime.Now.Year) {
                                ep.year = year;
                                ep.series = ep.series.Replace(m.Groups[1].Captures[0].Value, "");
                            }
                        }
                        ep.series = ep.series.Replace("()", "");
                        break;
                    }
                    else {
                        dir = di.Parent.FullName;
                    }
                }

                String title = "";
                String series = "";
                String name = fi.Name;
                bool matched = false;
                // Scan for season and episode
                String[] regExp = Episode.regEx;
                foreach (String pat in regExp) {
                    Regex reg = new Regex(pat, RegexOptions.IgnoreCase);
                    Match m = null;
                    m = reg.Match(name);
                    if (m.Success) {
                        ep.season = Int32.Parse(m.Result("${season}"));
                        ep.episode = Int32.Parse(m.Result("${episode}"));
                        String episode2str = m.Result("${episode2}");
                        int episode2 = -1;
                        Int32.TryParse(episode2str, out episode2);
                        if (episode2 != 0) {
                            ep.episodes = new int[2];
                            ep.episodes[0] = ep.episode;
                            ep.episodes[1] = episode2;
                        }
                        else {
                            ep.episodes = new int[1];
                            ep.episodes[0] = ep.episode;
                        }

                        if (name.IndexOf(m.Value) > 0) {
                            series = name.Substring(0, name.IndexOf(m.Value) - 1);

                            series = Eregi.replace("([a-zA-Z]{1})([0-9]{1})", "\\1 \\2", series);
                            series = Eregi.replace("([0-9]{1})([a-zA-Z]{1})", "\\1 \\2", series);
                            series = Eregi.replace("([a-zA-Z]{2})\\.([a-zA-Z]{1})", "\\1 \\2", series);
                            series = Eregi.replace("([a-zA-Z]{1})\\.([a-zA-Z]{2})", "\\1 \\2", series);
                            series = series.Replace("_", " ");
                            series = series.Replace("  ", " ");
                            series = series.Replace(" - ", " ");
                            series = series.Replace(" -", " ");
                            series = series.Replace("[", "");
                            series = series.Replace("]", "");
                            series = series.Replace("(", "");
                            series = series.Replace(")", "");
                            series = series.Trim();
                        }
                        ep.altSeries = ep.series;
                        ep.series = series;
                        if (ep.series == "") ep.series = ep.altSeries;

                        if (name.IndexOf(m.Value) == 0) {
                            title = name.Replace(m.Value, "");
                        }
                        else {
                            title = name.Substring(name.IndexOf(m.Value) + m.Value.Length);
                        }
                        if (title.StartsWith(" - ")) {
                            title = title.Substring(3);
                        }
                        title = title.Trim();
                        title = title.Substring(0, title.LastIndexOf("."));
                        ep.title = title;

                        // find title using online parser
                        OnlineParserBase parser = null;
                        String selectedParser = Settings.GetValueAsString(SettingKeys.SeriesParser);
                        if (selectedParser == OnlineParserTVDB.parserName) {
                            parser = new OnlineParserTVDB();
                        }
                        else if (selectedParser == OnlineParserEPW.parserName) {
                            parser = new OnlineParserEPW();
                        }
                        parser.getEpisodeData(ref ep);

                        matched = true;

                        break;
                    }
                }
                // no matching data found. try to find title of episode anyway
                if (!matched) {
                    ep.season = 0;
                    ep.episode = 0;
                    if (file.IndexOf("-") > 0) {
                        title = file.Substring(file.IndexOf("-") + 1);
                        title = title.Trim();
                        title = title.Substring(0, title.LastIndexOf("."));
                        ep.title = title;
                    }
                }
            }
            catch (Exception E) {
                #if DEBUG
                MessageBox.Show("Error parsing file\n" + ep.filename + "\n\n" + E.Message);
                #endif
            }

            return ep;
        }