This commit is contained in:
2025-02-03 14:58:49 +01:00
commit 13c26eb3d8
13 changed files with 818 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using System.IO;
using System.Text.Json;
using System.Windows;
namespace Bokhantarare;
public class BareBookInfo(string editionId, string title, string? workId = null)
{
string WorkID { get; set; } = workId??"";
string EditionID { get; set; } = editionId;
string Title { get; set; } = title;
public Book getBook()
{
Dictionary<String, Object>? responce = JsonSerializer.Deserialize<Dictionary<String, Object>>(
Helper.Request($"https://openlibrary.org/books/{EditionID}.json"));
if (responce == null)
{
throw new Exception("Failed to get book info");
}
object? isbn_13_raw_array = 0;
if (responce.ContainsKey("isbn_13"))
{
isbn_13_raw_array = responce["isbn_13"];
}
else if(responce.ContainsKey("isbn_10"))
{
isbn_13_raw_array = responce["isbn_10"];
}
else
{
throw new Exception("Failed to get ISBN");
}
if (isbn_13_raw_array == null)
{
throw new Exception("Failed to get book info");
}
List<string> isbn_13_array = JsonSerializer.Deserialize<List<string>>(isbn_13_raw_array.ToString());
return Book.GetBookFromISBN(isbn_13_array[0])??throw new Exception("Failed to get book info");
}
public override string ToString()
{
return Title;
}
}