Skip to content

Commit

Permalink
Merge pull request #278 from NymexData/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog authored Aug 3, 2023
2 parents 39c231a + f0203d7 commit 8d67476
Show file tree
Hide file tree
Showing 23 changed files with 447 additions and 98 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ https://chrome.google.com/webstore/detail/theaterflix-extension/phakiffpjmnaecdc
#### YouTube Video

<p align="center">
<a href="https://www.youtube.com/watch?v=BWHu_yDAe9w">
<a href="https://www.youtube.com/watch?v=lcYfPwwIKqI">
<img src="https://img.youtube.com/vi/BWHu_yDAe9w/0.jpg" alt="YouTube Video">
</a>
</p>
Expand Down Expand Up @@ -83,15 +83,15 @@ Exciting news! Our extension will soon be available for Chrome users, providing
--->

<p align="center">
<img src="./images/small_sshots_1.1.1/sshot_front.png" alt="Screenshot" width="400" height="350">
<img src="./images/small_sshots_1.1.2/sshot_front.png" alt="Screenshot" width="400" height="350">
</p>

<p align="center">
<img src="./images/small_sshots_1.1.1/sshot_top.png" alt="Screenshot" width="400" height="350">
<img src="./images/small_sshots_1.1.2/sshot_top.png" alt="Screenshot" width="400" height="350">
</p>

<p align="center">
<img src="./images/small_sshots_1.1.1/sshot_bottom.png" alt="Screenshot" width="400" height="350">
<img src="./images/small_sshots_1.1.2/sshot_bottom.png" alt="Screenshot" width="400" height="350">
</p>

#
Expand Down
Binary file modified images/.DS_Store
Binary file not shown.
Binary file removed images/screenshots/.DS_Store
Binary file not shown.
Binary file removed images/screenshots/v.1.1.0/.DS_Store
Binary file not shown.
Binary file removed images/screenshots/v.1.1.0/sshot_bottom.png
Binary file not shown.
Binary file removed images/screenshots/v.1.1.0/sshot_top.png
Binary file not shown.
Binary file modified images/small_sshots_1.1.1/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added images/small_sshots_1.1.2/sshot_bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/small_sshots_1.1.2/sshot_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/small_sshots_1.1.2/sshot_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"manifest_version": 3,
"name": "Theaterflix Extension",
"version": "1.1.1",
"description": "Extension to display personalized recommendations for movies and series.",
"version": "1.1.2",
"description": "Extension to display personalized worldwide recommendations for movies and series.",
"action": {
"default_popup": "popup/index.html"
},
"icons": {
"48": "assets/icon.png"
}
}

43 changes: 38 additions & 5 deletions popup/index.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Theaterflix Extension</title>
<link rel="stylesheet" href="../styles/styles.css">
<link rel="stylesheet" href="../styles/popup.css">
</head>

<body>

<div class="header">
<img src="../images/logo.png" alt="Theaterflix Logo" width="170" height="35">
<h1>Theaterflix Extension</h1>
<p>Explore a world of personalized movie and TV show recommendations! Our extension harnesses TMDb's vast database to deliver tailored content, enhancing your entertainment journey with seamless suggestions!</p>
<p>Explore a world of personalized movie and TV show recommendations! Our extension harnesses TMDb's vast database
to deliver tailored content, enhancing your entertainment journey with seamless suggestions!</p>
</div>

<div id="recommendations-list">
<!-- Recommendations will be displayed here -->
</div>

<button id="load-more-button" class="button">Load More</button>
<!-- Load More button -->
<button id="load-more-button" class="button" style="display: none;">Load More</button>

<!-- Configure API Key Section -->
<div class="accordion-header">Configure API Key</div>
<div id="config-section" class="active">
<label for="api-key">Enter your TMDb API Key:</label>
<input type="text" id="api-key" placeholder="Type your API Key here">
<input type="text" id="api-key" placeholder="Type your API Key here" pattern="[A-Za-z0-9]+"
title="Only letters and numbers are allowed for the API Key.">
<button id="save-button">Save</button>
<p id="status-message"></p>
<a href="#" id="refresh-button" class="button">Refresh</a>
</div>

