Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
48 changes: 36 additions & 12 deletions src/actions/external/getHtmlJustWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ProviderInfo } from '@/types/justwatch/providers';
export const getHtmlJustWatch = async (moviename: string) => {
const encode = encodeURIComponent(moviename);

const res = await fetch(`https://www.justwatch.com/kr/๊ฒ€์ƒ‰?q=${encode}`, {
const res = await fetch(`https://www.justwatch.com/kr/search?content_type=movie&q=${encode}`, {
//.json๋ง๊ณ  .textํ•ด์•ผํ•ด์„œ ๊ทธ๋ƒฅ fetch๋กœ
cache: 'force-cache',
headers: {
Expand All @@ -20,15 +20,39 @@ export const getHtmlJustWatch = async (moviename: string) => {
const $ = cheerio.load(html);

const providers: ProviderInfo[] = [];
$('.buybox-row a').each((_, el) => {
const $el = $(el);
const url = $el.attr('href') || '';
const logo = $el.find('img').attr('src');

if (url.startsWith('http') && !providers.some((p) => p.logo === logo)) {
providers.push({ url, logo });
}
});

return providers;
let matched = false;
const allowedProviders = ['netflix', 'watcha', 'disney', 'wavve'];

const firstTitleRow = $('.title-list-row__row').first();

//๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์˜ ์ฒซ๋ฒˆ์งธ ํ•ญ๋ชฉ
const title = firstTitleRow.find('.title-list-row__column-header').text().trim();

// ๊ฒ€์ƒ‰์–ด๊ฐ€ ์˜ํ™” ์ œ๋ชฉ์— 'ํฌํ•จ' ๋˜์–ด ์žˆ๋Š”์ง€?
if (title.toLowerCase().includes(moviename.toLowerCase())) {
matched = true;

//์ฒซ๋ฒˆ์งธ ํ•ญ๋ชฉ ์•ˆ์˜ ํ”„๋กœ๋ฐ”์ด๋”๋“ค ์ค‘
firstTitleRow.find('.buybox-row a').each((_, el) => {
const $el = $(el);
const url = $el.attr('href') || '';
const logo = $el.find('img').attr('src');

const lowerUrl = url.toLowerCase();
if (
allowedProviders.some((p) => lowerUrl.includes(p)) && //[๋„ทํ”Œ, ๋””์ฆˆ๋‹ˆ, ์›จ์ด๋ธŒ, ์™“์ฑ ๋งŒ]
url.startsWith('http') &&
!providers.some((p) => p.logo === logo)
) {
const providerName = allowedProviders.find((p) => lowerUrl.includes(p));
const alreadyAdded = providers.some((p) => p.url.toLowerCase().includes(providerName!));

if (!alreadyAdded) {
providers.push({ url, logo });
}
}
});
}

return matched ? providers : [];
};
4 changes: 0 additions & 4 deletions src/actions/profile/getUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ export const getMyInfo = async () => {
};

export const getUserInfo = async (userid: number) => {
const session = await auth();
const accessToken = session?.accessToken;

return await fetcher(`${process.env.API_BASE_URL}/${process.env.TEST_TEAM_ID}/users/${userid}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
cache: 'no-store',
Expand Down
4 changes: 2 additions & 2 deletions src/app/testTrailer/StreamingIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface Props {

export const StreamingIcon = ({ providers }: Props) => {
return (
<div className='relative inline-block'>
<h3 className='text-mogazoa-16px-600 text-black-2e2e3a mb-5'>๊ฐ์ƒํ•˜๊ธฐ</h3>
<div className='relative inline-block min-w-40'>
<h3 className='text-mogazoa-16px-600 text-black-2e2e3a mb-5'>{`๋ฐ”๋กœ ๊ฐ์ƒํ•˜๊ธฐ`}</h3>
<div className='inline-flex items-center'>
{providers.map((item) => (
<Link
Expand Down
Loading