public frmGR(BookInfo[] bookList, ISecondarySource source) { InitializeComponent(); _bookList = bookList; lblID.Text = $"{source.Name} ID:"; linkID.Location = new Point(lblID.Location.X + lblID.Width - 4, linkID.Location.Y); }
public async Task <XRay> CreateXRayAsync( string dataLocation, string db, string guid, string asin, string tld, bool includeTopics, ISecondarySource dataSource, IProgressBar progress, CancellationToken token = default) { var xray = new XRay(dataLocation, db, guid, asin, dataSource) { Terms = (await dataSource.GetTermsAsync(dataLocation, asin, tld, includeTopics, progress, token)).ToList() }; if (dataSource.SupportsNotableClips) { _logger.Log("Downloading notable clips..."); xray.NotableClips = (await dataSource.GetNotableClipsAsync(dataLocation, null, progress, token))?.ToList(); } if (xray.Terms.Count == 0) { _logger.Log("Warning: No terms found on " + dataSource.Name + "."); } return(xray); }
/// <summary> /// Downloads terms from the <paramref name="dataSource"/> and saves them to <paramref name="outFile"/> /// </summary> public async Task DownloadAndSaveAsync(ISecondarySource dataSource, string dataUrl, string outFile, string asin, string tld, bool includeTopics, IProgressBar progress, CancellationToken token = default) { var terms = (await dataSource.GetTermsAsync(dataUrl, asin, tld, includeTopics, progress, token)).ToArray(); if (terms.Length == 0) { throw new Exception($"No terms were found on {dataSource.Name}"); } XmlUtil.SerializeToFile(terms, outFile); }
public XRay(string shelfari, ISecondarySource dataSource, ILogger logger, ChaptersService chaptersService) { if (!shelfari.ToLower().StartsWith("http://") && !shelfari.ToLower().StartsWith("https://")) { shelfari = "https://" + shelfari; } DataUrl = shelfari; DataSource = dataSource; _logger = logger; _chaptersService = chaptersService; }
// TODO fix this constructor crap public XRay(string xml, string db, string guid, string asin, ISecondarySource dataSource, bool xmlUgh) { if (xml == "" || db == "" || guid == "" || asin == "") { throw new ArgumentException("Error initializing X-Ray, one of the required parameters was blank."); } DatabaseName = db; Guid = guid; Asin = asin; DataSource = dataSource; SkipShelfari = true; }
public async Task <BookInfo[]> SearchSecondarySourceAsync(ISecondarySource dataSource, IMetadata metadata, CancellationToken cancellationToken = default) { var results = (await dataSource.SearchBookAsync(metadata, cancellationToken)).ToArray(); if (results.Length == 1) { return(results); } return(results .OrderByDescending(book => book.Editions) .ThenByDescending(book => book.Reviews) .ToArray()); }
private void SetDatasourceLabels() { // todo: use enum directly for setting - consider passing enum vs datasource var datasource = (SecondaryDataSourceFactory.Enum)Enum.Parse(typeof(SecondaryDataSourceFactory.Enum), _settings.dataSource); _dataSource = _diContainer.GetInstance <SecondaryDataSourceFactory>().Get(datasource); btnSearchGoodreads.Enabled = _dataSource.SearchEnabled; lblGoodreads.Left = _dataSource.UrlLabelPosition; rdoGoodreads.Text = _dataSource.Name; lblGoodreads.Text = $"{_dataSource.Name} URL:"; _tooltip.SetToolTip(btnDownloadTerms, $"Save {_dataSource.Name} info to an XML file."); _tooltip.SetToolTip(btnSearchGoodreads, _dataSource.SearchEnabled ? $"Try to search for this book on {_dataSource.Name}." : $"Search is disabled when {_dataSource.Name} is selected as a data source."); }
// TODO fix this constructor crap public XRay(string xml, string db, string guid, string asin, ISecondarySource dataSource, ILogger logger, ChaptersService chaptersService, bool xmlUgh, int locOffset = 0, string aliaspath = "") { if (xml == "" || db == "" || guid == "" || asin == "") { throw new ArgumentException("Error initializing X-Ray, one of the required parameters was blank."); } xmlFile = xml; databaseName = db; Guid = guid; Asin = asin; this.locOffset = locOffset; _aliasPath = aliaspath; DataSource = dataSource; _logger = logger; _chaptersService = chaptersService; SkipShelfari = true; }
public async Task <XRay> CreateXRayAsync( string dataLocation, string db, string guid, string asin, string tld, bool includeTopics, ISecondarySource dataSource, IProgressBar progress, CancellationToken token = default) { if (dataLocation == "" && !(dataSource is SecondarySourceRoentgen) || guid == "" || asin == "") { throw new ArgumentException("Error initializing X-Ray, one of the required parameters was blank."); } dataLocation = dataSource.SanitizeDataLocation(dataLocation); var terms = (await dataSource.GetTermsAsync(dataLocation, asin, tld, includeTopics, progress, token)).ToList(); var xray = new XRay { DatabaseName = string.IsNullOrEmpty(db) ? null : db, Guid = Functions.ConvertGuid(guid), Asin = asin, DataUrl = dataLocation, Terms = terms }; if (dataSource.SupportsNotableClips) { _logger.Log("Downloading notable clips..."); xray.NotableClips = (await dataSource.GetNotableClipsAsync(dataLocation, null, progress, token))?.ToList(); } if (xray.Terms.Count == 0) { _logger.Log($"Warning: No terms found on {dataSource.Name}."); } return(xray); }
public async Task <BookInfo[]> SearchSecondarySourceAsync(ISecondarySource dataSource, Parameters parameters, CancellationToken cancellationToken = default) { var books = new BookInfo[0]; // If ASIN is available, use it to search first before falling back to author/title if (!string.IsNullOrEmpty(parameters.Asin)) { books = (await dataSource.SearchBookByAsinAsync(parameters.Asin, cancellationToken)).ToArray(); } if (books.Length <= 0) { books = (await dataSource.SearchBookAsync(parameters.Author, parameters.Title, cancellationToken)).ToArray(); } return(books.OrderByDescending(book => book.Reviews) .ThenByDescending(book => book.Editions) .ToArray()); }
public XRay(string shelfari, string db, string guid, string asin, ISecondarySource dataSource) { if ((shelfari == "" && !(dataSource is SecondarySourceRoentgen)) || db == "" || guid == "" || asin == "") { throw new ArgumentException("Error initializing X-Ray, one of the required parameters was blank."); } if (!shelfari.ToLower().StartsWith("http://") && !shelfari.ToLower().StartsWith("https://")) { shelfari = "https://" + shelfari; } DataUrl = shelfari; DatabaseName = db; if (guid != null) { Guid = guid; } Asin = asin; DataSource = dataSource; }
public void ExportAndDisplayTerms(XRay xray, ISecondarySource dataSource, bool overwriteAliases, bool splitAliases) { //Export available terms to a file to make it easier to create aliases or import the modified aliases if they exist //Could potentially just attempt to automate the creation of aliases, but in some cases it is very subjective... //For example, Shelfari shows the character "Artemis Fowl II", but in the book he is either referred to as "Artemis Fowl", "Artemis", or even "Arty" //Other characters have one name on Shelfari but can have completely different names within the book var aliasesDownloaded = false; // TODO: Review this download process //if ((!File.Exists(AliasPath) || Properties.Settings.Default.overwriteAliases) && Properties.Settings.Default.downloadAliases) //{ // aliasesDownloaded = await AttemptAliasDownload(); //} var aliasPath = _directoryService.GetAliasPath(xray.Asin); if (!aliasesDownloaded && (!File.Exists(aliasPath) || overwriteAliases)) { // overwrite path in case it waas changed within the service aliasPath = _aliasesRepository.SaveCharactersToFile(xray.Terms, xray.Asin, splitAliases); if (aliasPath != null) { _logger.Log($"Characters exported to {aliasPath} for adding aliases."); } } var termsFound = $"{xray.Terms.Count} {(xray.Terms.Count > 1 ? "terms" : "term")} found"; _logger.Log($"{termsFound} on {dataSource.Name}:"); var str = new StringBuilder(xray.Terms.Count * 32); // Assume that most names will be less than 32 chars var termId = 1; foreach (var t in xray.Terms) { str.Append(t.TermName).Append(", "); // todo don't set the IDs here... t.Id = termId++; } _logger.Log(str.ToString()); }
//Requires an already-built AuthorProfile and the BaseEndActions.txt file // TODO Move non-DI params from constructor to function public EndActions( AuthorProfileGenerator.Response authorProfile, BookInfo book, long erl, ISecondarySource dataSource, Settings settings, Func <string, string, string> asinPrompt, ILogger logger, IHttpClient httpClient, IAmazonClient amazonClient, IAmazonInfoParser amazonInfoParser) { _authorProfile = authorProfile; curBook = book; _erl = erl; _dataSource = dataSource; _settings = settings; _asinPrompt = asinPrompt; _logger = logger; _httpClient = httpClient; _amazonClient = amazonClient; _amazonInfoParser = amazonInfoParser; }
public XRay(string shelfari, string db, string guid, string asin, ISecondarySource dataSource, ILogger logger, ChaptersService chaptersService, int locOffset = 0, string aliaspath = "") { if (shelfari == "" || db == "" || guid == "" || asin == "") { throw new ArgumentException("Error initializing X-Ray, one of the required parameters was blank."); } if (!shelfari.ToLower().StartsWith("http://") && !shelfari.ToLower().StartsWith("https://")) { shelfari = "https://" + shelfari; } DataUrl = shelfari; databaseName = db; if (guid != null) { Guid = guid; } Asin = asin; this.locOffset = locOffset; _aliasPath = aliaspath; DataSource = dataSource; _logger = logger; _chaptersService = chaptersService; }
public async Task <Response> GenerateNewFormatData( BookInfo curBook, Settings settings, ISecondarySource dataSource, AuthorProfileGenerator.Response authorProfile, Func <string, string, string> asinPrompt, IMetadata metadata, IProgressBar progress, CancellationToken cancellationToken = default) { // Generate old stuff first, ignore response since curBook and custAlsoBought are shared // todo make them not shared var oldResponse = await GenerateOld(curBook, settings, cancellationToken); if (oldResponse == null) { return(null); } try { await dataSource.GetExtrasAsync(curBook, progress, cancellationToken); curBook.Series = await dataSource.GetSeriesInfoAsync(curBook.DataUrl, cancellationToken); if (curBook.Series == null || curBook.Series.Total == 0) { _logger.Log("The book was not found to be part of a series."); } else if (curBook.Series.Next == null && curBook.Series.Position != curBook.Series.Total.ToString())// && !curBook.Series.Position?.Contains(".") == true) { _logger.Log("An error occurred finding the next book in series. The book may not be part of a series, or it is the latest release."); } else { await ExpandSeriesMetadata(authorProfile, curBook.Series, settings, asinPrompt, cancellationToken); } } catch (Exception ex) { if (ex.Message.Contains("(404)")) { _logger.Log("An error occurred finding next book in series: Goodreads URL not found.\r\n" + "If reading from a file, you can switch the source to Goodreads to specify a URL, then switch back to File."); } else { _logger.Log("An error occurred finding next book in series: " + ex.Message + "\r\n" + ex.StackTrace); } throw; } // TODO: Refactor next/previous series stuff if (curBook.Series?.Next == null) { try { var seriesResult = await _roentgenClient.DownloadNextInSeriesAsync(curBook.Asin, cancellationToken); switch (seriesResult?.Error?.ErrorCode) { case "ERR004": _logger.Log("According to Amazon, this book is not part of a series."); break; case "ERR000": if (curBook.Series == null) { curBook.Series = new SeriesInfo(); } curBook.Series.Next = new BookInfo(seriesResult.NextBook.Title.TitleName, Functions.FixAuthor(seriesResult.NextBook.Authors.FirstOrDefault()?.AuthorName), seriesResult.NextBook.Asin); var response = await _amazonInfoParser.GetAndParseAmazonDocument(curBook.Series.Next.AmazonUrl, cancellationToken); response.ApplyToBookInfo(curBook.Series.Next); break; } } catch { // Ignore } } if (curBook.Series != null) { _logger.Log($"\nSeries URL: {curBook.Series.Url}"); if (!string.IsNullOrEmpty(curBook.Series.Name)) { _logger.Log($"This is book {curBook.Series.Position} of {curBook.Series.Total} in the {curBook.Series.Name} series"); } if (curBook.Series.Previous != null) { _logger.Log($"Preceded by: {curBook.Series.Previous.Title}"); } if (curBook.Series.Next != null) { _logger.Log($"Followed by: {curBook.Series.Next.Title}\n"); } } try { if (!await dataSource.GetPageCountAsync(curBook, cancellationToken)) { var metadataCount = metadata.GetPageCount(); if (metadataCount.HasValue) { curBook.PagesInBook = metadataCount.Value; } else if (settings.EstimatePageCount) { _logger.Log("No page count found on Goodreads or in metadata. Attempting to estimate page count..."); _logger.Log(Functions.GetPageCount(curBook.RawmlPath, curBook)); } else { _logger.Log("No page count found on Goodreads or in metadata"); } } } catch (Exception ex) { _logger.Log("An error occurred while searching for or estimating the page count: " + ex.Message + "\r\n" + ex.StackTrace); throw; } return(new Response { Book = curBook, CustomerAlsoBought = oldResponse.CustomerAlsoBought }); }