Exemple #1
0
        public BookFile CalibreAddAndConvert(BookFile file, CalibreSettings settings)
        {
            _logger.Trace($"Importing to calibre: {file.Path}");

            if (file.CalibreId == 0)
            {
                var import = _calibre.AddBook(file, settings);
                file.CalibreId = import.Id;
            }
            else
            {
                _calibre.AddFormat(file, settings);
            }

            _calibre.SetFields(file, settings);

            var updated = _calibre.GetBook(file.CalibreId, settings);
            var path    = updated.Formats.Values.OrderByDescending(x => x.LastModified).First().Path;

            file.Path = path;

            _rootFolderWatchingService.ReportFileSystemChangeBeginning(file.Path);

            if (settings.OutputFormat.IsNotNullOrWhiteSpace())
            {
                _logger.Trace($"Getting book data for {file.CalibreId}");
                var options     = _calibre.GetBookData(file.CalibreId, settings);
                var inputFormat = file.Quality.Quality.Name.ToUpper();

                options.Conversion_options.Input_fmt = inputFormat;

                var formats = settings.OutputFormat.Split(',').Select(x => x.Trim());
                foreach (var format in formats)
                {
                    if (format.ToLower() == inputFormat ||
                        options.Input_formats.Contains(format, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    options.Conversion_options.Output_fmt = format;

                    if (settings.OutputProfile != (int)CalibreProfile.Default)
                    {
                        options.Conversion_options.Options.Output_profile = ((CalibreProfile)settings.OutputProfile).ToString();
                    }

                    _logger.Trace($"Starting conversion to {format}");
                    _calibre.ConvertBook(file.CalibreId, options.Conversion_options, settings);
                }
            }

            return(file);
        }
        public static RootFolder ToModel(this RootFolderResource resource)
        {
            if (resource == null)
            {
                return(null);
            }

            CalibreSettings cs;

            if (resource.IsCalibreLibrary)
            {
                cs = new CalibreSettings
                {
                    Host          = resource.Host,
                    Port          = resource.Port,
                    UrlBase       = resource.UrlBase,
                    Username      = resource.Username,
                    Password      = resource.Password,
                    Library       = resource.Library,
                    OutputFormat  = resource.OutputFormat,
                    OutputProfile = (int)Enum.Parse(typeof(CalibreProfile), resource.OutputProfile, true),
                    UseSsl        = resource.UseSsl
                };
            }
            else
            {
                cs = null;
            }

            return(new RootFolder
            {
                Id = resource.Id,
                Name = resource.Name,
                Path = resource.Path,

                DefaultMetadataProfileId = resource.DefaultMetadataProfileId,
                DefaultQualityProfileId = resource.DefaultQualityProfileId,
                DefaultMonitorOption = resource.DefaultMonitorOption,
                DefaultNewItemMonitorOption = resource.DefaultNewItemMonitorOption,
                DefaultTags = resource.DefaultTags,
                IsCalibreLibrary = resource.IsCalibreLibrary,
                CalibreSettings = cs
            });
        }
 private string GetLibraryUri(CalibreSettings settings)
 {
     return(HttpUri.CombinePath(HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase), settings.Library));
 }