Introduce searchFirstDetail

This commit is contained in:
haiyangcui
2021-04-12 16:48:58 +02:00
parent da5531a947
commit 9ec65ab027
3 changed files with 66 additions and 33 deletions

View File

@@ -343,11 +343,9 @@ export default {
if (recommendations) {
this.info.recommendations = []
recommendations.forEach(element => {
zy.search(this.detail.key, element).then(res => {
if (res) {
zy.detail(this.detail.key, res[0].id).then(detailRes => {
this.info.recommendations.push(detailRes)
})
zy.searchFirstDetail(this.detail.key, element).then(detailRes => {
if (detailRes) {
this.info.recommendations.push(detailRes)
}
})
})

View File

@@ -264,20 +264,18 @@ export default {
axios.get(doubleUrl).then(res => {
if (res.data) {
res.data.subjects.forEach(element => {
zy.search(this.sites[0].key, element.title).then(res => {
if (res && res[0] && res[0].name === element.title) {
zy.detail(this.sites[0].key, res[0].id).then(detailRes => {
const doc = {
key: this.sites[0].key,
ids: res[0].id,
site: this.sites[0],
name: res[0].name,
detail: detailRes,
rate: element.rate
}
this.recommendationsDoubanMovie.push(doc)
this.recommendations.push(doc)
})
zy.searchFirstDetail(this.sites[0].key, element.title).then(detailRes => {
if (detailRes) {
const doc = {
key: this.sites[0].key,
ids: detailRes.id,
site: this.sites[0],
name: detailRes.name,
detail: detailRes,
rate: element.rate
}
this.recommendationsDoubanMovie.push(doc)
this.recommendations.push(doc)
}
})
})
@@ -294,20 +292,20 @@ export default {
axios.get(doubleUrl).then(res => {
if (res.data) {
res.data.subjects.forEach(element => {
zy.search(this.sites[0].key, element.title).then(res => {
if (res && res[0] && res[0].name === element.title) {
zy.detail(this.sites[0].key, res[0].id).then(detailRes => {
const doc = {
key: this.sites[0].key,
ids: res[0].id,
site: this.sites[0],
name: res[0].name,
detail: detailRes,
rate: element.rate
}
this.recommendationsDoubanTV.push(doc)
this.recommendations.push(doc)
})
console.log('searching ' + element.title)
zy.searchFirstDetail(this.sites[0].key, element.title).then(detailRes => {
console.log(detailRes)
if (detailRes) {
const doc = {
key: this.sites[0].key,
ids: detailRes.id,
site: this.sites[0],
name: detailRes.name,
detail: detailRes,
rate: element.rate
}
this.recommendationsDoubanTV.push(doc)
this.recommendations.push(doc)
}
})
})

View File

@@ -240,6 +240,43 @@ const zy = {
})
})
},
/**
* 搜索资源详情
* @param {*} key 资源网 key
* @param {*} wd 搜索关键字
* @returns
*/
searchFirstDetail (key, wd) {
return new Promise((resolve, reject) => {
this.getSite(key).then(res => {
const site = res
const url = `${site.api}?wd=${encodeURI(wd)}`
axios.get(url, { timeout: 3000 }).then(res => {
const data = res.data
const json = parser.parse(data, this.xmlConfig)
const jsondata = json?.rss === undefined ? json : json.rss
if (json && jsondata && jsondata.list) {
let videoList = jsondata.list.video
if (Object.prototype.toString.call(videoList) === '[object Object]') videoList = [].concat(videoList)
videoList = videoList?.filter(e => e.name.toLowerCase().includes(wd.toLowerCase()))
if (videoList?.length) {
this.detail(key, videoList[0].id).then(detailRes => {
resolve(detailRes)
})
} else {
resolve()
}
} else {
resolve()
}
}).catch(err => {
reject(err)
})
}).catch(err => {
reject(err)
})
})
},
/**
* 获取资源详情
* @param {*} key 资源网 key