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

refactor 2020 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
MEDIA=./data/media
DATA=./data/data
DB=./data/db
CACHE=./data/cache
MEDIA_PATH=./data/media
DATA_PATH=./data/data
TRAKT_ID=
TRAKT_SECRET=
TRAKT_TOKEN=
TMDB_KEY=
PLAYER=mpv
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ coverage
/demo/public
.env*
!.env.example

data
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "lib/index.js",
"bin": "cli.js",
"scripts": {
"start": "NODE_ENV=development run-p start:dev:*",
"start": "NODE_ENV=development dotenv run-p start:dev:*",
"start:dev:backend": "NODE_ENV=development babel-watch src/index.js",
"start:dev:frontend": "NODE_ENV=development webpack-dev-server --config webpack.config.js --host 0.0.0.0",
"start:dev:frontend": "NODE_ENV=development webpack-dev-server --config webpack.config.js --port 8081",
"start:demo": "NODE_ENV=development webpack-dev-server --config demo/webpack.config.js --host 0.0.0.0",
"build": "npm-run-all --parallel build:backend build:frontend",
"build:backend": "babel -s -d lib src",
Expand Down Expand Up @@ -81,6 +81,7 @@
"morgan": "^1.6.1",
"nlp_compromise": "^6.4.1",
"node-cache": "^3.1.0",
"node-mpv": "ewnd9/Node-MPV",
"ohcrash": "^1.0.3",
"omxplayer": "0.0.1",
"opensubtitles-universal-api": "^1.1.0",
Expand Down
7 changes: 4 additions & 3 deletions src/players/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Player.prototype.play = function({ uri, media, position, traktScrobble }) {
};

Player.prototype.getFsUri = function(uri) {
return this.services.configService.MEDIA_PATH + '/' + uri;
return this.services.configService.mediaPath + '/' + uri;
};

Player.prototype.togglePlay = function() {
Expand Down Expand Up @@ -101,9 +101,10 @@ Player.prototype.updatePosition = function(position) {
this.emitUpdate();

if (positionCount % 10 === 0) {
if (this.traktScrobble) {
console.log({positionCount});
// if (this.traktScrobble) {
this.services.filesService.updatePosition(this.uri, this.media, position, this.duration);
}
// }
}

positionCount = (positionCount + 1) % 10;
Expand Down
97 changes: 97 additions & 0 deletions src/players/mpv-player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { inherits } from 'util';
import BasePlayer from './base';
import Mpv from 'node-mpv';

function MpvPlayer() {
BasePlayer.apply(this, Array.prototype.slice.apply(arguments));
}

inherits(MpvPlayer, BasePlayer);

MpvPlayer.prototype.play = function({ uri, position }) {
BasePlayer.prototype.play.apply(this, Array.prototype.slice.apply(arguments));

this.mpvPlayer = new Mpv();
this.mpvPlayer.load(this.getFsUri(uri), 'replace', {
start: 50000
});
this.mpvPlayer.once('started', () => {
console.log({start: position})
this.mpvPlayer.goToPosition(position);
// _player.play();
});
const metaInfo = {};

this.mpvPlayer.on('statuschange', status => {
if (status.path && !metaInfo[status.path]) {
metaInfo[status.path] = this.mpvPlayer.getProperty('track-list').then(res => {
const audio = res.filter(item => item.type === 'audio');
const subtitles = res.filter(item => item.type === 'sub');
const ret = {
audio,
subtitles,
};
console.log(ret);
return ret;
});
}
});

this.mpvPlayer.on('timeposition', (seconds) => {
console.log({seconds})
this.updatePosition(seconds);
});

// this.media = this.vlcProcess.mediaFromFile();
// this.media.parseSync();

// this.duration = this.media.duration;

// this.player = this.vlcProcess.mediaplayer;

// this.player.fullscreen = true;
// this.player.media = this.media;

// this.player.play();

// if (position) {
// this.player.position = position * 0.1 / this.media.duration;
// }

// this.startPolling();
};

MpvPlayer.prototype.resume = function() {
BasePlayer.prototype.resume.apply(this);
// this.mpvPlayer.resume();
};

MpvPlayer.prototype.pause = function() {
BasePlayer.prototype.pause.apply(this);
// this.mpvPlayer.pause();
};

MpvPlayer.prototype.stop = function () {
BasePlayer.prototype.stop.apply(this);
// this.player.quit();
};

MpvPlayer.prototype.startPolling = function() {
// this.poller = setInterval(() => {
// this.updatePosition(this.player.position * this.duration);
// }, 1000);
};

MpvPlayer.prototype.stopPolling = function() {
// clearInterval(this.poller);
};

MpvPlayer.onKeyPress = function(key) {
// if (key === OMX_KEYS.pause) {
// this.togglePlay();
// } else if (key === OMX_KEYS.stop) {
// this.stop();
// }
};

export default MpvPlayer;
2 changes: 1 addition & 1 deletion src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default ({ filesService, playerService }) => {
}

playerService
.play({ media: req.body.media, uri: req.body.filename, position: req.body.position, traktScrobble: !noScrobble });
.play({ media: req.body.media, uri: req.body.filename, position: req.body.media.position, traktScrobble: !noScrobble });

res.json({ status: 'ok' });
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/player-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
function getPlayer() {
if (process.env.PLAYER === 'vlc') {
return require('../players/vlc').default;
} else if (process.env.PLAYER === 'mpv') {
return require('../players/mpv-player').default;
} else if (process.env.PLAYER === 'mock') {
return require('../players/mock-player').default;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/services/posters-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ PostersService.prototype.getPosterStream = function(type, imdbId) {

PostersService.prototype.getPlaceholderPosterStream = function() {
const filePath = `${this.filePath}/placeholder.jpg`;
return fsCache(filePath, () => Promise.resolve('https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97300&w=200&h=300'));
return fsCache(filePath, () => Promise.resolve('https://via.placeholder.com/200x300'));
};
Loading