コード例 #1
0
        public string DownloadSubtitle(string fileName, SubtitleInfo subtitle)
        {
            if (string.IsNullOrEmpty(subtitle.SubFormat))
            {
                subtitle.SubFormat = "srt";
            }

            return(DoDownloadSubtitle(fileName, subtitle));
        }
コード例 #2
0
        protected override List<SubtitleInfo> DoGetSubtitles(VideoInfo vi)
        {
            List<SubtitleInfo> retVal = new List<SubtitleInfo>();

            SubtitleFile[] subtitles = _wsdl.searchSubtitlesByHash(vi.moviehash, vi.sublanguageid, 0, 100);
            if (subtitles != null && subtitles.Length > 0)
            {
                foreach (SubtitleFile sf in subtitles)
                {
                    SubtitleInfo si = new SubtitleInfo();

                    si.IDSubtitleFile = sf.cod_subtitle_file.ToString();
                    si.SubFileName = sf.file_name;
                    si.SubHash = sf.sub_hash;
                    si.LanguageName = sf.language;
                    si.MovieHash = vi.moviehash;
                    si.SubFormat = PathUtils.GetExtension(sf.file_name);

                    retVal.Add(si);
                }
            }

            return retVal;
        }
コード例 #3
0
 protected abstract string DoDownloadSubtitle(string fileName, SubtitleInfo subtitle);
コード例 #4
0
        public string DownloadSubtitle(string fileName, SubtitleInfo subtitle)
        {
            if (string.IsNullOrEmpty(subtitle.SubFormat))
            {
                subtitle.SubFormat = "srt";
            }

            return DoDownloadSubtitle(fileName, subtitle);
        }
コード例 #5
0
ファイル: OsdbSession.cs プロジェクト: rraguso/protone-suite
        protected override string DoDownloadSubtitle(string fileName, SubtitleInfo subtitle)
        {
            string destPath = Path.ChangeExtension(fileName, subtitle.SubFormat);
            string downloadPath = Path.ChangeExtension(fileName, "gz");

            bool downloaded = false;
            using (WebFileRetriever wfr = new WebFileRetriever(AppConfig.ProxySettings,
                subtitle.SubDownloadLink, downloadPath, false))
            {
                downloaded = true;
            }

            if (downloaded)
            {
                using (FileStream compressedSubtitle = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                {
                    using (GZipStream str = new GZipStream(compressedSubtitle, CompressionMode.Decompress, false))
                    {
                        using (FileStream outputSubtitle = new FileStream(destPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            byte[] buffer = new byte[65536];
                            int read = 0;
                            do
                            {
                                read = str.Read(buffer, 0, buffer.Length);
                                if (read > 0)
                                {
                                    outputSubtitle.Write(buffer, 0, read);
                                }
                            }
                            while (read > 0);
                        }
                    }
                }

                File.Delete(downloadPath);

                return destPath;
            }

            return string.Empty;
        }
コード例 #6
0
ファイル: BspV1Session.cs プロジェクト: rraguso/protone-suite
        protected override List<SubtitleInfo> DoGetSubtitles(VideoInfo vi)
        {
            List<SubtitleInfo> retVal = new List<SubtitleInfo>();

            SearchResult res = _wsdl.searchSubtitles(_sessionToken, vi.moviehash, (long)vi.moviebytesize, vi.sublanguageid, vi.imdbid);
            if (res.data != null && res.data.Length > 0)
            {
                foreach (SubtitleData sd in res.data)
                {
                    SubtitleInfo si = new SubtitleInfo();

                    si.IDSubtitleFile = sd.subID.ToString();
                    si.SubFileName = sd.subName;
                    si.MovieName = sd.movieName;
                    si.SubHash = sd.subHash;

                    si.LanguageName = OPMedia.Core.Language.ThreeLetterISOLanguageNameToEnglishName(sd.subLang);

                    si.MovieHash = vi.moviehash;
                    si.SubDownloadLink = sd.subDownloadLink;
                    si.SubFormat = sd.subFormat;

                    retVal.Add(si);
                }
            }

            return retVal;
        }
コード例 #7
0
 protected abstract string DoDownloadSubtitle(string fileName, SubtitleInfo subtitle);
コード例 #8
0
        public string DownloadCompressedSubtitle(string fileName, SubtitleInfo subtitle)
        {
            try
            {
                if (_session == null)
                {
                    _session = SubtitleServerSession.Create(_serverType, _serverUrl, _userName, _password);
                }

                if (_session != null)
                {
                    return _session.DownloadSubtitle(fileName, subtitle);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return string.Empty;
        }
コード例 #9
0
        protected override string DoDownloadSubtitle(string fileName, SubtitleInfo si)
        {
            OPMedia.Runtime.ProTONE.NuSoap.SubtitleDownload sd = new OPMedia.Runtime.ProTONE.NuSoap.SubtitleDownload();
            int x = 0;
            int.TryParse(si.IDSubtitleFile, out x);

            sd.cod_subtitle_file = x;
            sd.movie_hash = si.MovieHash;

            string destPath = Path.ChangeExtension(fileName, si.SubFormat);

            SubtitleArchive[] archives = _wsdl.downloadSubtitles(new OPMedia.Runtime.ProTONE.NuSoap.SubtitleDownload[] { sd });

            if (archives != null && archives.Length > 0)
            {
                byte[] decodedBytes = Convert.FromBase64String(archives[0].data);

                using (MemoryStream compressedSubtitle = new MemoryStream(decodedBytes))
                {
                    using (InflaterInputStream str = new InflaterInputStream(compressedSubtitle))
                    {
                        using (FileStream outputSubtitle = new FileStream(destPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            byte[] buffer = new byte[65536];
                            int read = 0;
                            do
                            {
                                read = str.Read(buffer, 0, buffer.Length);
                                if (read > 0)
                                {
                                    outputSubtitle.Write(buffer, 0, read);
                                }
                            }
                            while (read > 0);
                        }
                    }
                }

                return destPath;
            }

            return string.Empty;
        }