Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/helpers/movie.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ export const getTitle = (el: HTMLElement): string => {
return el.querySelector('h1').innerText.split(`(`)[0].trim();
};

export const getParent = (el: HTMLElement): string => {
let parentId = null;
parentId = getId(el.querySelector('h2').childNodes) || getId(el.querySelector('h1').childNodes);
return (parentId);

function getId(nodes: any){
let parentId = null;
let i = nodes.length; //we get all objects
while (i > 0){
i--;
let node = nodes[i];
if (node?._rawAttrs?.href){
let arr = node._rawAttrs.href.split("/").filter(function (el: any) {
return el != "";
});
parentId = arr[arr.length-1].split("-")[0];
break;
}
}
return(parentId);
};
};

export const getGenres = (el: HTMLElement): CSFDGenres[] => {
const genresRaw = el.querySelector('.genres').textContent;
return genresRaw.split(' / ') as CSFDGenres[];
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/movie.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CSFDMovie extends CSFDScreening {
related: CSFDMovieListItem[];
similar: CSFDMovieListItem[];
episodeNum: string;
parentId: string;
}

export type CSFDVodService =
Expand Down
2 changes: 2 additions & 0 deletions src/services/movie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getRatingCount,
getTags,
getTitle,
getParent,
getTitlesOther,
getTrivia,
getType,
Expand Down Expand Up @@ -53,6 +54,7 @@ export class MovieScraper {
this.film = {
id: movieId,
title: getTitle(el),
parentId: getParent(el),
year: getYear(jsonLd),
duration: getDuration(jsonLd, el),
descriptions: getDescriptions(el),
Expand Down