Exemple #1
0
        public static string[] GetMovieID(string Title, string Year = "")
        {
            string URLTitle = null;
            string url      = null;

            byte[]              MovieData = null;
            FileStream          FileWrite = default(FileStream);
            XPathDocument       xpathDoc  = default(XPathDocument);
            XPathNavigator      xmlNav    = default(XPathNavigator);
            XmlNamespaceManager nsMgr     = default(XmlNamespaceManager);
            XPathNodeIterator   xmlNI     = default(XPathNodeIterator);
            int Result = 0;

            string[]       TMDbID      = { "", string.Empty };
            frmTitleSelect TitleSelect = new frmTitleSelect();

            //Replace spaces in movie title with +'s and, create URL, and get data
            URLTitle  = Title.Replace(" ", "+");
            url       = "http://api.themoviedb.org/2.1/Movie.search/en/xml/" + tmdbAPIKey + "/" + URLTitle;
            MovieData = GetWebData(url);

            //Write data to temporary XML file
            FileWrite = new FileStream(TempDir + "temp.xml", FileMode.Create);
            FileWrite.Write(MovieData, 0, MovieData.Length);
            FileWrite.Close();

            //Open XML file
            xpathDoc = new XPathDocument(TempDir + "temp.xml");
            xmlNav   = xpathDoc.CreateNavigator();
            nsMgr    = new XmlNamespaceManager(xmlNav.NameTable);
            nsMgr.AddNamespace("opensearch", "http://a9.com/-/spec/opensearch/1.1/");

            //If the year of the movie was captured use the Title and Year to search XML
            if (!string.IsNullOrEmpty(Year))
            {
                //Check to make sure there were results first
                xmlNI = xmlNav.Select("/OpenSearchDescription/opensearch:totalResults", nsMgr);
                xmlNI.MoveNext();
                Result = Convert.ToInt32(xmlNI.Current.Value);
                //If Result <> "Nothing found." Then
                if (Result > 0)
                {
                    xmlNI = xmlNav.Select("/OpenSearchDescription/movies/movie[contains(name,\"" + Title + "\") and contains(released,'" + Year + "')]/id");
                }
                else
                {
                    return(TMDbID);
                }
                //Otherwise get all TMDB ID's
            }
            else
            {
                //Check to make sure there were results first
                xmlNI = xmlNav.Select("/OpenSearchDescription/opensearch:totalResults", nsMgr);
                xmlNI.MoveNext();
                Result = Convert.ToInt32(xmlNI.Current.Value);
                //If Result <> "Nothing found." Then
                if (Result > 0)
                {
                    //xmlNI = xmlNav.Select("/OpenSearchDescription/movies/movie/name[. = """ & Title & """]/parent::node()/id")
                    xmlNI = xmlNav.Select("/OpenSearchDescription/movies/movie[name = \"" + Title + "\"]/id");
                }
                else
                {
                    return(TMDbID);
                }
            }

            //Only get the TMDB ID if there is one result, otherwise we don't want to get the wrong ID
            if (xmlNI.Count == 1)
            {
                while (xmlNI.MoveNext())
                {
                    TMDbID[0] = xmlNI.Current.Value;
                }
            }
            else
            {
                SelectedID[0] = string.Empty;

                xmlNI      = xmlNav.Select("/OpenSearchDescription/movies/movie/name");
                Selections = new string[xmlNI.Count, 3];

                int x = 0;
                while (xmlNI.MoveNext())
                {
                    Selections[x, 0] = xmlNI.Current.Value;
                    x += 1;
                }
                xmlNI = xmlNav.Select("/OpenSearchDescription/movies/movie/released");
                x     = 0;
                while (xmlNI.MoveNext())
                {
                    Selections[x, 1] = xmlNI.Current.Value;
                    x += 1;
                }
                xmlNI = xmlNav.Select("/OpenSearchDescription/movies/movie/id");
                x     = 0;
                while (xmlNI.MoveNext())
                {
                    Selections[x, 2] = xmlNI.Current.Value;
                    x += 1;
                }
                SearchedTitle = "File Title: " + Title;
                TitleSelect.ShowDialog();
                if (SelectedID[0] != string.Empty)
                {
                    TMDbID = SelectedID;
                }
            }
            //Delete temp file
            File.Delete(TempDir + "temp.xml");
            //Return the TMDB ID
            return(TMDbID);
        }
