Skip to content

Commit

Permalink
✨ crawl trailer from article
Browse files Browse the repository at this point in the history
  • Loading branch information
Asing1001 committed Nov 15, 2023
1 parent 09d25df commit 5f9227e
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 69 deletions.
114 changes: 68 additions & 46 deletions src/crawler/lineCrawler.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import * as fetch from "isomorphic-fetch";
import * as fetch from 'isomorphic-fetch';
import { LINEPage } from '../models/LINEPage';

export async function getPlayingMovies(): Promise<LINEMovieResponse> {
try {
const res = await fetch("https://today.line.me/webapi/movie/incinemas/listings/inCinemas?offset=0&length=200&country=tw&tag=PLAYING");

const res = await fetch(
'https://today.line.me/webapi/movie/incinemas/listings/inCinemas?offset=0&length=200&country=tw&tag=PLAYING'
);

if (!res.ok) {
throw new Error(`HTTP error! Status: ${res.status}`);
}

const response: LINEMovieResponse = await res.json();

// Now you can work with the 'response' data.
console.log(response); // Replace this with your desired processing logic.

return response;
} catch (error) {
console.error("An error occurred:", error);
console.error('An error occurred:', error);
throw error;
}
}

export async function getLINEArticle(hash: string) {
// https://today.line.me/webapi/portal/page/setting/article?country=tw&hash=1DODQOz&group=NA
try {
const res = await fetch(
`https://today.line.me/webapi/portal/page/setting/article?country=tw&hash=${hash}&group=NA`
);

if (!res.ok) {
throw new Error(`HTTP error! Status: ${res.status}`);
}

const response: LINEPage = await res.json();
return response;
} catch (error) {
console.error('An error occurred:', error);
return null;
}
}

export interface LINEMovieResponse {
id: string;
totalCount: number;
Expand All @@ -30,11 +52,11 @@ export interface LINEMovieItem {
id: string;
title: string;
thumbnail: {
type: string;
hash: string;
type: string;
hash: string;
};
url: {
hash: string;
hash: string;
};
movieId: string;
movieGroupId: string;
Expand All @@ -43,34 +65,34 @@ export interface LINEMovieItem {
certificate: string;
releaseDate: number;
rating: {
totalScore: number;
count: number;
average: number;
totalScore: number;
count: number;
average: number;
};
genres: string[];
runtime: number;
showtimeCount: number;
directors: string[];
cast: string[];
latestTrailer: {
hash: string;
hash: string;
};
mainTrailer: {
id: string;
title: string;
publisher: string;
publisherId: string;
publishTimeUnix: number;
contentType: string;
thumbnail: {
type: string;
hash: string;
};
url: {
hash: string;
};
ageLimit: boolean;
categoryId: number;
id: string;
title: string;
publisher: string;
publisherId: string;
publishTimeUnix: number;
contentType: string;
thumbnail: {
type: string;
hash: string;
};
url: {
hash: string;
};
ageLimit: boolean;
categoryId: number;
};
bookable: boolean;
source: string;
Expand All @@ -81,26 +103,26 @@ export interface LINEMovieItem {
production: string;
synopsis: string;
trailers: {
id: string;
title: string;
publisher: string;
publisherId: string;
publishTimeUnix: number;
contentType: string;
thumbnail: {
type: string;
hash: string;
};
url: {
hash: string;
};
ageLimit: boolean;
categoryId: number;
}[];
pictures: {
id: string;
title: string;
publisher: string;
publisherId: string;
publishTimeUnix: number;
contentType: string;
thumbnail: {
type: string;
hash: string;
};
url: {
hash: string;
};
ageLimit: boolean;
categoryId: number;
}[];
pictures: {
type: string;
hash: string;
}[];
commentSetting: string;
manualTags: string[];
}
}
199 changes: 199 additions & 0 deletions src/models/LINEPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
export interface LINEPage {
pageId: string;
pageType: string;
modules: Module[];
data: PageData;
shareProperties: ShareProperties;
}

interface Module {
id: string;
type: string;
name: string;
source: string;
inStreamInventoryKey?: InStreamInventoryKey;
enableSubscribe?: boolean;
enableCp?: boolean;
subscribable?: boolean;
adRatio?: AdRatio;
lazyLoadingOn?: boolean;
lazyLoadingBuffer?: number;
startDateTime?: number;
endDateTime?: number;
metaData?: MetaData;
gptInventoryKey?: string;
lapInventoryKey?: string;
lapRsid?: string;
gfpInventoryKey?: string;
adId?: string;
lapCtid?: string;
adModuleType?: string;
containerStyle?: string;
header?: Header;
showDuration?: boolean;
order?: string;
adModule?: AdModule;
adStartPosition?: number;
adOffset?: number;
maxAdCount?: number;
style?: string;
searchTarget?: string;
listings?: Listing[];
showPublisher?: boolean;
showPlayCount?: boolean;
tabs?: string[];
actions?: string[];
sns?: string[];
}

interface InStreamInventoryKey {
keyType: string;
value: string;
}

interface AdRatio {
gpt: number;
lap: number;
gfp: number;
}

interface MetaData {
isDesktopOn: string;
}

interface Header {
title: string;
hasCompositeTitle: boolean;
subTitle: string;
}

interface AdModule {
id: string;
type: string;
name: string;
source: string;
adRatio: AdRatio;
lazyLoadingOn: boolean;
lazyLoadingBuffer: number;
startDateTime: number;
endDateTime: number;
metaData: MetaData;
gptInventoryKey: string;
lapInventoryKey: string;
lapRsid: string;
gfpInventoryKey: string;
adId: string;
lapCtid: string;
adModuleType: string;
}

interface Listing {
id: string;
offset: number;
length: number;
target: string;
urlPath: string;
params: Params;
}

interface Params {
excludeNoThumbnail: number;
containMainSnapshot: number;
articleId: string;
}

interface PageData {
id: string;
title: string;
publisher: string;
publisherId: string;
publishTimeUnix: number;
contentType: string;
thumbnail: Thumbnail;
url: Url;
categoryId: number;
categoryName: string;
media: Media;
shortDescription: string;
categoryPageUrlPath: string;
categoryPageLink: CategoryPageLink;
playCount: number;
language: string;
content: string;
publishTime: string;
updateTimeUnix: number;
displayStatus: string;
commentSetting: string;
movie: Movie;
exploreLinks: ExploreLink[];
brandSafetyCategories: any[];
publisherBlockAds: boolean;
aiTags: string;
}

interface Thumbnail {
type: string;
hash: string;
}

interface Url {
hash: string;
url: string;
}

interface Media {
type: string;
hash: string;
thumbnailHash: string;
profile: string;
duration: number;
width: number;
height: number;
meta: Meta;
}

interface Meta {
SOURCE_LINK_TYPE: string;
MOVIE_ARTICLE_HASH: string;
}

interface Movie {
id: string;
title: string;
articleId: number;
articleHash: string;
}

interface ExploreLink {
name: string;
pageLink: PageLink;
tagType: string | null;
}

interface PageLink {
pageType: string;
tag?: string;
hash?: string;
id?: string;
urlPath?: string;
type?: string;
}

interface ShareProperties {
title: string;
image: Image;
allowSEO: boolean;
}

interface Image {
hash: string;
}

interface CategoryPageLink {
pageType: string;
page: {
id: string;
urlPath: string;
type: string;
};
}
Loading

0 comments on commit 5f9227e

Please sign in to comment.