Skip to content

Commit

Permalink
Fix Automate and Add Trailers
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshiMinh committed Jun 6, 2024
1 parent b643ba2 commit a83e79a
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 108 deletions.
1 change: 1 addition & 0 deletions Login.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<script src="theme.js"></script>
<style>
body {
font-family: "Sirin Stencil", sans-serif;
Expand Down
3 changes: 2 additions & 1 deletion Register.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand All @@ -8,6 +8,7 @@

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<script src="theme.js"></script>
<style>
body {
font-family: "Sirin Stencil", sans-serif;
Expand Down
27 changes: 16 additions & 11 deletions fetchShowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ fetch('Movies.txt')
.then(data => {
const movieData = [];
const lines = data.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('MoviesShowing\\')) {
const parts = line.split('\\');
const name = parts[1].replace(/.jpg/g, '');
const image = `MoviesShowing/${parts[1]}`;
movieData.push({ name, image });
if (line !== '') {
const parts = line.split(' - ');
const movieInfo = parts[0].split('\\');
const category = movieInfo[0];
if (category === 'MoviesShowing') {
const imageFileName = movieInfo[1];
const movieTitle = imageFileName.replace(/.jpg/g, '');
const youtubeLink = parts[1] || '';

movieData.push({ category, movieTitle, imageFileName, youtubeLink });
}
}
}

// Define the movie card HTML as a template function
const movieCardTemplate = (movie) => `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="${movie.image}" class="card-img-top" />
<img src="${movie.category}/${movie.imageFileName}" class="card-img-top" />
<div class="card-body">
<p class="card-text">${movie.name}</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
</div>
<p class="card-text text-center">${movie.movieTitle}</p>
${movie.youtubeLink ? `<div>
<a href="${movie.youtubeLink}" target="_blank" class="btn btn-primary">Xem Trailer</a>
</div>` : ''}
</div>
</div>
</div>
Expand Down
44 changes: 23 additions & 21 deletions fetchUpcoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@
fetch('Movies.txt')
.then(response => response.text())
.then(data => {
const upcomingMovieData = [];
const movieData = [];
const lines = data.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('MoviesUpcoming\\')) {
const parts = line.split('\\');
const name = parts[1].replace(/.jpg/g, '');
const image = `MoviesUpcoming/${parts[1]}`;
upcomingMovieData.push({ name, image });
if (line !== '') {
const parts = line.split(' - ');
const movieInfo = parts[0].split('\\');
const category = movieInfo[0];
if (category === 'MoviesUpcoming') {
const imageFileName = movieInfo[1];
const movieTitle = imageFileName.replace(/.jpg/g, '');
const youtubeLink = parts[1] || '';

movieData.push({ category, movieTitle, imageFileName, youtubeLink });
}
}
}

// Define the upcoming movie card HTML as a template function
const upcomingMovieCardTemplate = (movie) => `
// Define the movie card HTML as a template function
const movieCardTemplate = (movie) => `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="${movie.image}" class="card-img-top" />
<img src="${movie.category}/${movie.imageFileName}" class="card-img-top" />
<div class="card-body">
<p class="card-text">${movie.name}</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
</div>
<p class="card-text text-center">${movie.movieTitle}</p>
${movie.youtubeLink ? `<div>
<a href="${movie.youtubeLink}" target="_blank" class="btn btn-primary">Xem Trailer</a>
</div>` : ''}
</div>
</div>
</div>
`;

// Get the container element
const upcomingContainer = document.getElementById('pills-sub');

// Get the row2 element inside the container
const row2 = upcomingContainer.querySelector('.row2');
const container = document.getElementById('upcoming-movies-container');

// Generate the HTML for each upcoming movie and append it to the row2 element
upcomingMovieData.forEach(movie => {
row2.innerHTML += upcomingMovieCardTemplate(movie);
// Generate the HTML for each movie and append it to the container
movieData.forEach(movie => {
container.innerHTML += movieCardTemplate(movie);
});
})
.catch(error => console.error('Error:', error));
57 changes: 51 additions & 6 deletions fetchmovies.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Run in Node.js
const fs = require('fs');
const path = require('path');
const https = require('https');

const apiKey = 'AIzaSyBZEQlM2UNO9ni0l62DwuvQ9JVfo55Am-0'; // Replace with your YouTube Data API key
const directoryPaths = ['MoviesShowing', 'MoviesUpcoming'];
const outputFile = 'movies.txt';

Expand All @@ -11,18 +12,62 @@ function fetchJPGFileNames(directory) {
.filter(file => path.extname(file).toLowerCase() === '.jpg');
}

// Function to fetch YouTube URL for a given movie name
function fetchYouTubeUrl(query) {
const apiUrl = `https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=${encodeURIComponent(query)}&maxResults=1&key=${apiKey}`;
return new Promise((resolve, reject) => {
https.get(apiUrl, (response) => {
let data = '';

response.on('data', (chunk) => {
data += chunk;
});

response.on('end', () => {
try {
const result = JSON.parse(data);
const videos = result.items;
if (videos.length > 0) {
const firstVideo = videos[0];
const videoId = firstVideo.id.videoId;
const videoUrl = `https://www.youtube.com/watch?v=${videoId}`;
resolve(videoUrl);
} else {
resolve('No video found');
}
} catch (error) {
reject('Error parsing JSON response from YouTube API.');
}
});
}).on('error', (error) => {
reject(`Error fetching data from YouTube API: ${error.message}`);
});
});
}

// Function to write file names to a text file
function writeToFile(fileNames) {
fs.writeFileSync(outputFile, fileNames.join('\n'));
}

// Main function to fetch file names from directories and write to file
function fetchAndWriteFileNames() {
// Main function to fetch file names from directories, fetch YouTube URLs, and write to file
async function fetchAndWriteFileNames() {
let allFileNames = [];
directoryPaths.forEach(directory => {

for (const directory of directoryPaths) {
const fileNames = fetchJPGFileNames(directory);
allFileNames = allFileNames.concat(fileNames.map(fileName => path.join(directory, fileName)));
});

for (const fileName of fileNames) {
const movieName = path.basename(fileName, path.extname(fileName));
const query = `${movieName} 2024 Trailer`;
try {
const youtubeUrl = await fetchYouTubeUrl(query);
allFileNames.push(`${directory}\\${fileName} - ${youtubeUrl}`);
} catch (error) {
console.error(error);
}
}
}

writeToFile(allFileNames);
console.log(`File names written to ${outputFile}`);
Expand Down
42 changes: 0 additions & 42 deletions minh.html

This file was deleted.

54 changes: 27 additions & 27 deletions movies.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
MoviesShowing\Abigail.jpg
MoviesShowing\DUNE Phần Hai.jpg
MoviesShowing\Exhuma Quật Mộ Trùng Ma.jpg
MoviesShowing\Godzilla X Kong Đế Chế Mới.jpg
MoviesShowing\Kung Fu Panda 4.jpg
MoviesShowing\Mai.jpg
MoviesShowing\Mobile Suit Gundam SEED FREEDOM.jpg
MoviesShowing\Monkey Man.jpg
MoviesShowing\Muôn Vị Nhân Gian.jpg
MoviesShowing\Người Chết Trở Về.jpg
MoviesShowing\Quỷ Thuật.jpg
MoviesShowing\Sáng Đèn.jpg
MoviesShowing\Thanh Xuân 18x2 Lữ Trình Hướng Về Em.jpg
MoviesShowing\Điềm Báo Của Quỷ.jpg
MoviesShowing\Đền Mạng.jpg
MoviesUpcoming\Anh Hùng Bàn Phím.jpg
MoviesUpcoming\B4S – Trước Giờ “Yêu”.jpg
MoviesUpcoming\Biệt Đội Săn Ma Kỷ Nguyên Băng Giá.jpg
MoviesUpcoming\Cái Giá Của Hạnh Phúc.jpg
MoviesUpcoming\Hòa Quang Đẫm Máu.jpg
MoviesUpcoming\Mùa Hè Của Luca.jpg
MoviesUpcoming\Ngày Tàn Của Đế Quốc.jpg
MoviesUpcoming\Người Bạn Trong Tưởng Tượng.jpg
MoviesUpcoming\Quỷ Cái.jpg
MoviesUpcoming\SUGA Agust D TOUR ‘D-DAY’ THE MOVIE.jpg
MoviesUpcoming\Trò Chơi Chết Chóc.jpg
MoviesUpcoming\Đóa Hoa Mong Manh.jpg
MoviesShowing\Abigail.jpg - https://www.youtube.com/watch?v=3PsP8MFH8p0
MoviesShowing\DUNE Phần Hai.jpg - https://www.youtube.com/watch?v=Svt6DK9T130
MoviesShowing\Exhuma Quật Mộ Trùng Ma.jpg - https://www.youtube.com/watch?v=7LH-TIcPqks
MoviesShowing\Godzilla X Kong Đế Chế Mới.jpg - https://www.youtube.com/watch?v=5XkgG_AAQs0
MoviesShowing\Kung Fu Panda 4.jpg - https://www.youtube.com/watch?v=_inKs4eeHiI
MoviesShowing\Mai.jpg - https://www.youtube.com/watch?v=EX6clvId19s
MoviesShowing\Mobile Suit Gundam SEED FREEDOM.jpg - https://www.youtube.com/watch?v=PcM1Nh3zoZM
MoviesShowing\Monkey Man.jpg - https://www.youtube.com/watch?v=g8zxiB5Qhsc
MoviesShowing\Muôn Vị Nhân Gian.jpg - https://www.youtube.com/watch?v=5APPENpUdu0
MoviesShowing\Người Chết Trở Về.jpg - https://www.youtube.com/watch?v=OcWPUd11mr0
MoviesShowing\Quỷ Thuật.jpg - https://www.youtube.com/watch?v=ZJQOD8ovRQc
MoviesShowing\Sáng Đèn.jpg - https://www.youtube.com/watch?v=jBC0GDOScSk
MoviesShowing\Thanh Xuân 18x2 Lữ Trình Hướng Về Em.jpg - https://www.youtube.com/watch?v=8Pq08VsVUFk
MoviesShowing\Điềm Báo Của Quỷ.jpg - https://www.youtube.com/watch?v=s3kWzhwsbpU
MoviesShowing\Đền Mạng.jpg - https://www.youtube.com/watch?v=Ys0SYxiI68Y
MoviesUpcoming\Anh Hùng Bàn Phím.jpg - https://www.youtube.com/watch?v=7GS72hn2VnA
MoviesUpcoming\B4S – Trước Giờ “Yêu”.jpg - https://www.youtube.com/watch?v=JJ_SyVWN9g0
MoviesUpcoming\Biệt Đội Săn Ma Kỷ Nguyên Băng Giá.jpg - https://www.youtube.com/watch?v=XDXgU6u3WXk
MoviesUpcoming\Cái Giá Của Hạnh Phúc.jpg - https://www.youtube.com/watch?v=79BznZKQwIQ
MoviesUpcoming\Hòa Quang Đẫm Máu.jpg - https://www.youtube.com/watch?v=N_ieracfsts
MoviesUpcoming\Mùa Hè Của Luca.jpg - https://www.youtube.com/watch?v=FzV3gRevq4Q
MoviesUpcoming\Ngày Tàn Của Đế Quốc.jpg - https://www.youtube.com/watch?v=QGlgPf9jGMA
MoviesUpcoming\Người Bạn Trong Tưởng Tượng.jpg - https://www.youtube.com/watch?v=EORcSY3j0dI
MoviesUpcoming\Quỷ Cái.jpg - https://www.youtube.com/watch?v=IUpYjuwetjY
MoviesUpcoming\SUGA Agust D TOUR ‘D-DAY’ THE MOVIE.jpg - https://www.youtube.com/watch?v=4mtUOuK7TOU
MoviesUpcoming\Trò Chơi Chết Chóc.jpg - https://www.youtube.com/watch?v=4_g8wD1pkjE
MoviesUpcoming\Đóa Hoa Mong Manh.jpg - https://www.youtube.com/watch?v=Qpf1SArSvyI

0 comments on commit a83e79a

Please sign in to comment.