2020-02-16 19:30:00 +01:00
|
|
|
import ytdl from 'ytdl-core'
|
|
|
|
import ytsr from 'ytsr'
|
|
|
|
import ytpl from 'ytpl'
|
|
|
|
|
2020-03-01 04:37:02 +01:00
|
|
|
import IsEqual from 'lodash.isequal'
|
2021-01-16 04:08:50 +01:00
|
|
|
import { SocksProxyAgent } from 'socks-proxy-agent'
|
|
|
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
|
|
|
import { HttpProxyAgent } from 'http-proxy-agent'
|
2020-03-01 04:37:02 +01:00
|
|
|
|
2020-02-16 19:30:00 +01:00
|
|
|
const state = {
|
|
|
|
main: 0,
|
|
|
|
isYtSearchRunning: false
|
|
|
|
}
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
getMain ({ state }) {
|
|
|
|
return state.main
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions = {
|
2020-03-01 20:44:19 +01:00
|
|
|
ytSearch ({ commit, dispatch, rootState }, payload) {
|
2020-02-16 19:30:00 +01:00
|
|
|
console.log('Performing search please wait...')
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (state.isYtSearchRunning) {
|
|
|
|
console.log('search is running. please try again')
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:22:05 +01:00
|
|
|
if (typeof payload.options.nextpageRef !== 'undefined') {
|
|
|
|
const continuation = payload.options.nextpageRef
|
2020-12-14 20:52:22 +01:00
|
|
|
const nextPageResults = ytsr.continueReq(continuation)
|
|
|
|
resolve(nextPageResults)
|
2020-12-17 17:22:05 +01:00
|
|
|
return
|
2020-12-14 20:52:22 +01:00
|
|
|
}
|
|
|
|
|
2020-03-01 04:37:02 +01:00
|
|
|
const defaultFilters = {
|
|
|
|
sortBy: 'relevance',
|
|
|
|
time: '',
|
|
|
|
type: 'all',
|
|
|
|
duration: ''
|
|
|
|
}
|
|
|
|
|
2021-01-17 17:09:51 +01:00
|
|
|
let agent = {}
|
2021-01-16 04:08:50 +01:00
|
|
|
const settings = rootState.settings
|
|
|
|
const useProxy = settings.useProxy
|
|
|
|
|
|
|
|
if (useProxy) {
|
|
|
|
const proxyProtocol = settings.proxyProtocol
|
|
|
|
const proxyHostname = settings.proxyHostname
|
|
|
|
const proxyPort = settings.proxyPort
|
|
|
|
|
|
|
|
switch (proxyProtocol) {
|
|
|
|
case 'http':
|
|
|
|
agent = new HttpProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'https':
|
|
|
|
agent = new HttpsProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks4':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 4
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks5':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.options.requestOptions = { agent }
|
|
|
|
}
|
|
|
|
|
2020-02-16 19:30:00 +01:00
|
|
|
commit('toggleIsYtSearchRunning')
|
|
|
|
|
2020-03-01 04:37:02 +01:00
|
|
|
if (!IsEqual(defaultFilters, rootState.utils.searchSettings)) {
|
|
|
|
dispatch('ytSearchGetFilters', payload).then((filter) => {
|
|
|
|
if (typeof (payload.options.nextpageRef) === 'undefined' && filter !== payload.query) {
|
|
|
|
payload.options.nextpageRef = filter
|
|
|
|
}
|
2020-02-16 19:30:00 +01:00
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
const query = filter || payload.query
|
|
|
|
|
|
|
|
ytsr(query, payload.options).then((result) => {
|
2020-09-13 02:36:02 +02:00
|
|
|
console.log(result)
|
|
|
|
console.log('done')
|
|
|
|
resolve(result)
|
|
|
|
}).catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
reject(err)
|
|
|
|
}).finally(() => {
|
2020-03-01 04:37:02 +01:00
|
|
|
commit('toggleIsYtSearchRunning')
|
|
|
|
})
|
2020-10-21 17:23:40 +02:00
|
|
|
}).catch((err) => {
|
|
|
|
console.log(err)
|
2020-12-14 20:15:29 +01:00
|
|
|
commit('toggleIsYtSearchRunning')
|
2020-10-21 17:23:40 +02:00
|
|
|
reject(err)
|
2020-03-01 04:37:02 +01:00
|
|
|
})
|
|
|
|
} else {
|
2020-09-13 02:36:02 +02:00
|
|
|
ytsr(payload.query, payload.options).then((result) => {
|
|
|
|
console.log(result)
|
|
|
|
console.log('done')
|
|
|
|
resolve(result)
|
|
|
|
}).catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
reject(err)
|
|
|
|
}).finally(() => {
|
2020-02-16 19:30:00 +01:00
|
|
|
commit('toggleIsYtSearchRunning')
|
|
|
|
})
|
2020-03-01 04:37:02 +01:00
|
|
|
}
|
2020-02-16 19:30:00 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
async ytSearchGetFilters ({ rootState }, payload) {
|
2021-01-16 04:08:50 +01:00
|
|
|
let options = null
|
|
|
|
let agent = null
|
|
|
|
const settings = rootState.settings
|
|
|
|
const useProxy = settings.useProxy
|
|
|
|
|
|
|
|
if (useProxy) {
|
|
|
|
const proxyProtocol = settings.proxyProtocol
|
|
|
|
const proxyHostname = settings.proxyHostname
|
|
|
|
const proxyPort = settings.proxyPort
|
|
|
|
|
|
|
|
switch (proxyProtocol) {
|
|
|
|
case 'http':
|
|
|
|
agent = new HttpProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'https':
|
|
|
|
agent = new HttpsProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks4':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 4
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks5':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
2021-01-17 17:09:51 +01:00
|
|
|
}
|
2021-01-16 04:08:50 +01:00
|
|
|
|
2021-01-17 17:09:51 +01:00
|
|
|
options = {
|
|
|
|
requestOptions: { agent }
|
2021-01-16 04:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let filter = await ytsr.getFilters(payload.query, options)
|
2020-12-14 20:15:29 +01:00
|
|
|
let filterUrl = null
|
|
|
|
let searchSettings = payload.searchSettings
|
|
|
|
|
|
|
|
if (typeof (searchSettings) === 'undefined') {
|
|
|
|
searchSettings = rootState.utils.searchSettings
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(searchSettings)
|
|
|
|
console.log(filter)
|
|
|
|
|
|
|
|
if (searchSettings.sortBy !== 'relevance') {
|
|
|
|
let filterValue
|
|
|
|
switch (searchSettings.sortBy) {
|
|
|
|
case 'rating':
|
|
|
|
filterValue = 'Rating'
|
|
|
|
break
|
|
|
|
case 'upload_date':
|
|
|
|
filterValue = 'Upload date'
|
|
|
|
break
|
|
|
|
case 'view_count':
|
|
|
|
filterValue = 'View count'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
filterUrl = filter.get('Sort by').get(filterValue).url
|
2021-01-16 04:08:50 +01:00
|
|
|
filter = await ytsr.getFilters(filterUrl, options)
|
2020-12-14 20:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Current ref: ${filterUrl}`)
|
|
|
|
|
|
|
|
if (searchSettings.duration !== '') {
|
|
|
|
let filterValue = null
|
|
|
|
if (searchSettings.duration === 'short') {
|
|
|
|
filterValue = 'Short (< 4 minutes)'
|
|
|
|
} else if (searchSettings.duration === 'long') {
|
|
|
|
filterValue = 'Long (> 20 minutes)'
|
|
|
|
}
|
2020-02-16 19:30:00 +01:00
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
filterUrl = filter.get('Duration').get(filterValue).url
|
2021-01-16 04:08:50 +01:00
|
|
|
filter = await ytsr.getFilters(filterUrl, options)
|
2020-12-14 20:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Current ref: ${filterUrl}`)
|
|
|
|
|
|
|
|
if (searchSettings.time !== '') {
|
|
|
|
let filterValue = null
|
|
|
|
|
|
|
|
switch (searchSettings.time) {
|
|
|
|
case 'hour':
|
|
|
|
filterValue = 'Last Hour'
|
|
|
|
break
|
|
|
|
case 'today':
|
|
|
|
filterValue = 'Today'
|
|
|
|
break
|
|
|
|
case 'week':
|
|
|
|
filterValue = 'This week'
|
|
|
|
break
|
|
|
|
case 'month':
|
|
|
|
filterValue = 'This month'
|
|
|
|
break
|
|
|
|
case 'year':
|
|
|
|
filterValue = 'This year'
|
|
|
|
break
|
2020-02-16 19:30:00 +01:00
|
|
|
}
|
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
filterUrl = filter.get('Upload date').get(filterValue).url
|
2021-01-16 04:08:50 +01:00
|
|
|
filter = await ytsr.getFilters(filterUrl, options)
|
2020-12-14 20:15:29 +01:00
|
|
|
}
|
2020-02-16 19:30:00 +01:00
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
console.log(`Current ref: ${filterUrl}`)
|
2020-02-16 19:30:00 +01:00
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
if (searchSettings.type !== 'all') {
|
|
|
|
const filterValue = searchSettings.type.charAt(0).toUpperCase() + searchSettings.type.slice(1)
|
|
|
|
filterUrl = filter.get('Type').get(filterValue).url
|
2021-01-16 04:08:50 +01:00
|
|
|
filter = await ytsr.getFilters(filterUrl, options)
|
2020-12-14 20:15:29 +01:00
|
|
|
}
|
2020-02-16 19:30:00 +01:00
|
|
|
|
2020-12-14 20:15:29 +01:00
|
|
|
console.log(`Current ref: ${filterUrl}`)
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(filterUrl)
|
2020-02-16 19:30:00 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-01-16 04:08:50 +01:00
|
|
|
ytGetPlaylistInfo ({ rootState }, playlistId) {
|
2020-02-16 19:30:00 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
console.log(playlistId)
|
|
|
|
console.log('Getting playlist info please wait...')
|
2021-01-16 04:08:50 +01:00
|
|
|
let agent = null
|
|
|
|
const settings = rootState.settings
|
|
|
|
const useProxy = settings.useProxy
|
|
|
|
|
|
|
|
if (useProxy) {
|
|
|
|
const proxyProtocol = settings.proxyProtocol
|
|
|
|
const proxyHostname = settings.proxyHostname
|
|
|
|
const proxyPort = settings.proxyPort
|
|
|
|
|
|
|
|
switch (proxyProtocol) {
|
|
|
|
case 'http':
|
|
|
|
agent = new HttpProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'https':
|
|
|
|
agent = new HttpsProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks4':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 4
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks5':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ytpl(playlistId, {
|
|
|
|
limit: 'Infinity',
|
|
|
|
requestOptions: { agent }
|
|
|
|
}).then((result) => {
|
2020-09-13 02:36:02 +02:00
|
|
|
resolve(result)
|
|
|
|
}).catch((err) => {
|
|
|
|
reject(err)
|
2020-02-16 19:30:00 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2021-01-16 04:08:50 +01:00
|
|
|
ytGetVideoInformation ({ rootState }, videoId) {
|
2020-02-16 19:30:00 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
console.log('Getting video info please wait...')
|
2021-01-16 04:08:50 +01:00
|
|
|
let agent = null
|
|
|
|
const settings = rootState.settings
|
|
|
|
const useProxy = settings.useProxy
|
|
|
|
|
|
|
|
if (useProxy) {
|
|
|
|
const proxyProtocol = settings.proxyProtocol
|
|
|
|
const proxyHostname = settings.proxyHostname
|
|
|
|
const proxyPort = settings.proxyPort
|
|
|
|
|
|
|
|
switch (proxyProtocol) {
|
|
|
|
case 'http':
|
|
|
|
agent = new HttpProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'https':
|
|
|
|
agent = new HttpsProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks4':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 4
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'socks5':
|
|
|
|
agent = new SocksProxyAgent({
|
|
|
|
host: proxyHostname,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 02:15:31 +01:00
|
|
|
ytdl.getInfo(videoId, {
|
2021-01-16 04:08:50 +01:00
|
|
|
lang: localStorage.getItem('locale'),
|
|
|
|
requestOptions: { agent }
|
2020-12-07 02:15:31 +01:00
|
|
|
}).then((result) => {
|
2020-08-27 23:40:01 +02:00
|
|
|
resolve(result)
|
|
|
|
}).catch((err) => {
|
|
|
|
reject(err)
|
2020-02-16 19:30:00 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
toggleIsYtSearchRunning (state) {
|
|
|
|
state.isYtSearchRunning = !state.isYtSearchRunning
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations
|
|
|
|
}
|