예제 #1
0
        private async Task <bool> Initialize()
        {
            try
            {
                var client = new XmlHttpClient();
                var xml    = await client.PostXmlAsync(OpenSubtitlesAPIUrl, "LogIn", new List <string> {
                    "", "", "fre", USER_AGENT
                });

                var tokenNode = xml.GetElementsByTagName("name");
                var firstNode = tokenNode[0].NextSibling;
                while (firstNode != null && token == null)
                {
                    if (firstNode.NodeName == "value")
                    {
                        token = System.Net.WebUtility.HtmlDecode(firstNode.InnerText.ToString()).Trim();
                    }
                    else
                    {
                        firstNode = firstNode.NextSibling;
                    }
                }
                if (!string.IsNullOrEmpty(token))
                {
                    configured = true;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("The app failed to get the OpenSubtitle token : " + e.ToString());
            }
            return(configured);
        }
예제 #2
0
        public async Task <string> GetSubtitleUrl(VideoItem video)
        {
            if (!configured)
            {
                if (!await Initialize())
                {
                    return(null);
                }
            }

            var file = await StorageFile.GetFileFromPathAsync(video.Path);

            var hash = await FileUtils.ComputeHash(file);

            var size = (await file.GetBasicPropertiesAsync()).Size;

            var client = new XmlHttpClient();

            var parameters = new List <object>();

            parameters.Add(token);
            parameters.Add(new SerializableList <SerializableDictionary <string, object> >()
            {
                new SerializableDictionary <string, object>
                {
                    { "sublanguageid", "eng" },
                    { "moviehash", hash },
                    { "moviebytesize", (double)size }
                }
            });
            var xml = await client.PostXmlAsync(OpenSubtitlesAPIUrl, "SearchSubtitles", parameters);

            var nodes = xml.GetElementsByTagName("name");

            for (uint i = 0; i < nodes.Count; i++)
            {
                var node = nodes.Item(i);
                if (node.InnerText == "ZipDownloadLink")
                {
                    return(node.NextSibling.NextSibling.InnerText.Trim());
                }
            }
            return(string.Empty);
        }