├── .gitignore ├── src ├── utils │ ├── GptConfig.js │ └── tmdbconfig.js ├── routes │ ├── Searchmovie.js │ └── gptSearch.js └── index.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | yarn.lock 2 | node_modules 3 | .env 4 | -------------------------------------------------------------------------------- /src/utils/GptConfig.js: -------------------------------------------------------------------------------- 1 | import OpenAI from "openai"; 2 | 3 | const AskGpt = (key) => { 4 | return new OpenAI({ 5 | apiKey: key, 6 | }); 7 | }; 8 | 9 | export default AskGpt; 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netflix-server", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "repository": "https://github.com/deepumandal/netflix-server.git", 6 | "author": "Deepak mandal ", 7 | "license": "MIT", 8 | "type": "module", 9 | "dependencies": { 10 | "axios": "^1.6.2", 11 | "cors": "^2.8.5", 12 | "dotenv": "^16.3.1", 13 | "express": "^4.18.2", 14 | "nodemon": "^3.0.1", 15 | "openai": "^4.20.0" 16 | }, 17 | "scripts": { 18 | "start": "nodemon ./src/index.js" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/utils/tmdbconfig.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | export const TMDB_OPTIONS = { 4 | method: "GET", 5 | headers: { 6 | accept: "application/json", 7 | Authorization: `Bearer ${process.env.REACT_APP_TMDB_AUTHORIZATION}`, 8 | }, 9 | }; 10 | const searchMovieTMDB = async (movie) => { 11 | const data = await axios.get( 12 | "https://api.themoviedb.org/3/search/movie?query=" + 13 | movie + 14 | "&include_adult=false&language=en-US&page=1", 15 | TMDB_OPTIONS 16 | ); 17 | return data.data?.results; 18 | }; 19 | 20 | export default searchMovieTMDB; 21 | -------------------------------------------------------------------------------- /src/routes/Searchmovie.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import searchMovieTMDB from "../utils/tmdbconfig.js"; 3 | 4 | const SearchRoute = express.Router(); 5 | 6 | SearchRoute.post("/movie", async (req, res) => { 7 | try { 8 | const body = req.body; 9 | 10 | if (!Array.isArray(body) && body.length) { 11 | return res.status(400).send("Invalid parameters"); 12 | } else { 13 | const gptMovies = body 14 | const promiseArray = gptMovies.map((movie) => searchMovieTMDB(movie)); 15 | 16 | const tmdbResults = await Promise.all(promiseArray); 17 | console.log("tmdbResults",tmdbResults[0]) 18 | 19 | res.status(200).send(tmdbResults); 20 | } 21 | } catch (err) { 22 | res.status(500).send(err.message); 23 | } 24 | }); 25 | export default SearchRoute; 26 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import GptRoute from "./routes/gptSearch.js"; 3 | import cors from "cors"; 4 | const app = express(); 5 | import "dotenv/config"; 6 | import SearchRoute from "./routes/Searchmovie.js"; 7 | 8 | const whitelist = ["http://localhost:8080","https://deepumandal.github.io"]; 9 | 10 | const corsConfig = { 11 | origin: (origin, cb) => { 12 | console.log("origin",origin) 13 | if (whitelist.indexOf(origin) !== -1) { 14 | cb(null, true); 15 | } else { 16 | cb(new Error("Not allowed by CORS")); 17 | } 18 | }, 19 | }; 20 | 21 | app.use(cors(corsConfig)); 22 | 23 | app.use(express.json()); 24 | 25 | app.get("/", (req, res) => { 26 | res.status(200).send("

hii i am netflix server and i am listening

"); 27 | }); 28 | 29 | app.use("/openai", GptRoute); 30 | app.use("/search", SearchRoute); 31 | app.listen(7000, () => { 32 | console.log("listening on http://localhost:7000"); 33 | }); 34 | -------------------------------------------------------------------------------- /src/routes/gptSearch.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import AskGpt from "../utils/GptConfig.js"; 3 | 4 | const GptRoute = express.Router(); 5 | 6 | GptRoute.get("/", (req, res) => { 7 | res.status(200).send("Hello World!"); 8 | }); 9 | 10 | GptRoute.post("/connections", async (req, res) => { 11 | try { 12 | const { question } = req.body; 13 | console.log(question); 14 | if (!question) { 15 | return res.status(400).send({ 16 | error: "invalid question argument", 17 | }); 18 | } else { 19 | const querry = 20 | "Act as a Movie Recommendation system and suggest some movies for the query : " + 21 | question + 22 | ". only give me names of 5 movies, comma seperated like the example result given ahead. Example Result: Gadar, Sholay, Don, Golmaal, Koi Mil Gaya"; 23 | 24 | const chatCompletion = await AskGpt(process.env.OPENAI_API_KEY)?.chat?.completions.create({ 25 | messages: [{ role: "user", content: querry }], 26 | model: "gpt-3.5-turbo", 27 | }); 28 | console.log("chatCompletion",chatCompletion,process.env.APP_GPT_API_KEY) 29 | const gptMovies = 30 | chatCompletion.choices?.[0]?.message?.content.split(","); 31 | 32 | res.status(200).send(gptMovies); 33 | } 34 | } catch (err) { 35 | console.log(err); 36 | return res.status(500).send(err); 37 | } 38 | }); 39 | 40 | export default GptRoute; 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Netflix Server 2 | 3 | This repository contains the server-side code for the Netflix clone project. It complements the frontend application by handling authentication, managing movie data, and supporting GPT integration for enhanced search functionality. 4 | 5 | ## Features 6 | 7 | - **Authentication**: Manages user authentication and access to content. 8 | - **Movie Data Management**: Handles movie-related data and interactions. 9 | - **GPT Integration**: Supports GPT-powered search capabilities for precise and intuitive results. 10 | 11 | ## Repository Information 12 | - **Frontend Repository**: The frontend code is hosted separately at [Frontend Repository URL](https://github.com/deepumandal/Netflix). 13 | 14 | ## Purpose 15 | This server repository is developed in conjunction with the Netflix clone project by Deepak Mandal for educational purposes. It's designed to support the frontend application and is not intended for unauthorized use or distribution. 16 | 17 | ## Setup Instructions 18 | To set up and run this server code: 19 | 1. Clone this repository. 20 | 2. Follow the setup instructions provided in the README or documentation. 21 | 3. Ensure proper integration with the frontend repository for a complete Netflix experience. 22 | 23 | ## Contributors 24 | This server code is primarily developed by [Deepak Mandal](https://github.com/deepumandal/Netflix). 25 | 26 | ## License 27 | This server repository is for educational purposes and not intended for unauthorized use. Please refer to the LICENSE file for more details. 28 | 29 | Feel free to contribute, report issues, or collaborate on enhancing the server-side functionality of the Netflix clone project! 30 | --------------------------------------------------------------------------------