private void SetIndustrialIdentifier(Rootobject root, int i, PocoBook abook) { if (root.items[i].volumeInfo.industryIdentifiers != null && root.items[i].volumeInfo.industryIdentifiers.Length == 1) { abook.Isbn = root.items[i].volumeInfo.industryIdentifiers[0].identifier; } if (root.items[i].volumeInfo.industryIdentifiers != null && root.items[i].volumeInfo.industryIdentifiers.Length == 2) { if ((root.items[i].volumeInfo.industryIdentifiers[1].type == "ISBN_13") || root.items[i].volumeInfo.industryIdentifiers[0].type == "ISBN_13") { abook.Isbn = root.items[i].volumeInfo.industryIdentifiers[1].identifier; } else { if ((root.items[i].volumeInfo.industryIdentifiers[1].type == "ISBN_10") || root.items[i].volumeInfo.industryIdentifiers[0].type == "ISBN_10") { abook.Isbn = root.items[i].volumeInfo.industryIdentifiers[1].identifier; } } } if (abook.Isbn == null) { //maybe a personal doc string personalId = BytesToString(GetHashSha256(abook.File)); abook.Isbn = String.Format("PersonalID<{0}>", Guid.NewGuid()); } }
private BookAtHome SearchBookInfoOfFile(string file) { _tracer?.TraceInfo("SearchBookInfoOfFile start for file {0}", file); try { PocoBook minimalbookinfo = GetMetadataFromFileDictionaryDelegate[Utils.GetExtension(file)].DynamicInvoke(file) as PocoBook; IBooksProvider libraryBookProvider = PluginLoader.GetPluginFromFolder(Configuration.providerPlugin.pluginassemblyname, Configuration.providerPlugin.pluginfolder); //TODO: performace improvments List <PocoBook> booksFromProvider = libraryBookProvider.FetchBookInfo(minimalbookinfo); return(FileExtractor.AnalyzeResults(minimalbookinfo, booksFromProvider, _tracer)); } catch (Exception ex) { if (ex is KeyNotFoundException || ex is InvalidOperationException || ex is ArgumentNullException || ex is System.Reflection.TargetInvocationException) { return(new BookToBeReviewed(file, ex.Message)); } throw; } }
public void Append(PocoBook abook) { lock (_object) { Library.Add(abook); } }
public static bool IsNullOrEmpty(PocoBook instance) { if (instance == null) { return(true); } return(instance == new PocoBook()); }
public override BookatHome GetPocoBook(string filepath) { iText.Kernel.Pdf.PdfReader reader = null; iText.Kernel.Pdf.PdfDocument pDoc = null; try { if (File.Exists(filepath)) { reader = new iText.Kernel.Pdf.PdfReader(filepath); pDoc = new iText.Kernel.Pdf.PdfDocument(reader); int nPages = pDoc.GetNumberOfPages(); int maxsearch = nPages < 15 ? nPages : 10; for (int i = 1; i <= maxsearch; i++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(pDoc.GetPage(i), strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); if (currentText.ToLower().Contains("isbn", System.StringComparison.InvariantCulture)) { string pattern = @"ISBN(-1(?:(0)|3))?:?\x20(\s)*[0-9]+[- ][0-9]+[- ][0-9]+[- ][0-9]*[- ]*[xX0-9]"; Match m = Regex.Match(currentText.Replace(":", "").Replace("-", " "), pattern); if (m.Success) { PocoBook retBook = base.GetPocoBook(filepath) as PocoBook; retBook.Isbnsearch = m.Value; return(retBook); } } } reader.Close(); } } catch (IOException) { return(new PocoBook(filepath)); } finally { ((IDisposable)reader)?.Dispose(); ((IDisposable)pDoc)?.Dispose(); } return(base.GetPocoBook(filepath)); }
private Rootobject ExecuteGoogleRequest(PocoBook book, IRestClient restclient, IBookParserTrace trace) { trace.TraceInfo("GetBooks start for book {0}", book.Title); string url = String.Format("https://www.googleapis.com/books/v1/volumes?q={0}&maxResults=40&country=IT", BuildQuery(book)); Rootobject root = GoogleRestBooksRequest(restclient, url); if (root == null) { string query = string.Format("intitle:{0}", book.Title); url = String.Format("https://www.googleapis.com/books/v1/volumes?q={0}&maxResults=40&country=IT", query); return(GoogleRestBooksRequest(restclient, url)); } else { return(root); } }
private static string BuildQuery(PocoBook book) { string query; if (!string.IsNullOrEmpty(book.Isbnsearch)) { query = "isbn:" + book.Isbnsearch.Replace("-", "").Replace("ISBN", "", true, null).Replace(" ", ""); } else { if (book.Authors == null || book.Authors.Length == 0) { query = string.Format("intitle:{0}", book.SearchTitle); } else { query = string.Format("intitle:{0}&inauthor:{1}", book.SearchTitle, string.Join(", ", book.Authors)); } } return(query); }
public bool Equals(PocoBook p) { // If parameter is null, return false. if (Object.ReferenceEquals(p, null)) { return(false); } // Optimization for a common success case. if (Object.ReferenceEquals(this, p)) { return(true); } // If run-time types are not exactly the same, return false. if (this.GetType() != p.GetType()) { return(false); } return(this.ToString() == p.ToString()); }
public static BookatHome AnalyzeResults(PocoBook minimalbookinfo, List <PocoBook> booksFromProvider, IBookParserTrace trace) { trace?.TraceInfo("AnalyzeResults start"); if (booksFromProvider == null || booksFromProvider.Count == 0) { if (!String.IsNullOrEmpty(minimalbookinfo?.Title) && minimalbookinfo.Authors.Count != 0) { minimalbookinfo.BookReliability = PocoBook.Reliability.Medium; return(minimalbookinfo); } throw new ArgumentNullException(nameof(booksFromProvider)); } if (booksFromProvider.Count == 1) { booksFromProvider[0].BookReliability = PocoBook.Reliability.High; return(booksFromProvider.First()); } return(FindTheBookInfoFromCollection(minimalbookinfo.File, booksFromProvider, minimalbookinfo.SearchTitle, trace)); }
private List <PocoBook> GetBookFromRest(Rootobject root, string filename) { if (root == null || root.items == null) { return(new List <PocoBook>()); } List <PocoBook> retval = new List <PocoBook>(); for (int i = 0; i < root.items.Length; i++) { PocoBook abook = new PocoBook(filename, root.items[i].volumeInfo.title, root.items[i].volumeInfo.authors, string.Empty, string.Empty) { Categories = root.items[i].volumeInfo.categories, Description = root.items[i].volumeInfo.description, Language = root.items[i].volumeInfo.language, Publisher = root.items[i].volumeInfo.publisher }; DateTime pubDate; if (DateTime.TryParse(root.items[i].volumeInfo.publishedDate, out pubDate) != true) { string[] formats = { "yyyy" }; DateTime.TryParseExact(root.items[i].volumeInfo.publishedDate, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out pubDate); } SetIndustrialIdentifier(root, i, abook); retval.Add(abook); } return(retval); }
public override List <PocoBook> GetBooks(PocoBook book, IRestClient restclient, IBookParserTrace trace) { Rootobject rootresponse = ExecuteGoogleRequest(book, restclient, trace); return(GetBookFromRest(rootresponse, book.File)); }
public abstract List <PocoBook> GetBooks(PocoBook book, IRestClient restclient, IBookParserTrace trace);