load theMovieDB info by movieID

This commit is contained in:
OldHawk
2017-03-29 19:02:28 +08:00
parent 95d856a07f
commit 23031a43c7
8 changed files with 135 additions and 17 deletions

View File

@@ -24,7 +24,7 @@
// Angular-ui-notification configuration
angular.module('ui-notification').config(function(NotificationProvider) {
NotificationProvider.setOptions({
delay: 2000,
delay: 4000,
startTop: 20,
startRight: 10,
verticalSpacing: 20,

View File

@@ -61,7 +61,14 @@
SELECT_TORRENT_FILE: '请选择种子文件',
SELECT_FILE: '选择文件',
DO_UPLOADS: '上传'
DO_UPLOADS: '上传',
ENTER_TMDB_ID: '请输入TMDB_ID',
LOAD_TMDB_INFO: '检索信息',
TMDB_ID: 'TMDB ID',
TMDB_ID_OK: 'MDB ID 正确,检索信息成功!',
TMDB_ID_ERROR: 'MDB ID 错误,检索信息失败!',
TMDB_ID_REQUIRED: '请输入 TMDB ID',
TMDB_MOVIE_INFO: 'TMDB 视频信息'
};
// **************************************************

View File

@@ -61,7 +61,14 @@
SELECT_TORRENT_FILE: 'Please select the torrent file',
SELECT_FILE: 'Select file',
DO_UPLOADS: 'Uploads'
DO_UPLOADS: 'Uploads',
ENTER_TMDB_ID: 'Please enter theMovieDB id  <span style="font-size: 10pt;">[<a href="https://www.themoviedb.org/" target="_blank">find id on themofiedb.org</a>]</span>',
LOAD_TMDB_INFO: 'Load info',
TMDB_ID: 'TMDB ID',
TMDB_ID_OK: 'MDB ID is ok! Get info successfully',
TMDB_ID_ERROR: 'MDB ID is error! Get info failed',
TMDB_ID_REQUIRED: 'Please enter TMDB ID',
TMDB_MOVIE_INFO: 'The movie info from TMDB'
};
// **************************************************

View File

@@ -5,15 +5,19 @@
.module('torrents')
.controller('TorrentsUploadsController', TorrentsUploadsController);
TorrentsUploadsController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'AnnounceConfig', 'Upload', 'Notification'];
TorrentsUploadsController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'AnnounceConfig', 'Upload', 'Notification',
'TorrentsService'];
function TorrentsUploadsController($scope, $state, $translate, $timeout, Authentication, AnnounceConfig, Upload, Notification) {
function TorrentsUploadsController($scope, $state, $translate, $timeout, Authentication, AnnounceConfig, Upload, Notification,
TorrentsService) {
var vm = this;
vm.announce = AnnounceConfig.announce;
vm.rule_items = [];
vm.movieinfoarray = [];
vm.user = Authentication.user;
vm.progress = 0;
vm.successfully = undefined;
vm.tmbd_info_ok = undefined;
for (var i = 0; i < $translate.instant('UPLOADS_RULES_COUNT'); i++) {
vm.rule_items[i] = i;
@@ -24,15 +28,15 @@
$state.go('authentication.signin');
}
//begin upload
//******************** begin upload torrent file *********************
vm.upload = function (dataUrl) {
console.log(dataUrl);
if(dataUrl===null){
if (dataUrl === null || dataUrl === undefined) {
vm.fileSelected = false;
// Show success message
Notification.success({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENTS_NO_FILE_SELECTED')
Notification.info({
message: '<i class="glyphicon glyphicon-info-sign"></i> ' + $translate.instant('TORRENTS_NO_FILE_SELECTED')
});
return;
}
@@ -54,7 +58,6 @@
});
};
// Called after the user has successfully uploaded a new picture
function onSuccessItem(response) {
vm.fileSelected = false;
vm.successfully = true;
@@ -64,7 +67,6 @@
});
}
// Called after the user has failed to upload a new picture
function onErrorItem(response) {
vm.fileSelected = false;
vm.successfully = false;
@@ -75,5 +77,52 @@
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENTS_UPLOAD_FAILED')
});
}
//************** begin get tmdb info ***********************************
vm.onTextClick = function ($event) {
$event.target.select();
};
vm.getInfo = function (tmdbid) {
console.log(tmdbid);
if (tmdbid === null || tmdbid === undefined) {
Notification.info({
message: '<i class="glyphicon glyphicon-info-sign"></i> ' + $translate.instant('TMDB_ID_REQUIRED')
});
angular.element('#tmdbid').focus();
return;
}
TorrentsService.getTMDBInfo({
tmdbid: tmdbid,
language: 'zh'
}, function (res) {
vm.tmbd_info_ok = true;
Notification.success({
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TMDB_ID_OK')
});
console.log(res);
vm.movieinfo = res;
for (var item in res) {
if(item[0]!=='$' && item!=='toJSON') {
var value = res[item];
var nv = {
key: item,
value: value
};
vm.movieinfoarray.push(nv);
}
}
console.log(vm.movieinfo);
}, function (err) {
vm.tmbd_info_ok = false;
Notification.error({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TMDB_ID_ERROR')
});
angular.element('#tmdbid').focus();
});
};
}
}());