<!-- Developer Info -->
<div class="developer-info">
<br>
Developed by <a href="https://github.com/felipealfonsog" target="_blank">Felipe Alfonso Gonzalez</a>, Computer Science Engineer
Developed by <a href="https://github.com/felipealfonsog" target="_blank">Felipe Alfonso Gonzalez</a>, Computer
Science Engineer
<br>
in collaboration with other members of Nymex Data Research.
<br>
Expand All @@ -50,14 +59,38 @@ <h1>Theaterflix Extension</h1>
<a href="https://www.themoviedb.org/" target="_blank" rel="noopener">
<img src="https://img.shields.io/badge/TMDb-Get%20API%20Key-red.svg?logo=themoviedatabase" alt="TMDb API Key">
</a>
<p>Get your API Key <a href="https://www.themoviedb.org/" target="_blank">here</a>! Sign up on TMDb to get your free API key for accessing movie data.</p>
<p>Get your API Key <a href="https://www.themoviedb.org/" target="_blank">here</a>! Sign up on TMDb to get your
free API key for accessing movie data.</p>
</div>

<!-- Mensaje con enlaces en inglés -->
<div class="api-key-info">
<p>Get your API Key to access movie and TV show data:</p>
<p>
<a href="https://kb.synology.com/en-my/DSM/tutorial/How_to_apply_for_a_personal_API_key_to_get_video_info" target="_blank">
Guide to obtain API Key in English
</a>
</p>
</div>

<!-- Mensaje con enlaces en español -->
<div class="api-key-info">
<p>Obtén tu API Key para acceder a los datos de películas y programas de TV:</p>
<p>
<a href="https://kb.synology.com/es-mx/DSM/tutorial/How_to_apply_for_a_personal_API_key_to_get_video_info" target="_blank">
Guía para obtener la API Key en español
</a>
</p>
</div>


</div>

<script src="../scripts/jquery-3.6.0.min.js"></script>
<script src="../scripts/axios.min.js"></script>
<script src="../scripts/api.js"></script>
<script src="../popup/popup.js"></script>

</body>

