电影增加字段is_modify
This commit is contained in:
parent
539ff78e70
commit
c23a86e102
@ -44,6 +44,8 @@ const Movies = new Schema({
|
|||||||
price: {type: Number, default: 100},
|
price: {type: Number, default: 100},
|
||||||
// 是否是新记录
|
// 是否是新记录
|
||||||
is_new: {type: Boolean, default: true},
|
is_new: {type: Boolean, default: true},
|
||||||
|
// 是否已修改
|
||||||
|
is_modify: {type: Boolean, default: false},
|
||||||
// 视频分类,movie: 电影;tv: 电视剧; show: 综艺节目
|
// 视频分类,movie: 电影;tv: 电视剧; show: 综艺节目
|
||||||
category: {type: String},
|
category: {type: String},
|
||||||
// 是否已删除
|
// 是否已删除
|
||||||
@ -55,15 +57,32 @@ const Movies = new Schema({
|
|||||||
collection: 'movies',
|
collection: 'movies',
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
});
|
});
|
||||||
|
class MovieClass {
|
||||||
const MovieModel = mongoose.model('Movies', Movies);
|
static findByGid = function(gid) {
|
||||||
MovieModel.findByGid = function(gid) {
|
|
||||||
return MovieModel.findOne({gid: gid, deleted: false});
|
return MovieModel.findOne({gid: gid, deleted: false});
|
||||||
};
|
}
|
||||||
|
static updateOne = async function (gid, record) {
|
||||||
MovieModel.updateOne = async function (gid, record) {
|
|
||||||
const query = {gid: gid};
|
const query = {gid: gid};
|
||||||
const options = {upsert: true, setDefaultsOnInsert:true};
|
const options = {upsert: true, setDefaultsOnInsert:true};
|
||||||
await MovieModel.update(query, record, options);
|
await MovieModel.update(query, record, options);
|
||||||
}
|
}
|
||||||
|
updateResources(arr) {
|
||||||
|
let isModify = false;
|
||||||
|
if (this.resources.length !== arr.length) {
|
||||||
|
isModify = true;
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < this.resources.length; i ++) {
|
||||||
|
if (this.resources[i].title !== arr[i].title
|
||||||
|
|| this.resources[i].link !== arr[i].link) {
|
||||||
|
isModify = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.resources = arr;
|
||||||
|
this.is_modify = isModify;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Movies.loadClass(MovieClass);
|
||||||
|
const MovieModel = mongoose.model('Movies', Movies);
|
||||||
export default MovieModel;
|
export default MovieModel;
|
||||||
|
@ -77,9 +77,10 @@ const parseOnePage = async ({subLink, category, sortIdx}) => {
|
|||||||
category: category,
|
category: category,
|
||||||
sortIdx: sortIdx,
|
sortIdx: sortIdx,
|
||||||
is_new: true,
|
is_new: true,
|
||||||
|
is_modify: true,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
record.resources = resourceArr;
|
record.updateResources(resourceArr);
|
||||||
record.sortIdx = sortIdx;
|
record.sortIdx = sortIdx;
|
||||||
}
|
}
|
||||||
await record.save();
|
await record.save();
|
||||||
@ -170,17 +171,18 @@ const parseAllMovie = async (category, beginNo = 1) => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
run: async () => {
|
run: async () => {
|
||||||
return new Promise(async (resolve, reject) => {
|
// return new Promise(async (resolve, reject) => {
|
||||||
generalQueue.setCb(function () {
|
// generalQueue.setCb(function () {
|
||||||
console.log('====crawl movie finished', dateformat('yyyy-mm-dd HH:MM:ss'));
|
// console.log('====crawl movie finished', dateformat('yyyy-mm-dd HH:MM:ss'));
|
||||||
resolve()
|
// resolve()
|
||||||
})
|
// })
|
||||||
console.log('====crawl movie begin', dateformat('yyyy-mm-dd HH:MM:ss'));
|
// console.log('====crawl movie begin', dateformat('yyyy-mm-dd HH:MM:ss'));
|
||||||
await parseAllMovie('movie');
|
// await parseAllMovie('movie');
|
||||||
await parseAllMovie('tv');
|
// await parseAllMovie('tv');
|
||||||
await parseAllMovie('show');
|
// await parseAllMovie('show');
|
||||||
await parseAllMovie('cartoon');
|
// await parseAllMovie('cartoon');
|
||||||
})
|
// })
|
||||||
|
parseOnePage({subLink:'/dianshiju/31701.html', category:'tv', sortIdx:0});
|
||||||
|
|
||||||
},
|
},
|
||||||
parseListPage: parseListPage,
|
parseListPage: parseListPage,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user