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

Shows #5

Merged
merged 5 commits into from
Jul 12, 2017
Merged
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
60 changes: 32 additions & 28 deletions app/api/Butter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@
* The highest level abstraction layer for querying torrents and metadata
* @flow
*/
import TorrentAdapter from './torrents/TorrentAdapter'
import MetadataAdapter from './metadata/MetadataAdapter'
import PctMetadataProvider from './metadata/PctMetadataProvider'
import TraktMetadataProvider from './metadata/TraktMetadataProvider'
import MetadataAdapter from './Metadata/TraktMetadataProvider'
import PctTorrentProvider from './Torrents/PctTorrentProvider'
import TorrentAdapter from './Torrents'

export class Butter {

metadata: MetadataAdapter
metadataAdapter: MetadataAdapter

trakt: TraktMetadataProvider
pctAdapter: PctMetadataProvider
pctAdapter: PctTorrentProvider

torrentAdapter: TorrentAdapter

constructor() {
this.metadata = MetadataAdapter
this.pctAdapter = new PctMetadataProvider()
this.trakt = new TraktMetadataProvider()
this.pctAdapter = new PctTorrentProvider()
this.metadataAdapter = new MetadataAdapter()
this.torrentAdapter = new TorrentAdapter()
}

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

getMovie = (itemId: string) => this.pctAdapter.getMovie(itemId)

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

getShow = (itemId: string) => {
return this.pctAdapter.getShow(itemId).then(pctShow => {
getShow = (itemId: string) => this.pctAdapter.getShow(itemId)
.then(pctShow => this.metadataAdapter
.getSeasons(pctShow.id, pctShow.seasons)
.then(seasons => ({
...pctShow,
seasons,
})))

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

return pctShow
})
}
search = (...args) => this.torrentAdapter.search(...args)

searchTorrent = (itemId: string, type: string) => {
return TorrentAdapter(itemId, type, {}, false)
}
/*
searchTorrent = (itemId: string, type: string) => {
return TorrentAdapter(itemId, type, {}, false)
}
*/

/* getSeasons(itemId: string) {
return MetadataAdapter.getSeasons(itemId);
Expand All @@ -58,15 +60,17 @@ export class Butter {
return MetadataAdapter.getSimilar(type, itemId, 5);
}*/

/**
/*
/!**
* @param {string} itemId
* @param {string} type | Type of torrent: movie or show
* @param {object} extendedDetails | Additional details provided for heuristics
* @param {boolean} returnAll
*!/
getTorrent(itemId: string, type: string, extendedDetails: { [option: string]: string | number } = {}, returnAll: boolean = false) {
return TorrentAdapter(itemId, type, extendedDetails, returnAll)
}
*/
getTorrent(itemId: string, type: string, extendedDetails: { [option: string]: string | number } = {}, returnAll: boolean = false) {
return TorrentAdapter(itemId, type, extendedDetails, returnAll)
}

/* getSubtitles(itemId: string, filename: string, length: number, metadata: Object) {
return MetadataAdapter.getSubtitles(itemId, filename, length, metadata);
Expand Down
16 changes: 16 additions & 0 deletions app/api/Metadata/MetadataAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MetadataProviderInterface } from './MetadataProviderInterface'
import TraktMetadataProvider from './TraktMetadataProvider'

export class MetadataAdapter implements MetadataProviderInterface {

providers = [
new TraktMetadataProvider(),
]

getSeasons = (itemId: string, pctSeasons) => Promise.all(
this.providers.map(provider => provider.getSeasons(itemId, pctSeasons)),
)

}

export default MetadataAdapter
18 changes: 18 additions & 0 deletions app/api/Metadata/MetadataProviderInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import type { MovieType, ShowType } from './MetadataTypes'

export interface MetadataProviderInterface {

getMovies: (page: number, limit: number, options: optionsType) => Promise<MovieType>,

getMovie: (itemId: string) => MovieType,

getShows: (page: number, limit: number) => Promise<ShowType>,

getShow: (itemId: string) => ShowType,

getSeasons: (itemId: string, pctSeasons: Array) => Promise<void>,

getStatus: () => Promise<boolean>,

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import type { TorrentType } from 'api/Torrents/TorrentsTypes'

export type ContentType = {
id: string,
title: string,
Expand All @@ -8,36 +10,44 @@ export type ContentType = {
fanart: ImageType,
},
type: string,
rating: RatingType
rating: RatingType,
summary: string,
genres: string,
runtime: RuntimeType,
}

export type MovieType = ContentType & {
certification: string,
summary: string,
runtime: string,
trailer: string,
genres: string,
rating: string,
torrents: {
'1080p': TorrentType,
'720p': TorrentType,
},
}

export type ShowType = ContentType & {}
export type ShowType = ContentType & {
genres: string,
seasons: Array<SeasonType>,
}

export type TorrentType = {
url: string,
seeds: number,
peers: number,
size: number,
filesize: string,
provider: string,
health: {
text: string,
number: number,
color: string,
}
export type SeasonType = {
title: string,
summary: string,
number: number,
episodes: Array<EpisodeType>,
}

export type EpisodeType = {
id: string,
title: string,
number: number,
summary: string,
aired: number,
torrents: {
'1080p': TorrentType,
'720p': TorrentType,
'420p': TorrentType,
},
}

export type ImageType = {
Expand All @@ -58,13 +68,6 @@ export type RuntimeType = {
minutes: number
}

type seasonType = {}

type episodeType = seasonType & {}

export type certificationType = 'G' | 'PG' | 'PG-13' | 'R' | 'n/a'

export type imagesType = {}

// sort?: 'ratings' | 'popular' | 'trending',
export type optionsType = {}
export type filterType = {
sort?: 'populaity' | 'trending',
}
56 changes: 56 additions & 0 deletions app/api/Metadata/TraktMetadataProvider/TraktMetadataProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @flow
import Trakt from 'trakt.tv'
import hasOwnProperty from 'has-own-property'

import type { EpisodeType } from './TraktMetadataTypes'
import type { MetadataProviderInterface } from '../MetadataProviderInterface'

export default class TraktMetadataAdapter implements MetadataProviderInterface {

clientId = '647c69e4ed1ad13393bf6edd9d8f9fb6fe9faf405b44320a6b71ab960b4540a2'
clientSecret = 'f55b0a53c63af683588b47f6de94226b7572a6f83f40bd44c58a7c83fe1f2cb1'

trakt: Trakt

constructor() {
this.trakt = new Trakt({
client_id : this.clientId,
client_secret: this.clientSecret,
})
}

getSeasons(itemId: string, pctSeasons) {
return this.trakt.seasons
.summary({ id: itemId, extended: 'episodes,full' })
.then(response => response.filter(season => season.aired_episodes !== 0))
.then(seasons => this.formatSeasons(seasons, pctSeasons))
}

formatSeasons = (seasons, pctSeasons) => seasons.map(season => ({
title : season.title,
summary : season.overview,
number : season.number,
episodes: this.formatEpisodes(season.episodes, pctSeasons[season.number]),
}))

formatEpisodes = (episodes, pctSeason) => episodes.map((episode: EpisodeType) => ({
id : episode.ids.imdb,
title : episode.title,
summary : episode.overview,
number : episode.number,
aired : new Date(episode.first_aired).getTime(),
torrents: this.getEpisodeTorrents(episode, pctSeason),
}))

getEpisodeTorrents = (episode, pctSeason) => {
if (!pctSeason || !hasOwnProperty(pctSeason, episode.number)) {
return {
'1080p': null,
'720p' : null,
'480p' : null,
}
}

return pctSeason[episode.number].torrents
}
}
24 changes: 24 additions & 0 deletions app/api/Metadata/TraktMetadataProvider/TraktMetadataTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Created by tycho on 10/07/2017.
*/

export type EpisodeType = {
available_translations: Array,
first_aired: string,
ids: {
imbdb: string,
tmdb: number,
trakt: number,
tvdb: number,
tvrage: number,
}
number: number,
number_abs: number,
overview: string,
rating: number,
runtime: number,
season: number,
title: string,
updated_at: string,
votes: number,
}
1 change: 1 addition & 0 deletions app/api/Metadata/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './MetadataAdapter'
36 changes: 36 additions & 0 deletions app/api/Player/PlayerInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @flow
import type { MetadataType } from './PlayerProviderTypes'

export interface PlayerProviderInterface {

load: (uri: string, metadata: MetadataType) => Promise<void>,

play: (uri: ?string, metadata: ?MetadataType) => Promise<void>,

pause: () => Promise<void>,

stop: () => Promise<void>,

registerEvent: (event: string, callback: () => void) => void,

isPlaying: () => boolean,

/*provider: string,

supportedFormats: Array<string>,

supportsSubtitles: boolean,

svgIconFilename: string,

contentUrl: string,

port: number,

constructor: () => void,

restart: () => Promise<void>,

destroy: () => Promise<void>,*/

}
16 changes: 16 additions & 0 deletions app/api/Player/PlayerTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow
export type DeviceType = {
id: string,
name: string,
address: string,
port: number
}

export type MetadataType = {
title: string,
type: ?string,
image: {
poster: string
},
autoPlay: ?boolean,
}
Loading