mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 04:34:50 -04:00
Finishing basic sql management.
This commit is contained in:
parent
b74fb83a49
commit
f5811b9ce4
@ -17,10 +17,10 @@ namespace Kyoo.Controllers
|
|||||||
this.libraryManager = libraryManager;
|
this.libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/browse")]
|
[HttpGet("api/getall")]
|
||||||
public IEnumerable<Show> GetAll()
|
public IEnumerable<Show> GetAll()
|
||||||
{
|
{
|
||||||
return libraryManager.QueryShows(null);//new Show[] { new Show(0, "clannad", "Clannad", null, "Best Anime", Status.Finished, 2007, 2008, "", "", "t", "", "", "TvDB=159|Mal=123") };
|
return libraryManager.QueryShows(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
|
|
||||||
namespace Kyoo.InternalAPI
|
namespace Kyoo.InternalAPI
|
||||||
{
|
{
|
||||||
@ -16,129 +16,137 @@ namespace Kyoo.InternalAPI
|
|||||||
Debug.WriteLine("&Library Manager init");
|
Debug.WriteLine("&Library Manager init");
|
||||||
|
|
||||||
string databasePath = @"C://Projects/database.db";
|
string databasePath = @"C://Projects/database.db";
|
||||||
SQLiteConnection.CreateFile(databasePath);
|
if (!File.Exists(databasePath))
|
||||||
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
|
{
|
||||||
sqlConnection.Open();
|
SQLiteConnection.CreateFile(databasePath);
|
||||||
|
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
|
||||||
|
sqlConnection.Open();
|
||||||
|
|
||||||
string createStatement = @"CREATE TABLE shows(
|
string createStatement = @"CREATE TABLE shows(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
uri TEXT UNIQUE,
|
uri TEXT UNIQUE,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
aliases TEXT,
|
aliases TEXT,
|
||||||
overview TEXT,
|
overview TEXT,
|
||||||
status TEXT,
|
status TEXT,
|
||||||
startYear INTEGER,
|
startYear INTEGER,
|
||||||
endYear INTEGER,
|
endYear INTEGER,
|
||||||
imgPrimary TEXT,
|
imgPrimary TEXT,
|
||||||
imgThumb TEXT,
|
imgThumb TEXT,
|
||||||
imgBanner TEXT,
|
imgBanner TEXT,
|
||||||
imgLogo TEXT,
|
imgLogo TEXT,
|
||||||
imgBackdrop TEXT,
|
imgBackdrop TEXT,
|
||||||
externalIDs TEXT
|
externalIDs TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE seasons(
|
CREATE TABLE seasons(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
seasonNumber INTEGER,
|
seasonNumber INTEGER,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
overview TEXT,
|
overview TEXT,
|
||||||
imgPrimary TEXT,
|
imgPrimary TEXT,
|
||||||
year INTEGER,
|
year INTEGER,
|
||||||
externalIDs TEXT,
|
externalIDs TEXT,
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id)
|
FOREIGN KEY(showID) REFERENCES shows(id)
|
||||||
);
|
);
|
||||||
CREATE TABLE episodes(
|
CREATE TABLE episodes(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
seasonID INTEGER,
|
seasonID INTEGER,
|
||||||
episodeNumber INTEGER,
|
episodeNumber INTEGER,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
overview TEXT,
|
overview TEXT,
|
||||||
imgPrimary TEXT,
|
imgPrimary TEXT,
|
||||||
releaseDate TEXT,
|
releaseDate TEXT,
|
||||||
runtime INTEGER,
|
runtime INTEGER,
|
||||||
externalIDs TEXT,
|
externalIDs TEXT,
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id),
|
FOREIGN KEY(showID) REFERENCES shows(id),
|
||||||
FOREIGN KEY(seasonID) REFERENCES seasons(id)
|
FOREIGN KEY(seasonID) REFERENCES seasons(id)
|
||||||
);
|
);
|
||||||
CREATE TABLE streams(
|
CREATE TABLE streams(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
episodeID INTEGER,
|
episodeID INTEGER,
|
||||||
streamIndex INTEGER,
|
streamIndex INTEGER,
|
||||||
streamType TEXT,
|
streamType TEXT,
|
||||||
codec TEXT,
|
codec TEXT,
|
||||||
language TEXT,
|
language TEXT,
|
||||||
channelLayout TEXT,
|
channelLayout TEXT,
|
||||||
profile TEXT,
|
profile TEXT,
|
||||||
aspectRatio TEXT,
|
aspectRatio TEXT,
|
||||||
bitRate INTEGER,
|
bitRate INTEGER,
|
||||||
sampleRate INTEGER,
|
sampleRate INTEGER,
|
||||||
isDefault BOOLEAN,
|
isDefault BOOLEAN,
|
||||||
isForced BOOLEAN,
|
isForced BOOLEAN,
|
||||||
isExternal BOOLEAN,
|
isExternal BOOLEAN,
|
||||||
height INTEGER,
|
height INTEGER,
|
||||||
width INTEGER,
|
width INTEGER,
|
||||||
frameRate NUMBER,
|
frameRate NUMBER,
|
||||||
level NUMBER,
|
level NUMBER,
|
||||||
pixelFormat TEXT,
|
pixelFormat TEXT,
|
||||||
bitDepth INTEGER,
|
bitDepth INTEGER,
|
||||||
FOREIGN KEY(episodeID) REFERENCES episodes(id)
|
FOREIGN KEY(episodeID) REFERENCES episodes(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE libraries(
|
CREATE TABLE libraries(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
uri TEXT UNIQUE,
|
uri TEXT UNIQUE,
|
||||||
name TEXT
|
name TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE librariesLinks(
|
CREATE TABLE librariesLinks(
|
||||||
librarieID INTEGER,
|
librarieID INTEGER,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
FOREIGN KEY(librarieID) REFERENCES libraries(id),
|
FOREIGN KEY(librarieID) REFERENCES libraries(id),
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id)
|
FOREIGN KEY(showID) REFERENCES shows(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE studios(
|
CREATE TABLE studios(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
uri TEXT UNIQUE,
|
uri TEXT UNIQUE,
|
||||||
name TEXT
|
name TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE studiosLinks(
|
CREATE TABLE studiosLinks(
|
||||||
studioID INTEGER,
|
studioID INTEGER,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
FOREIGN KEY(studioID) REFERENCES studios(id),
|
FOREIGN KEY(studioID) REFERENCES studios(id),
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id)
|
FOREIGN KEY(showID) REFERENCES shows(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE people(
|
CREATE TABLE people(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
uri TEXT UNIQUE,
|
uri TEXT UNIQUE,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
imgPrimary TEXT,
|
imgPrimary TEXT,
|
||||||
externalIDs TEXT
|
externalIDs TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE peopleLinks(
|
CREATE TABLE peopleLinks(
|
||||||
peopleID INTEGER,
|
peopleID INTEGER,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
role TEXT,
|
role TEXT,
|
||||||
type TEXT,
|
type TEXT,
|
||||||
FOREIGN KEY(peopleID) REFERENCES people(id),
|
FOREIGN KEY(peopleID) REFERENCES people(id),
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id)
|
FOREIGN KEY(showID) REFERENCES shows(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE genres(
|
CREATE TABLE genres(
|
||||||
id INTEGER PRIMARY KEY UNIQUE,
|
id INTEGER PRIMARY KEY UNIQUE,
|
||||||
uri TEXT UNIQUE,
|
uri TEXT UNIQUE,
|
||||||
name TEXT
|
name TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE genresLinks(
|
CREATE TABLE genresLinks(
|
||||||
genreID INTEGER,
|
genreID INTEGER,
|
||||||
showID INTEGER,
|
showID INTEGER,
|
||||||
FOREIGN KEY(genreID) REFERENCES genres(id),
|
FOREIGN KEY(genreID) REFERENCES genres(id),
|
||||||
FOREIGN KEY(showID) REFERENCES shows(id)
|
FOREIGN KEY(showID) REFERENCES shows(id)
|
||||||
);";
|
);";
|
||||||
|
|
||||||
SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
|
SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
|
||||||
createCmd.ExecuteNonQuery();
|
createCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
|
||||||
|
sqlConnection.Open();
|
||||||
|
}
|
||||||
|
|
||||||
Debug.WriteLine("&Sql Database initated.");
|
Debug.WriteLine("&Sql Database initated.");
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Kyoo.Models
|
namespace Kyoo.Models
|
||||||
{
|
{
|
||||||
public class Show
|
public class Show
|
||||||
{
|
{
|
||||||
public readonly int id;
|
public readonly long id;
|
||||||
|
|
||||||
public string Uri;
|
public string Uri;
|
||||||
public string Title;
|
public string Title;
|
||||||
public List<string> Aliases;
|
public List<string> Aliases;
|
||||||
public string Overview;
|
public string Overview;
|
||||||
public Status Status;
|
public Status? Status;
|
||||||
|
|
||||||
public int StartYear;
|
public long? StartYear;
|
||||||
public int EndYear;
|
public long? EndYear;
|
||||||
|
|
||||||
public string ImgPrimary;
|
public string ImgPrimary;
|
||||||
public string ImgThumb;
|
public string ImgThumb;
|
||||||
@ -24,7 +25,7 @@ namespace Kyoo.Models
|
|||||||
public string ExternalIDs;
|
public string ExternalIDs;
|
||||||
|
|
||||||
|
|
||||||
public Show(int id, string uri, string title, List<string> aliases, string overview, Status status, int startYear, int endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
|
public Show(long id, string uri, string title, List<string> aliases, string overview, Status? status, long? startYear, long? endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
Uri = uri;
|
Uri = uri;
|
||||||
@ -42,23 +43,22 @@ namespace Kyoo.Models
|
|||||||
ExternalIDs = externalIDs;
|
ExternalIDs = externalIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Cast error here (Unable to cast object of type 'System.Int64' to type 'System.Int32'.)
|
|
||||||
public static Show FromReader(System.Data.SQLite.SQLiteDataReader reader)
|
public static Show FromReader(System.Data.SQLite.SQLiteDataReader reader)
|
||||||
{
|
{
|
||||||
return new Show((int)reader["id"],
|
return new Show((long)reader["id"],
|
||||||
(string)reader["uri"],
|
reader["uri"] as string,
|
||||||
(string)reader["title"],
|
reader["title"] as string,
|
||||||
null,
|
(reader["aliases"] as string)?.Split('|').ToList() ?? null,
|
||||||
(string)reader["overview"],
|
reader["overview"] as string,
|
||||||
Status.Finished,
|
reader["status"] as Status?,
|
||||||
(int)reader["startYear"],
|
reader["startYear"] as long?,
|
||||||
(int)reader["endYear"],
|
reader["endYear"] as long?,
|
||||||
(string)reader["imgPrimary"],
|
reader["imgPrimary"] as string,
|
||||||
(string)reader["imgThumb"],
|
reader["imgThumb"] as string,
|
||||||
(string)reader["imgBanner"],
|
reader["imgBanner"] as string,
|
||||||
(string)reader["imgLogo"],
|
reader["imgLogo"] as string,
|
||||||
(string)reader["imgBackdrop"],
|
reader["imgBackdrop"] as string,
|
||||||
(string)reader["externalIDs"]);
|
reader["externalIDs"] as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user