Skip to content

Commit

Permalink
Refactor file paths, update dependencies, and add new components
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu8443 committed Apr 27, 2024
1 parent 73d8f84 commit e2416e4
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 40 deletions.
35 changes: 33 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "VegaMovies",
"name": "vega",
"version": "0.0.1",
"private": true,
"scripts": {
Expand All @@ -21,6 +21,7 @@
"react-native-linear-gradient": "^2.8.3",
"react-native-safe-area-context": "^4.10.1",
"react-native-screens": "^3.31.1",
"react-native-svg": "14.1.0",
"react-native-vector-icons": "^10.0.3"
},
"devDependencies": {
Expand Down
68 changes: 68 additions & 0 deletions src/components/SeasonList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
View,
Text,
ScrollView,
Animated,
Platform,
UIManager,
LayoutAnimation,
} from 'react-native';
import React, {useEffect, useState} from 'react';
import {Link} from '../lib/getInfo';
import {getStream} from '../lib/getStream';

const SeasonList = ({LinkList}: {LinkList: Link[]}) => {
if (Platform.OS === 'android') {
if (UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
}
const [acc, setAcc] = useState<string>('');
const [stream, setStream] = useState<string>('');
useEffect(() => {
const fetchStream = async () => {
const link = await getStream(
LinkList.find(link => link.title === acc)?.movieLinks || '',
);
console.log('link', link);
setStream(link);
};
if (acc) {
fetchStream();
}
}, [acc]);

return (
<ScrollView className="p-4">
<Text className="text-white text-lg font-semibold mb-2">Seasons</Text>
<View className="flex-row flex-wrap justify-center gap-x-2 gap-y-2">
{LinkList.map(link => (
<View
className="bg-quaternary min-w-full p-2 rounded-md"
key={link.movieLinks}>
<Text
className="text-white"
onPress={() => {
LayoutAnimation.configureNext(
LayoutAnimation.Presets.easeInEaseOut,
);
setAcc(acc === link.title ? '' : link.title);
}}>
{link.title}
</Text>
<Animated.ScrollView
style={{
maxHeight: acc === link.title ? 200 : 0,
overflow: 'hidden',
}}>
<Text className="text-white">{link.movieLinks}</Text>
<Text className="text-white">{stream}</Text>
</Animated.ScrollView>
</View>
))}
</View>
</ScrollView>
);
};

export default SeasonList;
31 changes: 0 additions & 31 deletions src/lib/fetcher.ts

This file was deleted.

41 changes: 39 additions & 2 deletions src/lib/getInfo.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import * as cheerio from 'cheerio';
import fetcher from './fetcher';
import axios from 'axios';

export interface Info {
title: string;
image: string;
synopsis: string;
imdbId: string;
type: string;
linkList?: Link[];
}

export interface Link {
title: string;
movieLinks: string;
episodeLinks: string;
}

export const getInfo = async (link: string): Promise<Info> => {
try {
const url = `https://vegamovies.ph/${link}`;
const response = await fetcher(url);
const response = await axios(url);
const $ = cheerio.load(response.data);
const infoContainer = $('.entry-content');
const heading = infoContainer?.find('h3');
Expand Down Expand Up @@ -44,12 +51,41 @@ export const getInfo = async (link: string): Promise<Info> => {
// console.log(image);

console.log({title, synopsis, image, imdbId, type});
/// Links
const hr = infoContainer?.first()?.find('hr');
const list = hr?.nextUntil('hr');
const links: Link[] = [];
list.each((index, element: any) => {
element = $(element);
const title = element?.text() || '';
// console.log(title);
// movieLinks
const movieLinks = element
?.next()
.find('.dwd-button')
?.parent()
?.attr('href');

// episode links
const episodeLinks = element
?.next()
.find(
".btn-outline[style='background:linear-gradient(135deg,#0ebac3,#09d261); color: white;']",
)
?.parent()
?.attr('href');
if (movieLinks || episodeLinks) {
links.push({title, movieLinks, episodeLinks});
}
});
console.log(links);
return {
title,
synopsis,
image,
imdbId,
type,
linkList: links,
};
} catch (error) {
console.error('getInfo error');
Expand All @@ -59,6 +95,7 @@ export const getInfo = async (link: string): Promise<Info> => {
image: '',
imdbId: '',
type: '',
linkList: [],
};
}
};
6 changes: 3 additions & 3 deletions src/lib/getPosts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cheerio from 'cheerio';
import fetcher from './fetcher';
import axios from 'axios';

export interface Post {
title: string;
Expand All @@ -15,8 +15,8 @@ export const getPosts = async (
const baseUrl = 'https://vegamovies.ph';
const url = filter.includes('category')
? `${baseUrl}/${filter}/page/${page}/`
: `${baseUrl}/${page}/?s=${filter}`;
const urlRes = await fetcher(url);
: `${baseUrl}/page/${page}/?s=${filter}`;
const urlRes = await axios(url);
// if res 301 change url to res.headers.location
const $ = cheerio.load(urlRes.data);
const posts: Post[] = [];
Expand Down
51 changes: 51 additions & 0 deletions src/lib/getStream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import axios from 'axios';
import * as cheerio from 'cheerio';

export async function getStream(dotlink: string) {
try {
// console.log('dotlink', dotlink);
const dotlinkRes = await axios(dotlink);
const dotlinkText = dotlinkRes.data;
// console.log('dotlinkText', dotlinkText);
const vLink =
dotlinkText.match(/<a\s+href="([^"]*v-cloud\.bio[^"]*)"/i) || [];
// console.log('vLink', vLink[1]);
const vLinkRes = await axios(vLink[1]);
const vLinkText = vLinkRes.data;
const vLinkRedirect = vLinkText.match(/var\s+url\s*=\s*'([^']+)';/) || [
'',
'',
];
// console.log(vLinkRedirect);
const getTokenRes = await axios(vLinkRedirect[1]);

const getTokenText = getTokenRes.data;
const getToken = getTokenText.match(/[\?&]r=([^&;]*)/);
// console.log(getToken?.[1]);
const blogLink = `https://bloggingvector.shop/re/${getToken?.[1]}?_=631252793`;
const blogRes = await axios(blogLink);
// console.log(blogRes.data);
const vcloudLink = blogRes.data.match(
/https:\/\/v-cloud\.bio\/\w+\?token=([a-zA-Z0-9_-]+)/,
);
// console.log('vcloudLink', vcloudLink?.[0]);
const vcloudRes = await axios(vcloudLink?.[0]);
const $ = cheerio.load(vcloudRes.data);

const linkClass = $('.btn-success.btn-lg.h6');
const streamLinks: string[] = [];
linkClass.each((index, element) => {
const itm = $(element);
const link = itm.attr('href') || '';
if (link?.includes('workers.dev')) {
streamLinks.push(link);
}
});

// console.log(streamLinks);
return streamLinks[0];
} catch (error) {
console.error(error);
return '';
}
}
6 changes: 6 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {clsx, type ClassValue} from 'clsx';
import {twMerge} from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
2 changes: 1 addition & 1 deletion src/screens/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Home = () => {
return (
<SafeAreaView className="bg-black p-4 h-full w-full">
<ScrollView showsVerticalScrollIndicator={false}>
<Slider filter="" title="Latest" />
<Slider filter="d" title="Latest" />
<Slider filter="category/web-series/netflix" title="Netflix" />
<Slider
filter="category/web-series/amazon-prime-video"
Expand Down
2 changes: 2 additions & 0 deletions src/screens/home/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getInfo} from '../../lib/getInfo';
import type {Info} from '../../lib/getInfo';
import LinearGradient from 'react-native-linear-gradient';
import axios from 'axios';
import SeasonList from '../../components/SeasonList';

type Props = NativeStackScreenProps<HomeStackParamList, 'Info'>;
export default function Info({route}: Props) {
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function Info({route}: Props) {
: info?.synopsis || ''}
</Text>
</View>
<SeasonList LinkList={info?.linkList || []} />
</SafeAreaView>
);
}
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
primary: '#FF6347',
secondary: '#000000',
tertiary: '#171717',
quaternary: '#1a1a1a',
},
},
},
Expand Down
Loading

0 comments on commit e2416e4

Please sign in to comment.