Esempio n. 1
0
 /// <summary>
 /// Extracts the tools.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="zipFileResourcePath">The zip file resource path.</param>
 /// <param name="targetPath">The target path.</param>
 private void ExtractTools(Assembly assembly, string zipFileResourcePath, string targetPath)
 {
     using (var resourceStream = assembly.GetManifestResourceStream(zipFileResourcePath))
     {
         _zipClient.ExtractAll(resourceStream, targetPath, false);
     }
 }
        /// <summary>
        /// Extracts the tools.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="zipFileResourcePath">The zip file resource path.</param>
        /// <param name="targetPath">The target path.</param>
        private async void ExtractTools(Assembly assembly, string zipFileResourcePath, string targetPath)
        {
            using (var resourceStream = assembly.GetManifestResourceStream(zipFileResourcePath))
            {
                _zipClient.ExtractAll(resourceStream, targetPath, false);
            }

            try
            {
                await DownloadFonts(targetPath).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error getting ffmpeg font files", ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Downloads the series zip.
        /// </summary>
        /// <param name="seriesId">The series id.</param>
        /// <param name="seriesDataPath">The series data path.</param>
        /// <param name="lastTvDbUpdateTime">The last tv database update time.</param>
        /// <param name="preferredMetadataLanguage">The preferred metadata language.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        internal async Task DownloadSeriesZip(string seriesId, string seriesDataPath, long?lastTvDbUpdateTime, string preferredMetadataLanguage, CancellationToken cancellationToken)
        {
            var url = string.Format(SeriesGetZip, TVUtils.TvdbApiKey, seriesId, preferredMetadataLanguage);

            using (var zipStream = await _httpClient.Get(new HttpRequestOptions
            {
                Url = url,
                ResourcePool = TvDbResourcePool,
                CancellationToken = cancellationToken
            }).ConfigureAwait(false))
            {
                // Delete existing files
                DeleteXmlFiles(seriesDataPath);

                // Copy to memory stream because we need a seekable stream
                using (var ms = new MemoryStream())
                {
                    await zipStream.CopyToAsync(ms).ConfigureAwait(false);

                    ms.Position = 0;
                    _zipClient.ExtractAll(ms, seriesDataPath, true);
                }
            }

            // Sanitize all files, except for extracted episode files
            foreach (var file in Directory.EnumerateFiles(seriesDataPath, "*.xml", SearchOption.AllDirectories).ToList()
                     .Where(i => !Path.GetFileName(i).StartsWith("episode-", StringComparison.OrdinalIgnoreCase)))
            {
                await SanitizeXmlFile(file).ConfigureAwait(false);
            }

            await ExtractEpisodes(seriesDataPath, Path.Combine(seriesDataPath, preferredMetadataLanguage + ".xml"), lastTvDbUpdateTime).ConfigureAwait(false);
        }
Esempio n. 4
0
 private void ExtractBytes(byte[] comBin, string dlPath, IZipClient zipClient)
 {
     using (MemoryStream ms = new MemoryStream(comBin))
     {
         _logger.Debug("ExtractBytes: {0}", dlPath);
         zipClient.ExtractAll(ms, dlPath, true);
     }
 }
 private void ExtractBytes(string filename, string dlPath, IZipClient zipClient)
 {
     using (var stream = GetType().Assembly.GetManifestResourceStream(GetType().Namespace + ".FilterZips." + filename))
     {
         _logger.Info("ExtractBytes: {0}", dlPath);
         zipClient.ExtractAll(stream, dlPath, true);
     }
 }
Esempio n. 6
0
        private static void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            try
            {
                Uri    objManifest     = new Uri(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], "manifest.txt"));
                string dlPath          = objDlPath.ToString();
                string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                using (WebClient mwc = new WebClient())
                {
                    string dlList = mwc.DownloadString(objManifest);
                    if (!string.IsNullOrWhiteSpace(dlList))
                    {
                        string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string toCheck in objToCheck)
                        {
                            string         txtPath    = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                            DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                            Uri            comPath    = new Uri(Path.Combine(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], toCheck)));
                            WebRequest     request    = WebRequest.Create(comPath);
                            request.Method = "HEAD";

                            using (WebResponse wr = request.GetResponse())
                            {
                                DateTime lmDate;
                                if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                {
                                    if (lmDate > lastUpdate.StoredDate)
                                    {
                                        //download the updated component
                                        using (WebClient fd = new WebClient())
                                        {
                                            fd.DownloadProgressChanged += fd_DownloadProgressChanged;
                                            byte[] comBin = fd.DownloadData(comPath);
                                            if (comBin.Length > 0)
                                            {
                                                using (MemoryStream ms = new MemoryStream(comBin))
                                                {
                                                    zipClient.ExtractAll(ms, dlPath, true);
                                                }

                                                DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 7
0
        public async Task <SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken, int depth = 0)
        {
            var idParts  = LegendasTVIdParts.parse(id);
            var savePath = $"{_appPaths.TempDirectory}{_fileSystem.DirectorySeparatorChar}{Name}_{idParts.downloadId}";

            var requestOptions = new HttpRequestOptions()
            {
                Url = string.Format(URL_BASE + "/downloadarquivo/" + idParts.downloadId),
                CancellationToken = cancellationToken,
            };

            try
            {
                using (var stream = await _httpClient.Get(requestOptions))
                {
                    _logger.Info("Extracting file to " + savePath);
                    _zipClient.ExtractAll(stream, savePath, true);
                }
            }
            catch (System.Exception)
            {
                if (depth < 1 && await Login())
                {
                    return(await GetSubtitles(id, cancellationToken, depth + 1));
                }
                else
                {
                    throw;
                }
            }

            var media         = _libraryManager.GetItemById(idParts.idMedia);
            var subtitleFiles = _fileSystem.GetFiles(savePath, new string[] { ".srt", ".ass" }, false, true);
            var bestCandidate = FindBestCandidate(media.FileNameWithoutExtension, subtitleFiles);

            _logger.Info("Best subtitle found: " + bestCandidate);

            var ms = new MemoryStream();
            await _fileSystem.GetFileStream(bestCandidate, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read).CopyToAsync(ms);

            ms.Position = 0;

            return(new SubtitleResponse()
            {
                Format = "srt",
                IsForced = false,
                Stream = ms,
                Language = idParts.language
            });
        }
        /// <summary>
        /// Downloads the series zip.
        /// </summary>
        /// <param name="seriesId">The series id.</param>
        /// <param name="seriesDataPath">The series data path.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        internal async Task DownloadSeriesZip(string seriesId, string seriesDataPath, CancellationToken cancellationToken)
        {
            var url = string.Format(SeriesGetZip, TVUtils.TvdbApiKey, seriesId, ConfigurationManager.Configuration.PreferredMetadataLanguage);

            using (var zipStream = await HttpClient.Get(new HttpRequestOptions
            {
                Url = url,
                ResourcePool = TvDbResourcePool,
                CancellationToken = cancellationToken
            }).ConfigureAwait(false))
            {
                // Copy to memory stream because we need a seekable stream
                using (var ms = new MemoryStream())
                {
                    await zipStream.CopyToAsync(ms).ConfigureAwait(false);

                    ms.Position = 0;
                    _zipClient.ExtractAll(ms, seriesDataPath, true);
                }
            }
        }
Esempio n. 9
0
 private void ExtractBytes(byte[] comBin, string dlPath, IZipClient zipClient)
 {
     using (MemoryStream ms = new MemoryStream(comBin))
     {
         _logger.Debug("ExtractBytes: {0}", dlPath);
         zipClient.ExtractAll(ms, dlPath, true);
     }
 }
        private static void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            try
            {
                Uri objManifest = new Uri(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], "manifest.txt"));
                string dlPath = objDlPath.ToString();
                string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                using (WebClient mwc = new WebClient())
                {
                    string dlList = mwc.DownloadString(objManifest);
                    if (!string.IsNullOrWhiteSpace(dlList))
                    {
                        string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string toCheck in objToCheck)
                        {
                            string txtPath = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                            DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                            Uri comPath = new Uri(Path.Combine(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], toCheck)));
                            WebRequest request = WebRequest.Create(comPath);
                            request.Method = "HEAD";

                            using (WebResponse wr = request.GetResponse())
                            {
                                DateTime lmDate;
                                if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                {
                                    if (lmDate > lastUpdate.StoredDate)
                                    {
                                        //download the updated component
                                        using (WebClient fd = new WebClient())
                                        {
                                            fd.DownloadProgressChanged += fd_DownloadProgressChanged;
                                            byte[] comBin = fd.DownloadData(comPath);
                                            if (comBin.Length > 0)
                                            {
                                                using (MemoryStream ms = new MemoryStream(comBin))
                                                {
                                                    zipClient.ExtractAll(ms, dlPath, true);
                                                }

                                                DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
            }
            catch (Exception ex)
            {
            }
        }