Exemplo n.º 1
0
        private SubtitleStream GetSubtitle(FileStream file, string languageCodes)
        {
            string hash = file.CalculateSubDbHash();

            var requestUri = new Uri(String.Format("{0}/?action=download&hash={1}&language={2}", ApiUrl, hash, languageCodes));

            var responseData = SendRequest(requestUri);

            if (responseData != null)
            {
                var languageCode = responseData.Item2.Get("Content-Language");
                var language     = languageCode != null ? new CultureInfo(languageCode) : null;

                var    cd        = responseData.Item2.Get("Content-Disposition");
                string extension = null;

                if (REGEX_GET_EXTENSION.IsMatch(cd))
                {
                    extension = REGEX_GET_EXTENSION.Match(cd).Groups[1].Value;
                }

                return(new SubtitleStream(responseData.Item1, new FileInfo(file.Name), language, SubtitleFormat.ForExtension(extension), IDENTIFIER));
            }
            else
            {
                return(null);
            }
        }