View File

@@ -12,6 +12,14 @@
var Torrents = $resource('/api/torrents', {}, {
update: {
method: 'POST'
},
getTMDBInfo: {
method: 'GET',
url: '/api/movieinfo/:tmdbid/:language',
params: {
tmdbid: '@tmdbid',
language: '@language'
}
}
});

View File

@@ -12,7 +12,7 @@
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12">
<div class="col-md-12 col-sm-12 col-xs-12">
<legend class="small-legend" translate="SELECT_TORRENT_FILE"></legend>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="input-group">
@@ -21,6 +21,7 @@
<div class="input-group-btn">
<button class="btn btn-primary btn-file" ngf-select="vm.fileSelected = true; vm.successfully = undefined; vm.progress = 0;"
ng-model="tFile"
accept="application/x-bittorrent"
ngf-resize="{width: 400}"
ngf-resize-if="$width > 400 || $height > 400"
ng-disabled="vm.successfully">{{ 'SELECT_FILE' | translate}}
@@ -31,14 +32,56 @@
<div ng-show="vm.fileSelected" class="col-md-4 col-sm-4 col-xs-12">
<button class="btn btn-success" ng-click="vm.upload(tFile)">{{ 'DO_UPLOADS' | translate}} ({{vm.progress}}%)</button>
</div>
<div ng-show="vm.successfully == true" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 8px">
<div ng-show="vm.successfully == true" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 7px">
<label class="text-success control-label" translate="TORRENTS_UPLOAD_SUCCESSFULLY"></label>
</div>
<div ng-show="vm.successfully == false" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 8px">
<div ng-show="vm.successfully == false" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 7px">
<label class="text-danger control-label" translate="TORRENTS_UPLOAD_FAILED"></label>
</div>
</div>
</div>
<div class="row" style="margin-top: 40px;">
<div class="col-md-12 col-sm-12 col-xs-12">
<legend class="small-legend" translate="ENTER_TMDB_ID"></legend>
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-6">
<div class="input-group">
<input type="text" class="form-control" ng-ac ng-model="tmdbid"
id="tmdbid"
ng-change="vm.tmbd_info_ok = undefined"
ng-disabled="vm.tmbd_info_ok"
ng-focus="vm.onTextClick($event)"
placeholder="{{ 'TMDB_ID' | translate}}" autofocus>
<div class="input-group-btn">
<button class="btn btn-primary" ng-click="vm.getInfo(tmdbid)"
ng-disabled="vm.tmbd_info_ok">{{ 'LOAD_TMDB_INFO' | translate}}
</button>
</div>
</div>
</div>
<div ng-show="vm.tmbd_info_ok == true" class="col-lg-9 col-md-8 col-sm-7 col-xs-6" style="margin-top: 7px">
<label class="text-success control-label" translate="TMDB_ID_OK"></label>
</div>
<div ng-show="vm.tmbd_info_ok == false" class="col-lg-9 col-md-8 col-sm-7 col-xs-6" style="margin-top: 7px">
<label class="text-danger control-label" translate="TMDB_ID_ERROR"></label>
</div>
</div>
</div>
<div class="row" style="margin-top: 40px;">
<div class="col-md-12 col-sm-12 col-xs-12">
<legend class="small-legend" translate="TMDB_MOVIE_INFO"></legend>
<div class="col-md-4 col-sm-4 col-xs-12">
<img src="http://image.tmdb.org/t/p/w500/{{vm.movieinfo.poster_path}}" width="100%">
</div>
<div class="col-md-8 col-sm-8 col-xs-12">
<div ng-repeat="d in vm.movieinfoarray" class="row">
<div class="col-md-4"><strong>{{d.key}}</strong></div>
<div class="col-md-8">{{d.value}}</div>
</div>
</div>
</div>
</div>
</section>

View File

@@ -18,10 +18,14 @@ var path = require('path'),
*/
exports.movieinfo = function (req, res) {
console.log('------- API: movieinfo --------------------');
console.log(req.params);
tmdb.movieInfo({id: 263115, language: 'zh'}, function (err, info) {
tmdb.movieInfo({
id: req.params.tmdbid,
language: req.params.language
}, function (err, info) {
if (err) {
console.log(err);
res.status(900).send(err);
} else {
res.json(info);
}

View File

@@ -7,7 +7,7 @@ var torrents = require('../controllers/torrents.server.controller');
module.exports = function (app) {
// Articles collection routes
app.route('/api/movieinfo')
app.route('/api/movieinfo/:tmdbid/:language')
.get(torrents.movieinfo);
app.route('/api/torrents/upload')