public ILocalSubtitleFinder CreateLocalSubtitleFinderByVideo(Video video, ILogger logger)
        {
            if (video.VideoFileCount() > 1)
                return new MultiFileSubtitleFinder(video, logger);

            return new SingleFileSubtitleFinder(video, logger, extendedLogging);
        }
        public ISubtitleExtractor CreateSubtitleExtractorByVideo(Video video)
        {
            if (video.VideoFileCount() > 1)
                return new MultiFileSubtitleExtractor(video);

            return new SubtitleExtractor(video);
        }
        protected override IEnumerable<Subtitle> Find(Video video, List<string> languages)
        {
            var videoHashString = video.GetVideoHashString();
            var videoSize = video.GetVideoSize();

            var subtitleCollection = this.FindSubtitlesByHash(video, videoHashString, videoSize, languages);

            return subtitleCollection;
        }
예제 #4
0
        public List<Subtitle> GetBlackListedSubtitles(Video video)
        {
            lock (this)
            {
                var xml = XDocument.Load(xmlFilePath);
                var videoElement = this.GetVideoElement(video, xml);

                var blackListedElement = videoElement.Element("BlackListedSubtitles");

                var blackListedSubtitles = (from s in blackListedElement.Elements()
                                            select new Subtitle(video.Name, s.Element("Language").Value, s.Element("Url").Value)).ToList();

                return blackListedSubtitles;
            }
        }
예제 #5
0
        public void BlackListSubtitle(Video video, Subtitle subtitle)
        {
            lock (this)
            {

                if (subtitle.UrlToFile == "")
                    return;

                var xml = XDocument.Load(xmlFilePath);
                var videoElement = this.GetVideoElement(video, xml);

                var blacklistedElement = videoElement.Element("BlackListedSubtitles");
                var newBlacklistedElement = new XElement("BlackListedSubtitle",
                                                         new XElement("Language", subtitle.Langugage),
                                                         new XElement("Url", subtitle.UrlToFile));

                if (blacklistedElement != null) blacklistedElement.Add(newBlacklistedElement);

                xml.Save(xmlFilePath);
            }
        }
예제 #6
0
        public Subtitle GetCurrentSubtitle(Video video)
        {
            lock (this)
            {
                var xml = XDocument.Load(xmlFilePath);

                var videoElement = this.GetVideoElement(video, xml);
                var subtitleElement = videoElement.Element("CurrentSubtitle");

                if (subtitleElement == null)
                {
                    return new Subtitle("", "", "");
                }

                var language = (string)subtitleElement.Element("Language");
                var url = (string)subtitleElement.Element("Url");

                var subtitle = new Subtitle(video.Name, language, url);

                return subtitle;
            }
        }
        private IEnumerable<Subtitle> CreateSubtitlesFromReturnData(IEnumerable<string> languages, XmlRpcStruct subtitles, Video video)
        {
            if (subtitles == null || subtitles.Count < 1)
                return null;

            var data = subtitles["data"] as object[];

            if (data == null)
                return null;

            var subtitleCollection = new List<Subtitle>();
            foreach (Hashtable subtitleStructure in data)
            {
                var subtitleLanguage = (string)subtitleStructure["LanguageName"];

                var subtitle = new Subtitle(video.Name, subtitleLanguage, (string)subtitleStructure["ZipDownloadLink"]);
                subtitleCollection.Add(subtitle);

            }

            return subtitleCollection;
        }
 public MultiFileSubtitleFinder(Video video, ILogger logger)
 {
     this.video = video;
     this.logger = logger;
 }
 public MultiFileSubtitleExtractor(Video video)
     : base(video)
 {
 }
 public BlackListingProvider(Video video, IDataSource dataSource)
 {
     this.video = video;
     this.dataSource = dataSource;
 }
 public BlackListingProvider(Video video)
     : this(video, DataSourceFactory.CreateDataSource())
 {
 }
예제 #12
0
        public void SetCurrentSubtitle(Video video, Subtitle subtitle)
        {
            lock (this)
            {
                var xml = XDocument.Load(xmlFilePath);

                var videoElement = this.GetVideoElement(video, xml);

                var subtitleElement = videoElement.Element("CurrentSubtitle");
                if (subtitleElement != null) subtitleElement.Remove();

                var newSubtitleElement = new XElement("CurrentSubtitle",
                                                   new XElement("Language", subtitle.Langugage),
                                                   new XElement("Url", subtitle.UrlToFile));

                videoElement.Add(newSubtitleElement);

                xml.Save(xmlFilePath);
            }
        }
예제 #13
0
        private XElement GetVideoElement(Video video, XDocument xml)
        {
            var providerElement = xml.Element("SubtitleProvider");
            if (providerElement != null)
            {
                var videoElement = (from s in providerElement.Elements("Video")
                                    where (string)s.Attribute("name") == video.Name
                                    select s).SingleOrDefault();

                return videoElement ?? this.CreateVideoElement(video, xml);
            }
            return null;
        }
예제 #14
0
        private XElement CreateVideoElement(Video video, XDocument document)
        {
            var newVideoElement = new XElement("Video",
                new XAttribute("name", video.Name),
                 new XElement("CurrentSubtitle",
                                   new XElement("Language", ""),
                                   new XElement("Url", "")),
                 new XElement("BlackListedSubtitles"));

            var element = document.Element("SubtitleProvider");

            if (element != null) element.Add(newVideoElement);

            return newVideoElement;
        }
        private IEnumerable<Subtitle> FindSubtitlesByHash(Video video, string videoHash, long videoSize, List<string> languages)
        {
            var token = LoginToOpenSubtitles();

            var searchArray = CreateSearchArray(languages, videoHash, videoSize);

            var subtitles = GetSubtitles(token, searchArray);

            var subtitleCollection = CreateSubtitlesFromReturnData(languages, subtitles, video);

            LogOutFromOpenSubtitles(token);

            return subtitleCollection;
        }
 public SingleFileSubtitleFinder(Video video, ILogger logger, bool extendedLogging)
 {
     this.video = video;
     this.logger = logger;
     this.extendedLogging = extendedLogging;
 }