Show default download options
This commit is contained in:
parent
57836d7a91
commit
162a89efc9
10 changed files with 53 additions and 25 deletions
3
@types/messageHandler.d.ts
vendored
3
@types/messageHandler.d.ts
vendored
|
|
@ -6,7 +6,8 @@ export interface MessageHandler {
|
|||
auth: (data: AuthData) => Promise<AuthResponse>;
|
||||
checkToken: () => Promise<CheckTokenResponse>;
|
||||
search: (data: SearchData) => Promise<SearchResponse>,
|
||||
dubLangCodes: () => Promise<string[]>
|
||||
availableDubCodes: () => Promise<string[]>,
|
||||
handleDefault: (name: string) => Promise<any>
|
||||
}
|
||||
|
||||
export type SearchResponseItem = {
|
||||
|
|
|
|||
10
crunchy.ts
10
crunchy.ts
|
|
@ -42,7 +42,7 @@ import { AuthData, AuthResponse, ResponseBase, SearchData, SearchResponse, Searc
|
|||
import { ServiceClass } from './@types/serviceClassInterface';
|
||||
|
||||
export default class Crunchy implements ServiceClass {
|
||||
private cfg: yamlCfg.ConfigObject;
|
||||
public cfg: yamlCfg.ConfigObject;
|
||||
private token: Record<string, any>;
|
||||
private req: reqModule.Req;
|
||||
private cmsToken: {
|
||||
|
|
@ -226,10 +226,10 @@ export default class Crunchy implements ServiceClass {
|
|||
yamlCfg.saveCRToken(this.token);
|
||||
}
|
||||
|
||||
public async getProfile() {
|
||||
public async getProfile() : Promise<boolean> {
|
||||
if(!this.token.access_token){
|
||||
console.log('[ERROR] No access token!');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const profileReqOptions = {
|
||||
headers: {
|
||||
|
|
@ -240,10 +240,11 @@ export default class Crunchy implements ServiceClass {
|
|||
const profileReq = await this.req.getData(api.beta_profile, profileReqOptions);
|
||||
if(!profileReq.ok || !profileReq.res){
|
||||
console.log('[ERROR] Get profile failed!');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const profile = JSON.parse(profileReq.res.body);
|
||||
console.log('[INFO] USER: %s (%s)', profile.username, profile.email);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async refreshToken(){
|
||||
|
|
@ -1231,6 +1232,7 @@ export default class Crunchy implements ServiceClass {
|
|||
}
|
||||
|
||||
public async muxStreams(data: DownloadedMedia[], options: CrunchyMuxOptions) {
|
||||
this.cfg.bin = await yamlCfg.loadBinCfg();
|
||||
if (options.novids || data.filter(a => a.type === 'Video').length === 0)
|
||||
return console.log('[INFO] Skip muxing since no vids are downloaded');
|
||||
const merger = new Merger({
|
||||
|
|
|
|||
7
funi.ts
7
funi.ts
|
|
@ -52,7 +52,7 @@ let fnEpNum: string|number = 0,
|
|||
stDlPath: Subtitle[] = [];
|
||||
|
||||
export default class Funi implements ServiceClass {
|
||||
private cfg: yamlCfg.ConfigObject;
|
||||
public cfg: yamlCfg.ConfigObject;
|
||||
private token: string | boolean;
|
||||
|
||||
constructor(private debug = false) {
|
||||
|
|
@ -65,10 +65,6 @@ export default class Funi implements ServiceClass {
|
|||
return isOk ? { isOk, value: undefined } : { isOk, reason: new Error('Not authenticated') };
|
||||
}
|
||||
|
||||
public async init() {
|
||||
this.cfg.bin = await yamlCfg.loadBinCfg();
|
||||
}
|
||||
|
||||
public async cli() : Promise<boolean|undefined> {
|
||||
const argv = appYargs.appArgv(this.cfg.cli);
|
||||
if (argv.debug)
|
||||
|
|
@ -757,6 +753,7 @@ export default class Funi implements ServiceClass {
|
|||
}
|
||||
|
||||
// check exec
|
||||
this.cfg.bin = await yamlCfg.loadBinCfg();
|
||||
const mergerBin = merger.checkMerger(this.cfg.bin, data.mp4, data.forceMuxer);
|
||||
|
||||
if ( data.novids ){
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@ export default () => {
|
|||
ipcMain.handle('auth', async (_, data) => handler?.auth(data));
|
||||
ipcMain.handle('checkToken', async () => handler?.checkToken());
|
||||
ipcMain.handle('search', async (_, data) => handler?.search(data));
|
||||
ipcMain.handle('dubLangCodes', async () => handler?.dubLangCodes());
|
||||
ipcMain.handle('default', async (_, data) => handler?.handleDefault(data));
|
||||
ipcMain.handle('availableDubCodes', async () => handler?.availableDubCodes());
|
||||
};
|
||||
|
|
|
|||
2
gui/electron/src/serviceHandler/base.ts
Normal file
2
gui/electron/src/serviceHandler/base.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export default class Base {
|
||||
}
|
||||
|
|
@ -1,19 +1,27 @@
|
|||
import { AuthData, CheckTokenResponse, MessageHandler, SearchData, SearchResponse } from '../../../../@types/messageHandler';
|
||||
import Crunchy from '../../../../crunchy';
|
||||
import Funimation from '../../../../funi';
|
||||
import { getDefault } from '../../../../modules/module.args';
|
||||
import { dubLanguageCodes } from '../../../../modules/module.langsData';
|
||||
import Base from './base';
|
||||
|
||||
class CrunchyHandler implements MessageHandler {
|
||||
class CrunchyHandler extends Base implements MessageHandler {
|
||||
private crunchy: Crunchy;
|
||||
constructor() {
|
||||
super();
|
||||
this.crunchy = new Crunchy();
|
||||
}
|
||||
|
||||
public async dubLangCodes(): Promise<string[]> {
|
||||
public async handleDefault(name: string) {
|
||||
return getDefault(name, this.crunchy.cfg.cli);
|
||||
}
|
||||
|
||||
public async availableDubCodes(): Promise<string[]> {
|
||||
return dubLanguageCodes;
|
||||
}
|
||||
|
||||
public async search(data: SearchData): Promise<SearchResponse> {
|
||||
this.crunchy.refreshToken();
|
||||
const funiSearch = await this.crunchy.doSearch(data);
|
||||
if (!funiSearch.isOk)
|
||||
return funiSearch;
|
||||
|
|
@ -21,7 +29,7 @@ class CrunchyHandler implements MessageHandler {
|
|||
}
|
||||
|
||||
public async checkToken(): Promise<CheckTokenResponse> {
|
||||
if (this.crunchy.checkToken()) {
|
||||
if (await this.crunchy.getProfile()) {
|
||||
return { isOk: true, value: undefined };
|
||||
} else {
|
||||
return { isOk: false, reason: new Error('') };
|
||||
|
|
|
|||
|
|
@ -1,14 +1,21 @@
|
|||
import { AuthData, CheckTokenResponse, MessageHandler, SearchData, SearchResponse } from '../../../../@types/messageHandler';
|
||||
import Funimation from '../../../../funi';
|
||||
import { getDefault } from '../../../../modules/module.args';
|
||||
import { dubLanguageCodes } from '../../../../modules/module.langsData';
|
||||
import Base from './base';
|
||||
|
||||
class FunimationHandler implements MessageHandler {
|
||||
class FunimationHandler extends Base implements MessageHandler {
|
||||
private funi: Funimation;
|
||||
constructor() {
|
||||
super();
|
||||
this.funi = new Funimation();
|
||||
}
|
||||
|
||||
public async dubLangCodes(): Promise<string[]> {
|
||||
public async handleDefault(name: string) {
|
||||
return getDefault(name, this.funi.cfg.cli);
|
||||
}
|
||||
|
||||
public async availableDubCodes(): Promise<string[]> {
|
||||
return dubLanguageCodes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,15 +8,24 @@ import { Check, Close } from "@mui/icons-material";
|
|||
const DownloadSelector: React.FC = () => {
|
||||
const messageHandler = React.useContext(messageChannelContext);
|
||||
const [store, dispatch] = useStore();
|
||||
const [dubLangCodes, setDubLangCodes] = React.useState<string[]>([]);
|
||||
const [availableDubs, setAvailableDubs] = React.useState<string[]>([]);
|
||||
|
||||
React.useEffect(() => {
|
||||
(async () => {
|
||||
const codes = await messageHandler?.dubLangCodes();
|
||||
setDubLangCodes(codes ?? []);
|
||||
dispatch({
|
||||
type: 'downloadOptions',
|
||||
payload: {
|
||||
...store.downloadOptions,
|
||||
dubLang: await messageHandler?.handleDefault('dubLang'),
|
||||
q: await messageHandler?.handleDefault('q'),
|
||||
fileName: await messageHandler?.handleDefault('fileName')
|
||||
}
|
||||
});
|
||||
setAvailableDubs(await messageHandler?.availableDubCodes() ?? []);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
|
||||
return <Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<Box sx={{ m: 2, gap: 1, display: 'flex', justifyContent: 'center', alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<TextField value={store.downloadOptions.id} required onChange={e => {
|
||||
|
|
@ -42,7 +51,7 @@ const DownloadSelector: React.FC = () => {
|
|||
}} label='Episode Select' />
|
||||
<MultiSelect
|
||||
title='Dub Languages'
|
||||
values={dubLangCodes}
|
||||
values={availableDubs}
|
||||
selected={store.downloadOptions.dubLang}
|
||||
onChange={(e) => {
|
||||
dispatch({
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ const SearchBox: React.FC = () => {
|
|||
<List>
|
||||
{searchResult && searchResult.isOk ?
|
||||
searchResult.value.map((a, ind, arr) => {
|
||||
return <>
|
||||
<ListItem className='listitem-hover' key={a.id} onClick={() => selectItem(a.id)}>
|
||||
return <Box key={a.id}>
|
||||
<ListItem className='listitem-hover' onClick={() => selectItem(a.id)}>
|
||||
<Box sx={{ display: 'flex' }}>
|
||||
<Box sx={{ width: '20%', height: '100%', pr: 2 }}>
|
||||
<img src={a.image} style={{ width: '100%', height: '100%' }}/>
|
||||
|
|
@ -70,8 +70,8 @@ const SearchBox: React.FC = () => {
|
|||
</Box>
|
||||
</Box>
|
||||
</ListItem>
|
||||
{(ind < arr.length - 1) && <Divider key={`${a.id}Divider`} />}
|
||||
</>
|
||||
{(ind < arr.length - 1) && <Divider />}
|
||||
</Box>
|
||||
})
|
||||
: <></>}
|
||||
</List>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ const MessageChannelProvider: React.FC = ({ children }) => {
|
|||
auth: async (data) => await ipcRenderer.invoke('auth', data),
|
||||
checkToken: async () => await ipcRenderer.invoke('checkToken'),
|
||||
search: async (data) => await ipcRenderer.invoke('search', data),
|
||||
dubLangCodes: async () => await ipcRenderer.invoke('dubLangCodes')
|
||||
handleDefault: async (data) => await ipcRenderer.invoke('default', data),
|
||||
availableDubCodes: async () => await ipcRenderer.invoke('availableDubCodes')
|
||||
}
|
||||
|
||||
return <messageChannelContext.Provider value={messageHandler}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue