Compare commits

...

10 commits

Author SHA1 Message Date
Nikhil Nawgiri e1dbe4d7e4 first commit 2024-10-26 19:08:03 +02:00
Nikhil Nawgiri 47ccc86b75 Refactor 2024-10-26 19:02:57 +02:00
Nikhil Nawgiri f4425c941f Update gitignore 2024-10-26 18:50:06 +02:00
Nikhil Nawgiri a3646e51d5 Refactor 2024-10-26 18:49:49 +02:00
Nikhil Nawgiri b7255bd6c5 Use saveJsonToDisk in main func 2024-10-26 18:47:48 +02:00
Nikhil Nawgiri afce2994bd Create fsHelper 2024-10-26 18:47:24 +02:00
Nikhil Nawgiri d6731d1676 Improve itemHelper: Improve final datastructure 2024-10-26 17:57:05 +02:00
Nikhil Nawgiri ce604b3626 Implement transformItems to ommit unnecessary props from items 2024-10-26 17:47:09 +02:00
Nikhil Nawgiri ea78b4a6b5 Create itemHelper 2024-10-26 17:46:58 +02:00
Nikhil Nawgiri 6ad2721831 Refactor 2024-10-26 17:27:42 +02:00
6 changed files with 86 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
be/config.ts
database.json
# Logs
logs

0
README.md Normal file
View file

7
be/src/fsHelper.ts Normal file
View file

@ -0,0 +1,7 @@
import * as fs from "fs";
export const saveJsonToDisk = (content: {}) => {
const outputPath = `../database.json`;
fs.writeFileSync(outputPath, JSON.stringify(content));
}

59
be/src/itemHelper.ts Normal file
View file

@ -0,0 +1,59 @@
interface ItemProvidedByJellyfin {
Name: string,
ServerId: string,
Id: string,
HasSubtitles?: boolean,
Container: string,
PremiereDate: string,
CriticRating: number,
OfficialRating: string,
ChannelId: null,
CommunityRating: number,
RunTimeTicks: number,
ProductionYear: number,
ProviderIds: {
Tmdb: string,
Imdb: string,
TmdbCollection?: string,
},
IsFolder: boolean,
Type: "Movie" | "Series",
VideoType: string,
ImageBlurHashes: {},
LocationType: string,
MediaType: string,
};
interface ItemForWishlistUsage {
name: string,
hasSubtitles: boolean,
ageRating: string,
productionYear: number,
itemType: "Movie" | "Series",
imdbId: string,
};
export const transformItems = (items: []) => (
items.map((item: ItemProvidedByJellyfin) => {
const {
Name,
HasSubtitles,
OfficialRating,
ProductionYear,
Type,
ProviderIds,
} = item;
const { Imdb } = ProviderIds;
const newItem: ItemForWishlistUsage = {
name: Name,
hasSubtitles: HasSubtitles,
ageRating: OfficialRating,
productionYear: ProductionYear,
itemType: Type,
imdbId: Imdb,
};
return newItem;
})
);

View file

@ -5,7 +5,7 @@ import { API_BASE, API_TOKEN } from "../config.ts";
const API_ENDPOINT_WITH_PARAMS = "/Items?isMovie=true&isSeries=true&recursive=true&fields=ProviderIds&filters=&mediaTypes=Video&enableTotalRecordCount=true&enableImages=false";
const API_URL = API_BASE + API_ENDPOINT_WITH_PARAMS;
export const fetchFromApi = async () => {
export const fetchFromJellyfinApi = async () => {
const init = {
method: "GET",
headers: {

View file

@ -1,4 +1,6 @@
import { fetchFromApi } from "./fetchItemsFromJellyfin.ts";
import { fetchFromJellyfinApi } from "./jellyfinApiHelper.ts";
import { saveJsonToDisk } from "./fsHelper.ts";
import { transformItems } from "./itemHelper.ts";
interface JellyfinApiResponse {
Items?: [],
@ -6,11 +8,20 @@ interface JellyfinApiResponse {
StartIndex?: number,
};
const init = async () => {
const response: JellyfinApiResponse = await fetchFromApi();
const { Items: items, TotalRecordCount: totalItemCount } = response;
console.log("items:", items);
console.log("totalItemCount:", totalItemCount);
const run = async () => {
const {
Items: items,
TotalRecordCount: totalItemCount
}: JellyfinApiResponse = await fetchFromJellyfinApi();
const transformedItems = transformItems(items);
saveJsonToDisk({ totalItemCount, jellyfinItems: transformedItems });
// save as something else than json lol
// express API
// GET endpoint
// POST endpoint
}
init();
run();