Skip to content

Commit

Permalink
requests to tmdb api async by fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan1986 committed Jan 16, 2024
1 parent 2bbc492 commit cb19d1d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 49 deletions.
21 changes: 4 additions & 17 deletions src/app/lib/views/browser/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
}
},

loadImage: function () {
loadImage: async function () {
var noimg = 'images/posterholder.png';
var poster = this.model.get('image');
if (!poster && this.model.get('images') && this.model.get('images').poster){
Expand All @@ -174,22 +174,9 @@
poster = this.model.get('poster');
} else {
var imdb = this.model.get('imdb_id'),
api_key = Settings.tmdb.api_key,
movie = (function () {
var tmp = null;
$.ajax({
url: 'http://api.themoviedb.org/3/movie/' + imdb + '?api_key=' + api_key + '&append_to_response=videos',
type: 'get',
dataType: 'json',
timeout: 5000,
async: false,
global: false,
success: function (data) {
tmp = data;
}
});
return tmp;
}());
api_key = Settings.tmdb.api_key;
const response = await fetch('http://api.themoviedb.org/3/movie/' + imdb + '?api_key=' + api_key + '&append_to_response=videos');
const movie = await response.json();
poster = movie && movie.poster_path ? 'http://image.tmdb.org/t/p/w500' + movie.poster_path : noimg;
this.model.set('poster', poster);
!this.model.get('synopsis') && movie && movie.overview ? this.model.set('synopsis', movie.overview) : null;
Expand Down
19 changes: 3 additions & 16 deletions src/app/lib/views/movie_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,27 +377,14 @@
}
},

openTmdb: function(e) {
openTmdb: async function(e) {
let imdb = this.model.get('imdb_id'),
tmdb = this.model.get('tmdb_id'),
api_key = Settings.tmdb.api_key;

if (!tmdb && !this.model.get('getmetarunned')) {
let movie = (function () {
let tmp = null;
$.ajax({
url: 'http://api.themoviedb.org/3/find/' + imdb + '?api_key=' + api_key + '&external_source=imdb_id',
type: 'get',
dataType: 'json',
timeout: 5000,
async: false,
global: false,
success: function (data) {
tmp = data;
}
});
return tmp;
}());
const response = await fetch('http://api.themoviedb.org/3/movie/' + imdb + '?api_key=' + api_key + '&external_source=imdb_id');
const movie = await response.json();
movie && movie.movie_results && movie.movie_results[0] && movie.movie_results[0].id ? this.model.set('tmdb_id', movie.movie_results[0].id) : null;
tmdb = this.model.get('tmdb_id');
}
Expand Down
19 changes: 3 additions & 16 deletions src/app/lib/views/show_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,27 +414,14 @@
}
},

openTmdb: function(e) {
openTmdb: async function(e) {
let imdb = this.model.get('imdb_id'),
tmdb = this.model.get('tmdb_id'),
api_key = Settings.tmdb.api_key;

if (!tmdb) {
let show = (function () {
let tmp = null;
$.ajax({
url: 'http://api.themoviedb.org/3/find/' + imdb + '?api_key=' + api_key + '&external_source=imdb_id',
type: 'get',
dataType: 'json',
timeout: 5000,
async: false,
global: false,
success: function (data) {
tmp = data;
}
});
return tmp;
}());
const response = await fetch('http://api.themoviedb.org/3/movie/' + imdb + '?api_key=' + api_key + '&external_source=imdb_id');
const show = await response.json();
show && show.tv_results && show.tv_results[0] && show.tv_results[0].id ? this.model.set('tmdb_id', show.tv_results[0].id) : null;
tmdb = this.model.get('tmdb_id');
}
Expand Down

0 comments on commit cb19d1d

Please sign in to comment.