Skip to content

Commit

Permalink
fixed sort by trending
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris authored and Chris committed Mar 6, 2016
1 parent 75bb4c9 commit 3280e84
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.1 - What's trening? - 6 March 2016
======================================

Bug fixes:
- Sort by trending

1.0.0 - Let's kick some ass! - 1 March 2016
============================================

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# TV Series API
An Objectivly better TV series API for Popcorn Time.
An objectivly better TV series API for Popcorn Time.

# Installation
1. Install MongoDB
2. Install NodeJS
3. install dependencies `cd tvseries-api` and `npm install`
3. install dependencies `cd popcorn-api` and `npm install`
4. Start the API with `npm start` or `node --harmony --armony_destructuring --use_strict index.js`

# Example output
Expand All @@ -23,6 +23,7 @@ An Objectivly better TV series API for Popcorn Time.
"hated": ​100,
"loved": ​100,
"votes": ​34059,
"watching": 65,
"percentage": ​85
},
"country": "us",
Expand Down Expand Up @@ -74,7 +75,6 @@ An Objectivly better TV series API for Popcorn Time.

# Known Issues
The issues are listed in the code with a 'TODO'.
- In the client, sorting my trending (Go ask the .sh developers).
- Kat scraping gets stuck if kat.cr times out at getting the 'totalPages'.

# Versioning
Expand All @@ -97,4 +97,4 @@ If you distribute a copy or make a fork of the project, you have to credit this

--------------------------------------------------------------------------------

Copyright (c) 2016 - TV Series API - Released under the [GPL v3 license](LICENSE.txt).
Copyright (c) 2016 - Popcorn API - Released under the [GPL v3 license](LICENSE.txt).
9 changes: 8 additions & 1 deletion controllers/shows.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module.exports = {

let sort = {
"rating.votes": data.order,
"rating.percentage": data.order
"rating.percentage": data.order,
"rating.watching": data.order
};

if (data.keywords) {
Expand Down Expand Up @@ -83,6 +84,12 @@ module.exports = {
if (data.sort === "name") sort = {
title: (data.order * -1)
};
if (data.sort == "rating") sort = {
"rating.percentage": data.order
};
if (data.sort == "trending") sort = {
"rating.watching": data.order
};
}

if (data.genre && data.genre != "All") {
Expand Down
15 changes: 15 additions & 0 deletions lib/trakt.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ module.exports = {
}
});
return defer.promise;
},

/* Get people watching a given show. */
getShowWatching: (slug) => {
const defer = Q.defer();
request("shows/" + slug + "/watching", (err, res, body) => {
if (err) {
defer.reject(err + " with link: 'shows/" + slug + "/watching'");
} else if (!body || res.statusCode >= 400) {
defer.reject("Trakt: Could not find watching info on: '" + slug + "'");
} else {
defer.resolve(JSON.parse(body));
}
});
return defer.promise;
}

};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tvseries-api",
"name": "popcorn-api",
"version": "1.0.0",
"description": "An Objectivly better TV series API for Popcorn Time.",
"description": "An objectivly better TV series API for Popcorn Time.",
"dependencies": {
"async-q": "^0.3.1",
"body-parser": "^1.15.0",
Expand Down
2 changes: 1 addition & 1 deletion providers/eztv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let helper;
const getShow = function*(eztvShow) {
if (eztvShow) {
const imdb = yield eztv.getShowDetails(eztvShow);
const newShow = yield helper.getTraktInfo(imdb);
const newShow = yield util.spawn(helper.getTraktInfo(imdb));
const episodes = yield eztv.getAllEpisodes(eztvShow);

if (typeof(newShow) !== "undefined" && newShow._id && !episodes.dateBased) {
Expand Down
71 changes: 36 additions & 35 deletions providers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,43 @@ const Helper = (_name) => {
},

/* Get info from Trakt and make a new show object. */
getTraktInfo: (slug) => {
return trakt.getShow(slug).then((traktShow) => {
if (traktShow.ids["imdb"]) {
return {
_id: traktShow.ids["imdb"],
imdb_id: traktShow.ids["imdb"],
tvdb_id: traktShow.ids["tvdb"],
title: traktShow.title,
year: traktShow.year,
slug: slug,
synopsis: traktShow.overview,
runtime: traktShow.runtime,
rating: {
hated: 100,
loved: 100,
votes: traktShow.votes,
percentage: Math.round(traktShow.rating * 10)
},
country: traktShow.country,
network: traktShow.network,
air_day: traktShow.airs.day,
air_time: traktShow.airs.time,
status: traktShow.status,
num_seasons: 0,
last_updated: Number(new Date()),
images: {
/* TODO: have the failed image on localhost. */
fanart: traktShow.images.fanart.full != null ? traktShow.images.fanart.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png",
poster: traktShow.images.poster.full != null ? traktShow.images.poster.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png",
banner: traktShow.images.banner.full != null ? traktShow.images.banner.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png"
},
genres: traktShow.genres.length != 0 ? traktShow.genres : ["Unknown"],
episodes: []
}
getTraktInfo: function*(slug) {
const traktShow = yield trakt.getShow(slug);
const traktWatchers = yield trakt.getShowWatching(slug);
if (traktShow.ids["imdb"]) {
return {
_id: traktShow.ids["imdb"],
imdb_id: traktShow.ids["imdb"],
tvdb_id: traktShow.ids["tvdb"],
title: traktShow.title,
year: traktShow.year,
slug: slug,
synopsis: traktShow.overview,
runtime: traktShow.runtime,
rating: {
hated: 100,
loved: 100,
votes: traktShow.votes,
watching: traktWatchers.length,
percentage: Math.round(traktShow.rating * 10)
},
country: traktShow.country,
network: traktShow.network,
air_day: traktShow.airs.day,
air_time: traktShow.airs.time,
status: traktShow.status,
num_seasons: 0,
last_updated: Number(new Date()),
images: {
/* TODO: have the failed image on localhost. */
fanart: traktShow.images.fanart.full != null ? traktShow.images.fanart.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png",
poster: traktShow.images.poster.full != null ? traktShow.images.poster.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png",
banner: traktShow.images.banner.full != null ? traktShow.images.banner.full : "https://raw.githubusercontent.com/PTCE-Public/popcorn-desktop/master/src/app/images/posterholder.png"
},
genres: traktShow.genres.length != 0 ? traktShow.genres : ["Unknown"],
episodes: []
}
});
}
}

};
Expand Down
2 changes: 1 addition & 1 deletion providers/kat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let helper, name;

/* Get all the shows competable with Popcorn Time. */
const getShow = function*(katShow) {
const newShow = yield helper.getTraktInfo(katShow.slug)
const newShow = yield util.spawn(helper.getTraktInfo(katShow.slug));
if (typeof(newShow) != "undefined" && newShow._id && !katShow.dateBased) {
const slug = katShow.slug;

Expand Down

0 comments on commit 3280e84

Please sign in to comment.