</html>
200 changes: 200 additions & 0 deletions popup/popup.bk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
document.addEventListener('DOMContentLoaded', () => {
const saveButton = document.getElementById('save-button');
const apiKeyInput = document.getElementById('api-key');
const statusMessage = document.getElementById('status-message');
const loadMoreButton = document.getElementById('load-more-button');
const recommendationsList = document.getElementById('recommendations-list');
const configSection = document.getElementById('config-section');
const refreshButton = document.getElementById('refresh-button');

let apiKey = '';
let page = 1;
const moviesPerPage = 20;
let movieRecommendations = [];

// Acordeón para la configuración
const accordionHeader = document.querySelector('.accordion-header');
accordionHeader.addEventListener('click', () => {
configSection.classList.toggle('active');
});

apiKeyInput.addEventListener('input', (event) => {
apiKey = event.target.value.trim();
validateApiKey(apiKey);
});

saveButton.addEventListener('click', () => {
if (!apiKey) {
statusMessage.textContent = 'Please enter a valid API Key.';
return;
}

if (!isValidApiKey(apiKey)) {
statusMessage.textContent = 'Please enter a valid API Key (letters and numbers only, no spaces).';
return;
}

localStorage.setItem('tmdb_api_key', apiKey);
statusMessage.textContent = 'API Key saved successfully!';
refreshRecommendations();
});

loadMoreButton.addEventListener('click', () => {
loadMoreRecommendations();
});

refreshButton.addEventListener('click', () => {
refreshRecommendations();
});

async function refreshRecommendations() {
if (!apiKey) {
statusMessage.textContent = 'Please enter a valid API Key before refreshing recommendations.';
return;
}

page = 1; // Reset page number on refresh

try {
const recommendations = await fetchMovieRecommendations();
movieRecommendations = recommendations;
renderMovieRecommendations();
loadMoreButton.style.display = 'block';
} catch (error) {
console.error('Error fetching movie recommendations:', error);
statusMessage.textContent = 'Error fetching movie recommendations. Please try again later.';
}
}

async function loadMoreRecommendations() {
if (!apiKey) {
statusMessage.textContent = 'Please enter a valid API Key before loading more recommendations.';
return;
}

page++;
try {
const recommendations = await fetchMovieRecommendations();
movieRecommendations.push(...recommendations);
renderMovieRecommendations();
loadMoreButton.style.display = 'block';
} catch (error) {
console.error('Error fetching movie recommendations:', error);
statusMessage.textContent = 'Error fetching movie recommendations. Please try again later.';
}
}

async function fetchMovieRecommendations() {
try {
const response = await axios.get(`https://api.themoviedb.org/3/movie/popular?api_key=${apiKey}&page=${page}`);
const movies = response.data.results;
const moviePromises = movies.map(async (movie) => {
const streamingInfo = await fetchStreamingInfo(apiKey, movie.id);
movie.streamingInfo = streamingInfo;
return movie;
});

const moviesWithStreamingInfo = await Promise.all(moviePromises);
return moviesWithStreamingInfo;
} catch (error) {
console.error('Error fetching movie recommendations:', error);
throw error;
}
}

async function fetchStreamingInfo(apiKey, movieId) {
try {
const response = await axios.get(`https://api.themoviedb.org/3/movie/${movieId}/watch/providers?api_key=${apiKey}`);
const results = response.data.results;
const streamingServices = new Set();

// Collect streaming information from all countries without duplicates
for (const country in results) {
if (results[country].flatrate) {
const countryStreamingServices = results[country].flatrate.map(service => service.provider_name);
countryStreamingServices.forEach(service => streamingServices.add(service));
}
}

return Array.from(streamingServices);
} catch (error) {
console.error('Error fetching streaming information:', error);
return [];
}
}

function renderMovieRecommendations() {
const startIndex = (page - 1) * moviesPerPage;
const endIndex = startIndex + moviesPerPage;
const visibleRecommendations = movieRecommendations.slice(0, endIndex);

recommendationsList.innerHTML = '';

visibleRecommendations.forEach((movie) => {
const movieBox = document.createElement('div');
movieBox.className = 'movie-box';

const moviePoster = document.createElement('img');
moviePoster.className = 'movie-poster';
moviePoster.src = `https://image.tmdb.org/t/p/w185${movie.poster_path}`;
movieBox.appendChild(moviePoster);

const movieInfo = document.createElement('div');
movieInfo.className = 'movie-info';

const movieTitle = document.createElement('h2');
movieTitle.textContent = movie.title;
movieInfo.appendChild(movieTitle);

const movieOverview = document.createElement('p');
movieOverview.textContent = movie.overview;
movieInfo.appendChild(movieOverview);

if (movie.streamingInfo && movie.streamingInfo.length > 0) {
const streamingInfo = document.createElement('p');
const services = movie.streamingInfo.join(', ');
streamingInfo.innerHTML = `<b>Available on:</b> ${services}`;
movieInfo.appendChild(streamingInfo);
} else {
const noStreamingInfo = document.createElement('p');
noStreamingInfo.textContent = 'Not available on any streaming service at the moment. Check local cinemas for availability.';
noStreamingInfo.style.fontWeight = 'bold'; // Make the message bold
movieInfo.appendChild(noStreamingInfo);
}

movieBox.appendChild(movieInfo);
recommendationsList.appendChild(movieBox);
});

if (endIndex >= movieRecommendations.length) {
loadMoreButton.style.display = 'none';
} else {
loadMoreButton.style.display = 'block';
}
}

function validateApiKey(apiKey) {
const apiKeyRegex = /^[A-Za-z0-9]+$/;
if (apiKeyRegex.test(apiKey)) {
statusMessage.textContent = '';
saveButton.disabled = false;
} else {
statusMessage.textContent = 'Please enter a valid API Key (letters and numbers only, no spaces).';
saveButton.disabled = true;
}
}

function isValidApiKey(apiKey) {
const apiKeyRegex = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+$/;
return apiKeyRegex.test(apiKey);
}

// Cargar API Key si existe en el almacenamiento local
const savedApiKey = localStorage.getItem('tmdb_api_key');
if (savedApiKey) {
apiKeyInput.value = savedApiKey;
apiKey = savedApiKey;
validateApiKey(apiKey);
refreshRecommendations();
}
});
Loading

0 comments on commit 8d67476

Please sign in to comment.