Updated channels sorting function

This commit is contained in:
freearhey 2019-09-08 00:51:06 +03:00
parent c890fa0be7
commit ce4d2ed32c
1 changed files with 16 additions and 13 deletions

View File

@ -163,21 +163,23 @@ function getGzipped(url) {
})
}
function byTitle(a, b) {
var nameA = a.title.toLowerCase()
var nameB = b.title.toLowerCase()
if (nameA < nameB) {
return -1
}
if (nameA > nameB) {
return 1
}
function byTitleAndUrl(a, b) {
var titleA = a.title.toLowerCase()
var titleB = b.title.toLowerCase()
var urlA = a.url.toLowerCase()
var urlB = b.url.toLowerCase()
if(titleA < titleB) return -1
if(titleA > titleB) return 1
if(urlA < urlB) return -1
if(urlA > urlB) return 1
return 0
}
function sortByTitle(arr) {
return arr.sort(byTitle)
function sortByTitleAndUrl(arr) {
return arr.sort(byTitleAndUrl)
}
function readFile(filename) {
@ -215,8 +217,9 @@ function clearCache() {
function getUrlPath(u) {
let parsed = urlParser.parse(u)
let searchQuery = parsed.search || ''
let path = parsed.host + parsed.pathname + searchQuery
return parsed.host + parsed.pathname + searchQuery
return path.toLowerCase()
}
function validateUrl(channelUrl) {
@ -236,7 +239,7 @@ function skipPlaylist(filename) {
module.exports = {
parsePlaylist,
sortByTitle,
sortByTitleAndUrl,
appendToFile,
createFile,
readFile,