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

Prettier Formatting #224

Merged
merged 3 commits into from
Jun 26, 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
165 changes: 165 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Development configuration can be loaded form this file via env variables
#
# To enable flags, create a .env file:
# ```
# cp .env.example .env
# ```
# and set the values in the new .env file to what you prefer



# ============================================================================
# Config:
#
# This set of configurations allow you to change the configuration of existing
# features.
# ============================================================================



# Download Location
#
# This configuration sets the folder where the downloads should be saved to.

CONFIG_DOWNLOAD_LOCATION=/tmp/popcorn-time-desktop



# Persist Donwloads
#
# Determine if downloaded content should not be deleted after usage. If this
# is set to false, files will be persist to the download location.

CONFIG_PERSIST_DOWNLOADS=false



# Cache Timeout
#
# Determine how long the API cache should be held. This is measured in hours.
# This includes the cache for Torrent Providers and Metadata Providers.

CONFIG_CACHE_TIMEOUT=1



# API Timeout
#
# Set the time, in milliseconds, that the API has to return. Increasing this
# may return faster torrents, but the API will take longer to find them.

CONFIG_API_TIMEOUT=10000



# Maximum Connections
#
# This sets the maximum number of network connections per torrent. This limits
# the bandwidth consumption so other apps can continue to function.

CONFIG_MAX_CONNECTIONS=20



# ============================================================================
# Flags:
#
# These allow you to enable experimental features or non-recommended in
# PopcornTime with the flip of a switch!
# ============================================================================



# English subtitles support
#
# This flag allows subtitles in torrents to be played along with the movie. Be
# careful, since this is a very early stage experiment! Currently this only
# allows English subtitles. Support for subtitles of multiple languages is
# planned for a future release.

FLAG_SUBTITLES=false



# Allow torrents that do not have a quality.
#
# Butter validates and filters torrents based on a number of factors. Sometimes
# torrents with a large seed count fail are filtered because their quality cannot
# be determined. This flag allows those torrents to be verified and will most
# likely increase the seed count of torrents at the cost of those torrents being
# unverified.

FLAG_UNVERIFIED_TORRENTS=false



# Allow 'complete season' torrents
#
# 'Complete Seasons' is an experiment that significantly increases the amount
# of seeders of torrents. In many cases, 'Complete Show' torrents offer
# significantly more torrents than the traditional 'Shows' method.
# 'Complete Seasons' works by querying a complete season of a show and downloading
# only the wanted episode. While this can increase torrent counts, it increases
# the time to fetch torrents.

FLAG_SEASON_COMPLETE=true



# Enable experimental casting support
#
# This feature allows casting to a external devices. Note that this will only
# work if you have a global installation of node. Also only chromecast
# devices are supported at the moment 😢 but support for Airplay, DLNA, and
# upup protocols is planned!

FLAG_CASTING=false



# Allow video whose subtitles are rendered as part of the movie.
#
# This makes removing them impossible. If you can tolerate these kinds of movies
# enable them and your will likely increase your seeder count.

FLAG_SUBTITLE_EMBEDDED_MOVIES=false



# Show multiple video qualities
#
# Ideally, PopcornTime would be able to select the best torrent for the user, as
# opposed to having them manually chose. Manually choosing allows users to pick
# which qualify (ex. 1080p, 720p, etc) of torrent they want.

FLAG_MANUAL_TORRENT_SELECTION=true



# Only play torrents that are natively supported
#
# Filter torrents that are not natively supported. This will drastically reduce
# the seeder count of tv shows, since most tv shows are in non-native formats
# (mkv, avi, and others). Use this only if your OS is not supported by
# PopcornTime yet.

FLAG_NATIVE_PLAYBACK_FILTERING=false



# ============================================================================
# Testing:
#
# This set of configuration is used for testing purposes only. It lets the
# compiler how to compile the app for the testing environment.
# ============================================================================



# Use Mock Data
#
# Force the API to use mock data. This method falls back to the network if no
# mock data is found. Mock data is located in ./tests/api/ and is named as
# *.mock.js.

