mirror of
https://github.com/cuiocean/ZY-Player.git
synced 2026-02-10 14:05:05 +08:00
支持 txt 文件格式的 直播源 和 视频源本地导入.
This commit is contained in:
@@ -379,31 +379,58 @@ export default {
|
||||
}
|
||||
const options = {
|
||||
filters: [
|
||||
{ name: 'JSON file', extensions: ['json'] }
|
||||
{ name: 'JSON file', extensions: ['json'] },
|
||||
{ name: 'Text file', extensions: ['txt'] }
|
||||
],
|
||||
properties: ['openFile', 'multiSelections']
|
||||
}
|
||||
remote.dialog.showOpenDialog(options).then(result => {
|
||||
if (!result.canceled) {
|
||||
result.filePaths.forEach(file => {
|
||||
const str = fs.readFileSync(file)
|
||||
const json = JSON.parse(str)
|
||||
json.forEach(ele => {
|
||||
if (ele.api && this.sites.filter(x => x.key === ele.key).length === 0 && this.sites.filter(x => x.name === ele.name && x.api === ele.api).length === 0) {
|
||||
// 不含该key 同时也不含名字和url一样的
|
||||
if (ele.isActive === undefined) {
|
||||
ele.isActive = true
|
||||
if (file.endsWith('json')) {
|
||||
const str = fs.readFileSync(file)
|
||||
const json = JSON.parse(str)
|
||||
json.forEach(ele => {
|
||||
if (ele.api && this.sites.filter(x => x.key === ele.key).length === 0 && this.sites.filter(x => x.name === ele.name && x.api === ele.api).length === 0) {
|
||||
// 不含该key 同时也不含名字和url一样的
|
||||
if (ele.isActive === undefined) {
|
||||
ele.isActive = true
|
||||
}
|
||||
if (ele.group === undefined) {
|
||||
ele.group = '导入'
|
||||
}
|
||||
this.sites.push(ele)
|
||||
}
|
||||
if (ele.group === undefined) {
|
||||
ele.group = '导入'
|
||||
}
|
||||
this.sites.push(ele)
|
||||
})
|
||||
this.resetId(this.sites)
|
||||
sites.clear().then(sites.bulkAdd(this.sites))
|
||||
this.$message.success('导入成功')
|
||||
this.getSites()
|
||||
}
|
||||
if (file.endsWith('txt')) {
|
||||
try {
|
||||
const txt = fs.readFileSync(file, 'utf8')
|
||||
const json = JSON.parse(txt)
|
||||
json.forEach(ele => {
|
||||
if (ele.api && this.sites.filter(x => x.key === ele.key).length === 0 && this.sites.filter(x => x.name === ele.name && x.api === ele.api).length === 0) {
|
||||
// 不含该key 同时也不含名字和url一样的
|
||||
if (ele.isActive === undefined) {
|
||||
ele.isActive = true
|
||||
}
|
||||
if (ele.group === undefined) {
|
||||
ele.group = '导入'
|
||||
}
|
||||
this.sites.push(ele)
|
||||
}
|
||||
})
|
||||
this.resetId(this.sites)
|
||||
sites.clear().then(sites.bulkAdd(this.sites))
|
||||
this.$message.success('导入成功')
|
||||
this.getSites()
|
||||
} catch (error) {
|
||||
this.$message.warning('导入失败')
|
||||
}
|
||||
})
|
||||
this.resetId(this.sites)
|
||||
sites.clear().then(sites.bulkAdd(this.sites))
|
||||
this.$message.success('导入成功')
|
||||
this.getSites()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -352,7 +352,8 @@ export default {
|
||||
const options = {
|
||||
filters: [
|
||||
{ name: 'm3u file', extensions: ['m3u', 'm3u8'] },
|
||||
{ name: 'JSON file', extensions: ['json'] }
|
||||
{ name: 'JSON file', extensions: ['json'] },
|
||||
{ name: 'Text file', extensions: ['txt'] }
|
||||
],
|
||||
properties: ['openFile', 'multiSelections']
|
||||
}
|
||||
@@ -389,8 +390,8 @@ export default {
|
||||
this.updateChannelList()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
// Import Json file
|
||||
}
|
||||
if (file.endsWith('json')) {
|
||||
const importedList = JSON.parse(fs.readFileSync(file))
|
||||
importedList.forEach(ele => {
|
||||
const commonEle = this.channelList.find(e => e.name === ele.name)
|
||||
@@ -405,6 +406,26 @@ export default {
|
||||
})
|
||||
this.updateDatabase()
|
||||
}
|
||||
if (file.endsWith('txt')) {
|
||||
try {
|
||||
const txt = fs.readFileSync(file, 'utf8')
|
||||
const importedList = JSON.parse(txt)
|
||||
importedList.forEach(ele => {
|
||||
const commonEle = this.channelList.find(e => e.name === ele.name)
|
||||
if (commonEle) {
|
||||
const urls = commonEle.channels.map(c => c.url)
|
||||
const channels = ele.channels.filter(e => !urls.includes(e.url))
|
||||
commonEle.channels = commonEle.channels.concat(channels)
|
||||
} else {
|
||||
ele.id = this.channelList.length ? this.channelList.slice(-1)[0].id + 1 : 1
|
||||
this.channelList.push(ele)
|
||||
}
|
||||
})
|
||||
this.updateDatabase()
|
||||
} catch (error) {
|
||||
this.$message.warning('导入失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
this.$message.success('导入成功')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user