Exemple #2
0
        public static long GetSeriesID(string SeriesName, string RecEpID = "0")
        {
            byte[]     bytearray = null;
            FileStream xmldata   = default(FileStream);
            string     url       = null;
            string     Title     = null;
            string     SeriesID  = "0";
            long       RecZapID  = 0;
            //string zapID = "";
            XPathDocument     xpathDoc;
            XPathNavigator    xmlNav;
            XPathNodeIterator xmlNI;
            frmTitleSelect    TitleSelect = new frmTitleSelect();

            //Replace spaces in title with +'s, generate URL, and get XML data
            Title     = SeriesName.Replace(" ", "+");
            url       = "http://www.thetvdb.com/api/GetSeries.php?seriesname=" + Title + "&language=en";
            bytearray = GetWebData(url);

            //Write XML data to file
            xmldata = new FileStream(TempDir + "temp.xml", FileMode.Create);
            xmldata.Write(bytearray, 0, bytearray.Length);
            xmldata.Close();

            //Open file with XPath
            xpathDoc = new XPathDocument(@TempDir + "temp.xml");
            xmlNav   = xpathDoc.CreateNavigator();

            //If there is no ID from file metadata exactly match title to get TVDB Series ID
            if (RecEpID == "0")
            {
                //xmlNI = xmlNav.Select("//SeriesName[. = '" & SeriesName & "']/parent::node()/seriesid")
                xmlNI = xmlNav.Select("/Data/Series[contains(SeriesName,\"" + SeriesName + "\")]/seriesid");

                if (xmlNI.Count > 0)
                {
                    if (xmlNI.Count == 1)
                    {
                        xmlNI.MoveNext();
                        SeriesID = xmlNI.Current.Value;
                    }
                    else
                    {
                        SelectedID[0] = string.Empty;
                        xmlNI         = xmlNav.Select("/Data/Series/SeriesName");
                        Selections    = new string[xmlNI.Count, 3];

                        int x = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 0] = xmlNI.Current.Value;
                            x += 1;
                        }
                        xmlNI = xmlNav.Select("/Data/Series/FirstAired");
                        x     = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 1] = xmlNI.Current.Value.Substring(0, 4);
                            x += 1;
                        }
                        xmlNI = xmlNav.Select("/Data/Series/seriesid");
                        x     = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 2] = xmlNI.Current.Value;
                            x += 1;
                        }
                        SearchedTitle = "File Title: " + SeriesName;
                        TitleSelect.ShowDialog();
                        if (SelectedID[0] != string.Empty)
                        {
                            SeriesID = SelectedID[0];
                        }
                    }
                }

                //Otherwise try and match the zap2it ID to the recording's ID to get the correct TVDB Series ID
            }
            else
            {
                RecZapID = Convert.ToInt64(RecEpID.Substring(2, (RecEpID.Length - 2)).Substring(0, (RecEpID.Length - 2 - 4)));

                xmlNI = xmlNav.Select("/Data/Series[contains(zap2it_id,'" + RecZapID.ToString() + "')]/seriesid");

                if (xmlNI.Count > 1)
                {
                    //xmlNI = xmlNav.Select("//SeriesName[. = '" & SeriesName & "']/parent::node()/seriesid")
                    xmlNI = xmlNav.Select("/Data/Series[contains(SeriesName,\"" + SeriesName + "\")]/seriesid");
                    if (xmlNI.Count == 1)
                    {
                        xmlNI.MoveNext();
                        SeriesID = xmlNI.Current.Value;
                    }
                    else
                    {
                        SelectedID[0] = string.Empty;
                        xmlNI         = xmlNav.Select("/Data/Series[contains(zap2it_id,'" + RecZapID.ToString() + "')]/SeriesName");
                        Selections    = new string[xmlNI.Count, 3];

                        int x = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 0] = xmlNI.Current.Value;
                            x += 1;
                        }
                        xmlNI = xmlNav.Select("/Data/Series[contains(zap2it_id,'" + RecZapID.ToString() + "')]/FirstAired");
                        x     = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 1] = xmlNI.Current.Value.Substring(0, 4);
                            x += 1;
                        }
                        xmlNI = xmlNav.Select("/Data/Series[contains(zap2it_id,'" + RecZapID.ToString() + "')]/seriesid");
                        x     = 0;
                        while (xmlNI.MoveNext())
                        {
                            Selections[x, 2] = xmlNI.Current.Value;
                            x += 1;
                        }
                        SearchedTitle = "File Title: " + SeriesName;
                        TitleSelect.ShowDialog();
                        if (SelectedID[0] != string.Empty)
                        {
                            SeriesID = SelectedID[0];
                        }
                    }
                }
                else if (xmlNI.Count == 1)
                {
                    xmlNI.MoveNext();
                    SeriesID = xmlNI.Current.Value;
                }
                else if (xmlNI.Count == 0)
                {
                    SeriesName = SeriesName.ToLower();
                    xmlNI      = xmlNav.Select("/Data/Series[translate(SeriesName,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = \"" + SeriesName + "\"]/seriesid");
                    if (xmlNI.Count > 0)
                    {
                        xmlNI.MoveNext();
                        SeriesID = xmlNI.Current.Value;
                    }
                }
            }

            if (string.IsNullOrEmpty(SeriesID))
            {
                SeriesID = "0";
            }

            //Delete temporary XML file and return the TVDB series ID
            File.Delete(TempDir + "temp.xml");
            return(Convert.ToInt64(SeriesID));
        }