Skip to content

Commit

Permalink
Small start on shows
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Jul 10, 2017
1 parent 9d5cfad commit b702805
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 390 deletions.
15 changes: 14 additions & 1 deletion app/api/Butter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import TorrentAdapter from './torrents/TorrentAdapter'
import MetadataAdapter from './metadata/MetadataAdapter'
import PctMetadataProvider from './metadata/PctMetadataProvider'
import TraktMetadataProvider from './metadata/TraktMetadataProvider'

export class Butter {

metadata: MetadataAdapter

trakt: TraktMetadataProvider
pctAdapter: PctMetadataProvider

constructor() {
this.metadata = MetadataAdapter
this.pctAdapter = new PctMetadataProvider()
this.trakt = new TraktMetadataProvider()
}

getMovies = (page: number = 1, limit: number = 50) => this.pctAdapter.getMovies(page, limit)
Expand All @@ -23,7 +26,17 @@ export class Butter {

getShows = (page: number = 1, limit: number = 50) => this.pctAdapter.getShows(page, limit)

getShow = (itemId: string) => this.pctAdapter.getShow(itemId)
getShow = (itemId: string) => {
return this.pctAdapter.getShow(itemId).then(pctShow => {

// Deze wordt leidend! Episode info van pctShow hier in mergen
this.trakt.getSeasons(pctShow.id).then(show => {
console.log('trakt', show)
})

return pctShow
})
}

searchTorrent = (itemId: string, type: string) => {
return TorrentAdapter(itemId, type, {}, false)
Expand Down
9 changes: 7 additions & 2 deletions app/api/Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class Player implements PlayerProviderInterface {

plyrAdapter: PlyrPlayerProvider

lastPlayer = null

constructor() {
this.playerAdapter = new PlayerAdapter()
this.plyrAdapter = new PlyrPlayerProvider()
Expand Down Expand Up @@ -88,15 +90,18 @@ export class Player implements PlayerProviderInterface {
return null

default:
return this.plyrAdapter
return this.lastPlayer = this.plyrAdapter
}
}

getStatus = () => this.getRightPlayer().getStatus()

destroy() {
Torrent.destroy()
this.getRightPlayer().destroy()

if (this.lastPlayer) {
this.lastPlayer.destroy()
}
}

restart() {
Expand Down
1 change: 1 addition & 0 deletions app/api/Player/PlayerStatuses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const NONE = 'player.status.none'
export const PLAYING = 'player.status.playing'
export const LOADING = 'player.status.loading'
export const STREAMING = 'player.status.streaming'
Expand Down
3 changes: 1 addition & 2 deletions app/api/metadata/MetadataAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
import OpenSubtitles from 'opensubtitles-api'
import { merge, resolveCache, setCache } from '../torrents/BaseTorrentProvider'
import TheMovieDbMetadataProvider from './TheMovieDBMetadataProvider'
// import TraktMetadataProvider from './TraktMetadataProvider';
import type { runtimeType } from './MetadataProviderInterface'

Expand All @@ -28,7 +27,7 @@ const openSubtitles = new OpenSubtitles({
function MetadataAdapter() {
return [
// new TraktMetadataProvider(),
new TheMovieDbMetadataProvider()
// new TheMovieDbMetadataProvider()
]
}

Expand Down
31 changes: 29 additions & 2 deletions app/api/metadata/PctMetadataProvider/PctMetadataHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const formatImages = (images: ImageType) => {
}
}

export const formatTorrents = (torrents) => {
export const formatTorrents = (torrents, type = 'movie') => {
const getHealth = (seed, peer) => {
const ratio = seed && !!peer ? seed / peer : seed

Expand Down Expand Up @@ -48,16 +48,43 @@ export const formatTorrents = (torrents) => {
...torrent,
quality,
health: {
...getHealth(torrent.seed, torrent.peer),
...getHealth(torrent.seed || torrent.seeds, torrent.peer || torrent.peers),
},
})

if (type === 'movie') {
return {
'1080p': !torrents['1080p'] ? null : formatTorrent(torrents['1080p'], '1080p'),
'720p' : !torrents['720p'] ? null : formatTorrent(torrents['720p'], '720p'),
}
}

return {
'1080p': !torrents['1080p'] ? null : formatTorrent(torrents['1080p'], '1080p'),
'720p' : !torrents['720p'] ? null : formatTorrent(torrents['720p'], '720p'),
'480p' : !torrents['480p'] ? null : formatTorrent(torrents['480p'], '480p'),
}
}

export const formatRating = (rating: RatingType) => ({
stars: (rating.percentage / 100) * 5,
})

export const formatShowEpisodes = (episodes) => {
let seasons = []

episodes.map(episode => {
if (!seasons[episode.season]) {
seasons[episode.season] = []
}

seasons[episode.season][episode.episode] = {
summary : episode.overview,
season : episode.season,
episode : episode.episode,
torrents: formatTorrents(episode.torrents, 'show'),
}
})

return seasons
}
8 changes: 6 additions & 2 deletions app/api/metadata/PctMetadataProvider/PctMetadataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class PctMetadataProvider extends BaseMetadataProvider implements

getShow = (itemId: string) => (
this.popcornAPI.get(`show/${itemId}`)
.then(response => this.formatShow(response.data))
.then(response => this.formatShow(response.data, true))
)

formatMovies = (movies: Array<MovieType>) => (movies.map((movie: MovieType) => this.formatMovie(movie)))
Expand Down Expand Up @@ -66,7 +66,11 @@ export default class PctMetadataProvider extends BaseMetadataProvider implements
if (isDetail) {
formattedShow = {
...formattedShow,
episodes: show.episodes,
runtime : this.formatRuntimeMinutesToObject(show.runtime),
episodes: Helpers.formatShowEpisodes(show.episodes),
summary : show.synopsis,
genres : show.genres,
status : show.status,
}
}

Expand Down
Loading

0 comments on commit b702805

Please sign in to comment.