API_USE_MOCK_DATA=false
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": [
"airbnb",
"bliss"
"bliss",
"prettier",
"prettier/flowtype",
"prettier/react"
],
"parser": "babel-eslint",
"env": {
Expand All @@ -10,6 +13,7 @@
},
"rules": {
"class-methods-use-this": "off",
"flowtype/boolean-style": ["error", "boolean"],
"flowtype/no-weak-types": "error",
"fp/no-arguments": "off",
"fp/no-class": "off",
Expand All @@ -34,7 +38,10 @@
"no-plusplus": "off",
"no-use-before-define": "off",
"no-console": "off",
"promise/avoid-new": "off"
"promise/avoid-new": "off",
"react/sort-comp": ["error", {
"order": ["type-annotations", "static-methods", "lifecycle", "everything-else", "render"]
}]
},
"settings": {
"import/extensions": [".jsx", ".js"],
Expand Down
8 changes: 5 additions & 3 deletions app/actions/homePageActions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @flow
export function setActiveMode(activeMode: string, activeModeOptions: Object = {}) {
import type { activeModeOptionsType, itemType } from '../components/home/Home.jsx';

export function setActiveMode(activeMode: string, activeModeOptions?: activeModeOptionsType = {}) {
return {
type: 'SET_ACTIVE_MODE',
activeMode,
activeModeOptions
};
}

export function paginate(items: Array<Object>) {
export function paginate(items: Array<itemType>) {
return {
type: 'PAGINATE',
items
Expand All @@ -26,7 +28,7 @@ export function clearAllItems() {
};
}

export function setLoading(isLoading: bool) {
export function setLoading(isLoading: boolean) {
return {
type: 'SET_LOADING',
isLoading
Expand Down
17 changes: 11 additions & 6 deletions app/api/Butter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import TorrentAdapter from './torrents/TorrentAdapter';
import MetadataAdapter from './metadata/MetadataAdapter';


export default class Butter {

getMovies(page: number = 1, limit: number = 50) {
return MetadataAdapter.getMovies(page, limit);
}
Expand Down Expand Up @@ -46,18 +44,25 @@ export default class Butter {
* @param {object} extendedDetails | Additional details provided for heuristics
* @param {boolean} returnAll
*/
getTorrent(imdbId: string,
getTorrent(
imdbId: string,
type: string,
extendedDetails: Object = {},
returnAll: bool = false) {
extendedDetails: { [option: string]: string | number } = {},
returnAll: boolean = false
) {
return TorrentAdapter(imdbId, type, extendedDetails, returnAll);
}

search(query: string, page: number = 1) {
return MetadataAdapter.search(query, page);
}

getSubtitles(imdbId: string, filename: string, length: number, metadata: Object) {
getSubtitles(
imdbId: string,
filename: string,
length: number,
metadata: Object
) {
return MetadataAdapter.getSubtitles(imdbId, filename, length, metadata);
}

Expand Down
37 changes: 25 additions & 12 deletions app/api/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import plyr from 'plyr';
import childProcess from 'child_process';
import vlcCommand from 'vlc-command';


const { powerSaveBlocker } = remote;

export default class Player {

currentPlayer = 'plyr';

powerSaveBlockerId: number;
Expand All @@ -18,7 +16,15 @@ export default class Player {
*/
player: plyr;

static nativePlaybackFormats = ['mp4', 'ogg', 'mov', 'webmv', 'mkv', 'wmv', 'avi'];
static nativePlaybackFormats = [
'mp4',
'ogg',
'mov',
'webmv',
'mkv',
'wmv',
'avi'
];

static experimentalPlaybackFormats = [];

Expand All @@ -41,13 +47,16 @@ export default class Player {
this.player.restart();
}

static isFormatSupported(filename: string, mimeTypes: Array<string>): bool {
return !!mimeTypes.find(
mimeType => filename.toLowerCase().includes(mimeType)
static isFormatSupported(
filename: string,
mimeTypes: Array<string>
): boolean {
return !!mimeTypes.find(mimeType =>
filename.toLowerCase().includes(mimeType)
);
}

initPlyr(streamingUrl: string, metadata: Object = {}): plyr {
initPlyr(streamingUrl: string, metadata = {}): plyr {
console.info('Initializing plyr...');
this.currentPlayer = 'plyr';
this.powerSaveBlockerId = powerSaveBlocker.start('prevent-app-suspension');
Expand All @@ -62,10 +71,12 @@ export default class Player {

player.source({
type: 'video',
sources: [{
src: streamingUrl,
type: 'video/mp4'
}],
sources: [
{
src: streamingUrl,
type: 'video/mp4'
}
],
...metadata
});

Expand All @@ -90,7 +101,9 @@ export default class Player {
});
}

this.powerSaveBlockerId = powerSaveBlocker.start('prevent-app-suspension');
this.powerSaveBlockerId = powerSaveBlocker.start(
'prevent-app-suspension'
);

return true;
});
Expand Down
19 changes: 14 additions & 5 deletions app/api/Subtitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ import fs from 'fs';
import srt2vtt from 'srt2vtt';
import rndm from 'rndm';


export const basePath = os.tmpdir();
export const port = process.env.SUBTITLES_PORT || 4000;
export const port = typeof process.env.SUBTITLES_PORT === 'number'
? parseInt(process.env.SUBTITLES_PORT, 10)
: 4000;

export type subtitleType = {
filename: string,
basePath: string,
port: number,
fullPath: string,
buffer: Buffer
};

/**
* Serve the file through http
Expand All @@ -27,13 +36,13 @@ export function closeServer(server: express): express {
return server.close();
}

export function convertFromBuffer(srtBuffer: Buffer): Promise<Object> {
export function convertFromBuffer(srtBuffer: Buffer): Promise<subtitleType> {
const randomString = rndm(16);
const filename = `${randomString}.vtt`;
const fullPath = path.join(basePath, filename);

return new Promise((resolve: Function, reject: Function) => {
srt2vtt(srtBuffer, (error: Error, vttBuffer: Buffer) => {
return new Promise((resolve, reject) => {
srt2vtt(srtBuffer, (error?: Error, vttBuffer: Buffer) => {
if (error) reject(error);

fs.writeFile(fullPath, vttBuffer, () => {
Expand Down
Loading