Use XDG directory structure, introduce split DB format
This commit is contained in:
parent
70e7729443
commit
08ede4ed82
2 changed files with 40 additions and 27 deletions
|
@ -5,27 +5,50 @@ use async_sqlite :: rusqlite :: Row ;
|
||||||
use async_sqlite :: rusqlite :: Error :: * ;
|
use async_sqlite :: rusqlite :: Error :: * ;
|
||||||
use async_sqlite :: rusqlite :: ffi :: ErrorCode :: * ;
|
use async_sqlite :: rusqlite :: ffi :: ErrorCode :: * ;
|
||||||
use fallible_iterator :: * ;
|
use fallible_iterator :: * ;
|
||||||
|
use std :: env :: * ;
|
||||||
use std :: path :: * ;
|
use std :: path :: * ;
|
||||||
|
|
||||||
use crate :: error :: * ;
|
use crate :: error :: * ;
|
||||||
use crate :: error :: ZoodexError :: * ;
|
use crate :: error :: ZoodexError :: * ;
|
||||||
|
use crate :: utility :: * ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct DataManager { sqlite_client : Client }
|
pub struct DataManager {
|
||||||
|
sqlite_client_local : Client ,
|
||||||
|
sqlite_client_shared : Client ,
|
||||||
|
}
|
||||||
|
|
||||||
impl DataManager {
|
impl DataManager {
|
||||||
pub async fn new () -> Result <Self> {
|
pub async fn new () -> Result <Self> {
|
||||||
let sqlite_client = ClientBuilder :: new ()
|
let home_dir = var_os ("HOME") . unwrap () ;
|
||||||
. path ("zoodex.sqlite")
|
let xdg_data_home = var_os ("XDG_DATA_HOME") ;
|
||||||
|
|
||||||
|
let data_dir = match xdg_data_home {
|
||||||
|
Some (xdg_data_home) => concat_os_str ! ( xdg_data_home , "/zoodex" ) ,
|
||||||
|
None => concat_os_str ! ( home_dir , "/.local/share/zoodex" ) ,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
let sqlite_client_shared = ClientBuilder :: new ()
|
||||||
|
. path ( concat_os_str ! ( & data_dir , "/shared.sqlite" ) )
|
||||||
|
. flags ( OpenFlags :: SQLITE_OPEN_READ_ONLY | OpenFlags :: SQLITE_OPEN_NO_MUTEX )
|
||||||
|
. open ()
|
||||||
|
. await ? ;
|
||||||
|
|
||||||
|
let sqlite_client_local = ClientBuilder :: new ()
|
||||||
|
. path ( concat_os_str ! ( & data_dir , "/shared.sqlite" ) )
|
||||||
. flags ( OpenFlags :: SQLITE_OPEN_READ_WRITE | OpenFlags :: SQLITE_OPEN_NO_MUTEX )
|
. flags ( OpenFlags :: SQLITE_OPEN_READ_WRITE | OpenFlags :: SQLITE_OPEN_NO_MUTEX )
|
||||||
. open ()
|
. open ()
|
||||||
. await ? ;
|
. await ? ;
|
||||||
Ok ( Self { sqlite_client } )
|
|
||||||
|
Ok ( Self {
|
||||||
|
sqlite_client_local ,
|
||||||
|
sqlite_client_shared ,
|
||||||
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_collection_overview ( & self ) -> Result <CollectionOverview> {
|
pub async fn get_collection_overview ( & self ) -> Result <CollectionOverview> {
|
||||||
let collection_overview = self . sqlite_client . conn ( |sqlite_connection| {
|
let collection_overview = self . sqlite_client_shared . conn ( |sqlite_connection| {
|
||||||
let films = sqlite_connection
|
let films = sqlite_connection
|
||||||
. prepare ( "
|
. prepare ( "
|
||||||
select uuid , name , original_name , release_date , runtime_minutes , poster_file_path
|
select uuid , name , original_name , release_date , runtime_minutes , poster_file_path
|
||||||
|
@ -53,7 +76,7 @@ impl DataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_film_details ( & self , uuid : String ) -> Result <FilmDetails> {
|
pub async fn get_film_details ( & self , uuid : String ) -> Result <FilmDetails> {
|
||||||
let film_details = self . sqlite_client . conn ( |sqlite_connection| {
|
let film_details = self . sqlite_client_shared . conn ( |sqlite_connection| {
|
||||||
let film_details = sqlite_connection
|
let film_details = sqlite_connection
|
||||||
. prepare ( "
|
. prepare ( "
|
||||||
select
|
select
|
||||||
|
@ -63,14 +86,13 @@ impl DataManager {
|
||||||
films . release_date ,
|
films . release_date ,
|
||||||
films . runtime_minutes ,
|
films . runtime_minutes ,
|
||||||
films . poster_file_path ,
|
films . poster_file_path ,
|
||||||
films . source ,
|
sources . media_uuid ,
|
||||||
|
sources . bittorrent_hash ,
|
||||||
sources . file_path ,
|
sources . file_path ,
|
||||||
sources . subtitle_file_path ,
|
|
||||||
sources . video_track ,
|
|
||||||
sources . audio_track ,
|
sources . audio_track ,
|
||||||
sources . subtitle_track
|
sources . subtitle_track
|
||||||
from films left join sources
|
from films left join sources
|
||||||
on films . source = sources . uuid
|
on films . uuid = sources . media_uuid
|
||||||
where films . uuid = (?1)
|
where films . uuid = (?1)
|
||||||
" ) ?
|
" ) ?
|
||||||
. query ( [ uuid ] ) ?
|
. query ( [ uuid ] ) ?
|
||||||
|
@ -179,9 +201,8 @@ fn row_to_series_overview ( row : & Row ) -> rusqlite :: Result <SeriesOverview>
|
||||||
pub source : Option <SourceDetails> ,
|
pub source : Option <SourceDetails> ,
|
||||||
}
|
}
|
||||||
# [ derive (Clone) ] pub struct SourceDetails {
|
# [ derive (Clone) ] pub struct SourceDetails {
|
||||||
|
pub bittorrent_hash : String ,
|
||||||
pub file_path : PathBuf ,
|
pub file_path : PathBuf ,
|
||||||
pub subtitle_file_path : Option <PathBuf> ,
|
|
||||||
pub video_track : Option <u32> ,
|
|
||||||
pub audio_track : Option <u32> ,
|
pub audio_track : Option <u32> ,
|
||||||
pub subtitle_track : Option <u32> ,
|
pub subtitle_track : Option <u32> ,
|
||||||
}
|
}
|
||||||
|
@ -194,19 +215,17 @@ fn row_to_film_details ( row : & Row ) -> rusqlite :: Result <FilmDetails> {
|
||||||
let runtime_minutes = row . get (4) ? ;
|
let runtime_minutes = row . get (4) ? ;
|
||||||
let poster_file_path = row . get :: < _ , Option <String> > (5) ? . map ( PathBuf :: from ) ;
|
let poster_file_path = row . get :: < _ , Option <String> > (5) ? . map ( PathBuf :: from ) ;
|
||||||
|
|
||||||
let source_uuid = row . get :: < _ , Option <String> > (6) ? ;
|
let source_media_uuid = row . get :: < _ , Option <String> > (6) ? ;
|
||||||
let source = match source_uuid {
|
let source = match source_media_uuid {
|
||||||
Some (_) => {
|
Some (_) => {
|
||||||
let file_path = PathBuf :: from ( row . get :: < _ , String > (7) ? ) ;
|
let bittorrent_hash = row . get (7) ? ;
|
||||||
let subtitle_file_path = row . get :: < _ , Option <String> > (8) ? . map ( PathBuf :: from ) ;
|
let file_path = PathBuf :: from ( row . get :: < _ , String > (8) ? ) ;
|
||||||
let video_track = row . get (9) ? ;
|
let audio_track = row . get (9) ? ;
|
||||||
let audio_track = row . get (10) ? ;
|
let subtitle_track = row . get (10) ? ;
|
||||||
let subtitle_track = row . get (11) ? ;
|
|
||||||
|
|
||||||
Some ( SourceDetails {
|
Some ( SourceDetails {
|
||||||
|
bittorrent_hash ,
|
||||||
file_path ,
|
file_path ,
|
||||||
subtitle_file_path ,
|
|
||||||
video_track ,
|
|
||||||
audio_track ,
|
audio_track ,
|
||||||
subtitle_track ,
|
subtitle_track ,
|
||||||
} )
|
} )
|
||||||
|
|
|
@ -62,12 +62,6 @@ impl UI {
|
||||||
|
|
||||||
let arguments = [
|
let arguments = [
|
||||||
Some ( source . file_path . as_os_str () . to_owned () ) ,
|
Some ( source . file_path . as_os_str () . to_owned () ) ,
|
||||||
source . subtitle_file_path . map (
|
|
||||||
|subtitle_file_path| concat_os_str ! ( "--mpv-sub-file=" , subtitle_file_path ) ,
|
|
||||||
) ,
|
|
||||||
source . video_track . map (
|
|
||||||
|video_track| concat_os_str ! ( "--mpv-vid=" , to_os_string (video_track) ) ,
|
|
||||||
) ,
|
|
||||||
source . audio_track . map (
|
source . audio_track . map (
|
||||||
|audio_track| concat_os_str ! ( "--mpv-aid=" , to_os_string (audio_track) ) ,
|
|audio_track| concat_os_str ! ( "--mpv-aid=" , to_os_string (audio_track) ) ,
|
||||||
) ,
|
) ,
|
||||||
|
|
Loading…
Add table
Reference in a new issue