mirror of
https://github.com/iptv-org/database.git
synced 2024-11-09 22:16:38 -05:00
Update update.js
This commit is contained in:
parent
6a687675b2
commit
99260fb76a
1 changed files with 68 additions and 17 deletions
|
@ -13,27 +13,18 @@ const DATA_DIR = process.env.DATA_DIR || './data'
|
||||||
const OWNER = 'iptv-org'
|
const OWNER = 'iptv-org'
|
||||||
const REPO = 'database'
|
const REPO = 'database'
|
||||||
|
|
||||||
|
let channels = []
|
||||||
|
let processedIssues = []
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const filepath = `${DATA_DIR}/channels.csv`
|
const filepath = `${DATA_DIR}/channels.csv`
|
||||||
let channels = await csv.fromFile(filepath)
|
channels = await csv.fromFile(filepath)
|
||||||
const issues = await fetchIssues('channels:add,approved')
|
|
||||||
const processedIssues = []
|
|
||||||
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
|
||||||
if (!channel) {
|
|
||||||
updateIssue(issue, { labels: ['channels:add', 'rejected:invalid'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const found = channels.find(c => c.id === channel.id)
|
await editChannels()
|
||||||
if (found) {
|
await addChannels()
|
||||||
updateIssue(issue, { labels: ['channels:add', 'rejected:duplicate'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channels.push(channel)
|
console.log(channels[463])
|
||||||
processedIssues.push(issue)
|
|
||||||
})
|
|
||||||
|
|
||||||
channels = _.orderBy(channels, [channels => channels.id.toLowerCase()], ['asc'])
|
channels = _.orderBy(channels, [channels => channels.id.toLowerCase()], ['asc'])
|
||||||
await csv.save(filepath, channels)
|
await csv.save(filepath, channels)
|
||||||
|
@ -47,6 +38,53 @@ async function main() {
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
async function editChannels() {
|
||||||
|
const issues = await fetchIssues('channels:edit,approved')
|
||||||
|
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
||||||
|
if (!channel) {
|
||||||
|
updateIssue(issue, { labels: ['channels:edit', 'rejected:invalid'] })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = _.findIndex(channels, { id: channel.id })
|
||||||
|
if (!index) {
|
||||||
|
updateIssue(issue, { labels: ['channels:edit', 'rejected:invalid'] })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const found = channels[index]
|
||||||
|
|
||||||
|
for (let prop in channel) {
|
||||||
|
if (channel[prop] !== undefined) {
|
||||||
|
found[prop] = channel[prop]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
channels.splice(index, 1, found)
|
||||||
|
|
||||||
|
processedIssues.push(issue)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addChannels() {
|
||||||
|
const issues = await fetchIssues('channels:add,approved')
|
||||||
|
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
||||||
|
if (!channel) {
|
||||||
|
updateIssue(issue, { labels: ['channels:add', 'rejected:invalid'] })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const found = channels.find(c => c.id === channel.id)
|
||||||
|
if (found) {
|
||||||
|
updateIssue(issue, { labels: ['channels:add', 'rejected:duplicate'] })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channels.push(channel)
|
||||||
|
processedIssues.push(issue)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchIssues(labels) {
|
async function fetchIssues(labels) {
|
||||||
const issues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
|
const issues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
|
||||||
owner: OWNER,
|
owner: OWNER,
|
||||||
|
@ -77,20 +115,31 @@ function parseIssue(issue) {
|
||||||
const buffer = {}
|
const buffer = {}
|
||||||
const channel = {}
|
const channel = {}
|
||||||
const fields = {
|
const fields = {
|
||||||
|
'Channel ID (required)': 'id',
|
||||||
'Channel Name': 'name',
|
'Channel Name': 'name',
|
||||||
|
'Alternative Names': 'alt_names',
|
||||||
'Alternative Names (optional)': 'alt_names',
|
'Alternative Names (optional)': 'alt_names',
|
||||||
|
Network: 'network',
|
||||||
'Network (optional)': 'network',
|
'Network (optional)': 'network',
|
||||||
|
Owners: 'owners',
|
||||||
'Owners (optional)': 'owners',
|
'Owners (optional)': 'owners',
|
||||||
Country: 'country',
|
Country: 'country',
|
||||||
|
Subdivision: 'subdivision',
|
||||||
'Subdivision (optional)': 'subdivision',
|
'Subdivision (optional)': 'subdivision',
|
||||||
|
City: 'city',
|
||||||
'City (optional)': 'city',
|
'City (optional)': 'city',
|
||||||
'Broadcast Area': 'broadcast_area',
|
'Broadcast Area': 'broadcast_area',
|
||||||
Languages: 'languages',
|
Languages: 'languages',
|
||||||
|
Categories: 'categories',
|
||||||
'Categories (optional)': 'categories',
|
'Categories (optional)': 'categories',
|
||||||
NSFW: 'is_nsfw',
|
NSFW: 'is_nsfw',
|
||||||
|
Launched: 'launched',
|
||||||
'Launched (optional)': 'launched',
|
'Launched (optional)': 'launched',
|
||||||
|
Closed: 'closed',
|
||||||
'Closed (optional)': 'closed',
|
'Closed (optional)': 'closed',
|
||||||
|
'Replaced By': 'replaced_by',
|
||||||
'Replaced By (optional)': 'replaced_by',
|
'Replaced By (optional)': 'replaced_by',
|
||||||
|
Website: 'website',
|
||||||
'Website (optional)': 'website',
|
'Website (optional)': 'website',
|
||||||
Logo: 'logo'
|
Logo: 'logo'
|
||||||
}
|
}
|
||||||
|
@ -112,7 +161,9 @@ function parseIssue(issue) {
|
||||||
channel[field] = buffer[field]
|
channel[field] = buffer[field]
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.id = generateChannelId(channel.name, channel.country)
|
if (!channel.id) {
|
||||||
|
channel.id = generateChannelId(channel.name, channel.country)
|
||||||
|
}
|
||||||
|
|
||||||
return { issue, channel }
|
return { issue, channel }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue