Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature/minor fixes #192

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Welcome to **The MovieVerse** - your digital compass to the cinematic universe.

**This app is currently available at [movie-verse.com](https://movie-verse.com).**

---

## Table of Contents

- [User Interface](#user-interface)
Expand Down
2 changes: 1 addition & 1 deletion MovieVerse-Frontend/html/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ <h2 id="search-results-label">Search Results</h2>
</a>
<a href="trivia.html" class="bottom-bar-item">
<i class="fas fa-question-circle"></i>
<span>Movie Trivia</span>
<span>Trivia</span>
</a>
</div>

Expand Down
83 changes: 53 additions & 30 deletions MovieVerse-Frontend/js/movie-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,46 +818,64 @@ function getRatingDetails(rating) {
}

async function fetchMovieRatings(imdbId, tmdbMovieData) {
const omdbCode = `${getMovieCode2()}`;
const omdb = `https://${getMovieActor()}/?i=${imdbId}&${getMovieName()}${omdbCode}`;

try {
const response = await fetch(omdb);
const data = await response.json();
const apiKeys = [
await getMovieCode2(),
'58efe859',
'60a09d79',
'956e468a'
];

let imdbRating = data.imdbRating ? data.imdbRating : 'N/A';
const baseURL = `https://${getMovieActor()}/?i=${imdbId}&${getMovieName()}`;

if (imdbRating === 'N/A' && tmdbMovieData.vote_average) {
imdbRating = (tmdbMovieData.vote_average / 2).toFixed(1) * 2;
async function tryFetch(apiKey) {
const url = `${baseURL}${apiKey}`;
try {
const response = await fetch(url);
if (!response.ok) throw new Error('API limit reached or other error');
return await response.json();
} catch (error) {
return null;
}
}

const rtRatingObj = data.Ratings.find(rating => rating.Source === "Rotten Tomatoes");
let rtRating = rtRatingObj ? rtRatingObj.Value : 'N/A';
let data;
for (const key of apiKeys) {
data = await tryFetch(key);
if (data) break;
}

let metascore = data.Metascore ? `${data.Metascore}/100` : 'N/A';
let awards = data.Awards;
let rated = data.Rated ? data.Rated : 'Rating information unavailable';
if (!data) {
populateMovieDetails(tmdbMovieData, tmdbMovieData.vote_average, 'N/A', 'Metascore information unavailable, click to search on Metacritics', 'Awards information unavailable');
return;
}

if (awards === 'N/A') {
awards = 'Awards information unavailable';
}
let imdbRating = data.imdbRating ? data.imdbRating : 'N/A';
if (imdbRating === 'N/A' || imdbRating === '0.0') {
imdbRating = 'N/A';
}

if (metascore === 'N/A/100') {
const metacriticsRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
metascore = calculateFallbackMetacriticsRating(metacriticsRatingValue, tmdbMovieData.vote_average) + '/100';
}
const rtRatingObj = data.Ratings.find(rating => rating.Source === "Rotten Tomatoes");
let rtRating = rtRatingObj ? rtRatingObj.Value : 'N/A';

if (rtRating === 'N/A') {
const imdbRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
rtRating = calculateFallbackRTRating(imdbRatingValue, tmdbMovieData.vote_average)
}
let metascore = data.Metascore ? `${data.Metascore}/100` : 'N/A';
let awards = data.Awards;
let rated = data.Rated ? data.Rated : 'Rating information unavailable';

populateMovieDetails(tmdbMovieData, imdbRating, rtRating, metascore, awards, rated);
if (awards === 'N/A') {
awards = 'Awards information unavailable';
}
catch (error) {
const fallbackImdbRating = (tmdbMovieData.vote_average / 2).toFixed(1) * 2;
populateMovieDetails(tmdbMovieData, fallbackImdbRating, 'N/A', 'Metascore information unavailable, click to search on Metacritics', 'Awards information unavailable');

if (metascore === 'N/A/100') {
const metacriticsRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
metascore = calculateFallbackMetacriticsRating(metacriticsRatingValue, tmdbMovieData.vote_average) + '/100';
}

if (rtRating === 'N/A') {
const imdbRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
rtRating = calculateFallbackRTRating(imdbRatingValue, tmdbMovieData.vote_average)
}

populateMovieDetails(tmdbMovieData, imdbRating, rtRating, metascore, awards, rated);
}

function updateBrowserURL(title) {
Expand Down Expand Up @@ -1378,7 +1396,7 @@ async function populateMovieDetails(movie, imdbRating, rtRating, metascore, awar

function createImdbRatingCircle(imdbRating, imdbId) {
if (imdbRating === 'N/A' || imdbRating === null || imdbRating === undefined) {
imdbRating = 0;
imdbRating = 'N/A';
}

let circleContainer = document.getElementById('imdbRatingCircleContainer');
Expand All @@ -1397,6 +1415,11 @@ function createImdbRatingCircle(imdbRating, imdbId) {
<text id="imdbRatingText" class="circle-text" x="50" y="52" text-anchor="middle" fill="yellow" style="font-weight: bold; font-size: 25px">${imdbRating}</text>
</svg>
`;

if (imdbRating === 'N/A') {
circleContainer.innerHTML += `<p style="color: white; margin-top: 10px;">Rating information currently unavailable</p>`;
}

document.getElementById('movie-description').appendChild(circleContainer);
}
else {
Expand Down
10 changes: 5 additions & 5 deletions MovieVerse-Mobile/www/MovieVerse-Frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Welcome to the MovieVerse app, your ultimate guide to the world of movies! This

The MovieVerse app's `MovieVerse-Frontend` directory is organized into four primary directories: `css`, `html`, `js`, and `react`. Each directory contains specific files that contribute to the functionality and appearance of the app. Here's a detailed overview:

### CSS Directory
### CSS Directory - `css`

This directory contains the Cascading Style Sheets (CSS) files responsible for the styling of the web pages.

Expand All @@ -15,7 +15,7 @@ This directory contains the Cascading Style Sheets (CSS) files responsible for t
- `discussions.css`: Styles specific to the discussions page.
- `trivia.css`: Styles for the trivia section of the app.

### HTML Directory
### HTML Directory - `html`

The HTML directory includes all the markup files necessary for the structure of the web pages.

Expand Down Expand Up @@ -46,7 +46,7 @@ The HTML directory includes all the markup files necessary for the structure of
- `404.html`: A 404 error page for when a page is not found.
- `index.ejs`: The entry point for the app.

### JS Directory
### JS Directory - `js`

The JavaScript directory contains scripts that add interactivity and functionality to the web pages.

Expand All @@ -72,7 +72,7 @@ The JavaScript directory contains scripts that add interactivity and functionali
- `single-spa-config.js`: Configuration file for the single-spa framework used in the app.
- `systemjs-importmap.js`: Import map for the systemJS module loader.

### React Directory
### React Directory - `react`

The React directory contains a collection of React components developed for the MovieVerse application.

Expand All @@ -88,7 +88,7 @@ Please note that it is currently under development, and the components may under
- `UserProfile.jsx`: Component for managing user profiles
- `FeaturedMoviesCarousel.jsx`: Component for featured movies carousel

### Tests Directory
### Tests Directory - `tests`

The tests directory contains a collection of test scripts for the MovieVerse application. These tests are designed to ensure that the app's functionality is working as expected and to identify any potential issues or bugs.

Expand Down
2 changes: 1 addition & 1 deletion MovieVerse-Mobile/www/MovieVerse-Frontend/html/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ <h2 id="search-results-label">Search Results</h2>
</a>
<a href="trivia.html" class="bottom-bar-item">
<i class="fas fa-question-circle"></i>
<span>Movie Trivia</span>
<span>Trivia</span>
</a>
</div>

Expand Down
83 changes: 53 additions & 30 deletions MovieVerse-Mobile/www/MovieVerse-Frontend/js/movie-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,46 +818,64 @@ function getRatingDetails(rating) {
}

async function fetchMovieRatings(imdbId, tmdbMovieData) {
const omdbCode = `${getMovieCode2()}`;
const omdb = `https://${getMovieActor()}/?i=${imdbId}&${getMovieName()}${omdbCode}`;

try {
const response = await fetch(omdb);
const data = await response.json();
const apiKeys = [
await getMovieCode2(),
'58efe859',
'60a09d79',
'956e468a'
];

let imdbRating = data.imdbRating ? data.imdbRating : 'N/A';
const baseURL = `https://${getMovieActor()}/?i=${imdbId}&${getMovieName()}`;

if (imdbRating === 'N/A' && tmdbMovieData.vote_average) {
imdbRating = (tmdbMovieData.vote_average / 2).toFixed(1) * 2;
async function tryFetch(apiKey) {
const url = `${baseURL}${apiKey}`;
try {
const response = await fetch(url);
if (!response.ok) throw new Error('API limit reached or other error');
return await response.json();
} catch (error) {
return null;
}
}

const rtRatingObj = data.Ratings.find(rating => rating.Source === "Rotten Tomatoes");
let rtRating = rtRatingObj ? rtRatingObj.Value : 'N/A';
let data;
for (const key of apiKeys) {
data = await tryFetch(key);
if (data) break;
}

let metascore = data.Metascore ? `${data.Metascore}/100` : 'N/A';
let awards = data.Awards;
let rated = data.Rated ? data.Rated : 'Rating information unavailable';
if (!data) {
populateMovieDetails(tmdbMovieData, tmdbMovieData.vote_average, 'N/A', 'Metascore information unavailable, click to search on Metacritics', 'Awards information unavailable');
return;
}

if (awards === 'N/A') {
awards = 'Awards information unavailable';
}
let imdbRating = data.imdbRating ? data.imdbRating : 'N/A';
if (imdbRating === 'N/A' || imdbRating === '0.0') {
imdbRating = 'N/A';
}

if (metascore === 'N/A/100') {
const metacriticsRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
metascore = calculateFallbackMetacriticsRating(metacriticsRatingValue, tmdbMovieData.vote_average) + '/100';
}
const rtRatingObj = data.Ratings.find(rating => rating.Source === "Rotten Tomatoes");
let rtRating = rtRatingObj ? rtRatingObj.Value : 'N/A';

if (rtRating === 'N/A') {
const imdbRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
rtRating = calculateFallbackRTRating(imdbRatingValue, tmdbMovieData.vote_average)
}
let metascore = data.Metascore ? `${data.Metascore}/100` : 'N/A';
let awards = data.Awards;
let rated = data.Rated ? data.Rated : 'Rating information unavailable';

populateMovieDetails(tmdbMovieData, imdbRating, rtRating, metascore, awards, rated);
if (awards === 'N/A') {
awards = 'Awards information unavailable';
}
catch (error) {
const fallbackImdbRating = (tmdbMovieData.vote_average / 2).toFixed(1) * 2;
populateMovieDetails(tmdbMovieData, fallbackImdbRating, 'N/A', 'Metascore information unavailable, click to search on Metacritics', 'Awards information unavailable');

if (metascore === 'N/A/100') {
const metacriticsRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
metascore = calculateFallbackMetacriticsRating(metacriticsRatingValue, tmdbMovieData.vote_average) + '/100';
}

if (rtRating === 'N/A') {
const imdbRatingValue = imdbRating !== 'N/A' ? parseFloat(imdbRating) : (tmdbMovieData.vote_average / 2);
rtRating = calculateFallbackRTRating(imdbRatingValue, tmdbMovieData.vote_average)
}

populateMovieDetails(tmdbMovieData, imdbRating, rtRating, metascore, awards, rated);
}

function updateBrowserURL(title) {
Expand Down Expand Up @@ -1378,7 +1396,7 @@ async function populateMovieDetails(movie, imdbRating, rtRating, metascore, awar

function createImdbRatingCircle(imdbRating, imdbId) {
if (imdbRating === 'N/A' || imdbRating === null || imdbRating === undefined) {
imdbRating = 0;
imdbRating = 'N/A';
}

let circleContainer = document.getElementById('imdbRatingCircleContainer');
Expand All @@ -1397,6 +1415,11 @@ function createImdbRatingCircle(imdbRating, imdbId) {
<text id="imdbRatingText" class="circle-text" x="50" y="52" text-anchor="middle" fill="yellow" style="font-weight: bold; font-size: 25px">${imdbRating}</text>
</svg>
`;

if (imdbRating === 'N/A') {
circleContainer.innerHTML += `<p style="color: white; margin-top: 10px;">Rating information currently unavailable</p>`;
}

document.getElementById('movie-description').appendChild(circleContainer);
}
else {
Expand Down
3 changes: 1 addition & 2 deletions MovieVerse-Mobile/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,6 @@ <h2 id="other" style="cursor: pointer">Timeless Classics: Trending Classic Movie
searchInput.addEventListener('blur', clearSelection);
});
</script>

</body>

</html>
</html>
Loading