commit
7bb0ec6025
4 changed files with 157 additions and 0 deletions
@ -0,0 +1,81 @@
|
||||
const |
||||
axios = require('axios'), |
||||
userAgents = require('user-agents'); |
||||
|
||||
module.exports = ({ domain = 'invidious.snopyta.org' } = {}) => { |
||||
const |
||||
rootUrl = `https://${domain}`, |
||||
_axios = axios.create({ baseURL: `${rootUrl}/api/v1` }); |
||||
_axios.defaults.headers.common['User-Agent'] = userAgents.random().toString(); |
||||
return { |
||||
instance: { getInfo: async () => (await _axios('stats')).data }, |
||||
search: async ({ |
||||
query, |
||||
page, |
||||
sortBy, |
||||
date, |
||||
duration, |
||||
type, |
||||
features = [], |
||||
region |
||||
}) => (await _axios('search', { |
||||
params: { |
||||
'q': query, |
||||
page, |
||||
'sort_by': sortBy, |
||||
date, |
||||
duration, |
||||
type, |
||||
features: features.join(','), |
||||
region |
||||
} |
||||
})).data, |
||||
channel: ({ channelId }) => ({ |
||||
getInfo: async () => (await _axios(`channels/${channelId}`)).data, |
||||
getVideos: async ({ |
||||
page, |
||||
sortBy |
||||
} = {}) => (await _axios(`channels/${channelId}/videos`, { |
||||
params: { |
||||
page, |
||||
'sort_by': sortBy |
||||
} |
||||
})).data, |
||||
getPlaylists: async () => (await _axios(`channels/playlists/${channelId}`)).data, |
||||
getComments: async () => (await _axios(`channels/comments/${channelId}`)).data, |
||||
search: async ({ |
||||
query, |
||||
page |
||||
}) => (await _axios(`channels/search/${channelId}`, { |
||||
params: { |
||||
'q': query, |
||||
page |
||||
} |
||||
})).data |
||||
}), |
||||
video: ({ videoId }) => ({ |
||||
getInfo: async () => (await _axios(`videos/${videoId}`)).data, |
||||
getComments: async ({ |
||||
sortBy, |
||||
continuation |
||||
} = {}) => (await _axios(`comments/${videoId}`, { |
||||
params: { |
||||
'sort_by': sortBy, |
||||
continuation |
||||
} |
||||
})).data, |
||||
getCaptions: async () => (await _axios(`captions/${videoId}`)).data['captions'].map(caption => ({ |
||||
languageCode: caption['languageCode'], |
||||
label: caption['label'] |
||||
})), |
||||
getCaption: async ({ captionLabel }) => (await _axios(`captions/${videoId}`, { params: { label: captionLabel } })).data |
||||
}), |
||||
getPlaylist: async ({ |
||||
playlistId, |
||||
page |
||||
}) => (await _axios(`playlists/${playlistId}`, { params: { page } })).data, |
||||
getMix: async ({ mixId }) => (await _axios(`mixes/${mixId}`)).data, |
||||
getTrending: async () => (await _axios('trending')).data, |
||||
getPopular: async () => (await _axios('popular')).data |
||||
}; |
||||
}; |
@ -0,0 +1,15 @@
|
||||
{ |
||||
"name": "invidious-api-wrapper", |
||||
"version": "0.1.0", |
||||
"main": "index.js", |
||||
"author": "KaKi87 <KaKi87@pm.me>", |
||||
"license": "MIT", |
||||
"dependencies": { |
||||
"axios": "^0.22.0", |
||||
"user-agents": "^1.0.791" |
||||
}, |
||||
"keywords": [ |
||||
"invidious", |
||||
"youtube" |
||||
] |
||||
} |
@ -0,0 +1,59 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
||||
# yarn lockfile v1 |
||||
|
||||
|
||||
axios@^0.22.0: |
||||
version "0.22.0" |
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.22.0.tgz#bf702c41fb50fbca4539589d839a077117b79b25" |
||||
integrity sha512-Z0U3uhqQeg1oNcihswf4ZD57O3NrR1+ZXhxaROaWpDmsDTx7T2HNBV2ulBtie2hwJptu8UvgnJoK+BIqdzh/1w== |
||||
dependencies: |
||||
follow-redirects "^1.14.4" |
||||
|
||||
detect-indent@~6.0.0: |
||||
version "6.0.0" |
||||
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.0.0.tgz#0abd0f549f69fc6659a254fe96786186b6f528fd" |
||||
integrity sha512-oSyFlqaTHCItVRGK5RmrmjB+CmaMOW7IaNA/kdxqhoa6d17j/5ce9O9eWXmV/KEdRwqpQA+Vqe8a8Bsybu4YnA== |
||||
|
||||
docopt@~0.6.2: |
||||
version "0.6.2" |
||||
resolved "https://registry.yarnpkg.com/docopt/-/docopt-0.6.2.tgz#b28e9e2220da5ec49f7ea5bb24a47787405eeb11" |
||||
integrity sha1-so6eIiDaXsSffqW7JKR3h0Be6xE= |
||||
|
||||
dot-json@^1.2.2: |
||||
version "1.2.2" |
||||
resolved "https://registry.yarnpkg.com/dot-json/-/dot-json-1.2.2.tgz#7d35abece4aa22aa75a761388953f98495401bcc" |
||||
integrity sha512-AKL+GsO4wSEU4LU+fAk/PqN4nQ6PB1vT3HpMiZous9xCzK5S0kh4DzfUY0EfU67jsIXLlu0ty71659N9Nmg+Tw== |
||||
dependencies: |
||||
detect-indent "~6.0.0" |
||||
docopt "~0.6.2" |
||||
underscore-keypath "~0.0.22" |
||||
|
||||
follow-redirects@^1.14.4: |
||||
version "1.14.4" |
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379" |
||||
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g== |
||||
|
||||
lodash.clonedeep@^4.5.0: |
||||
version "4.5.0" |
||||
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" |
||||
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= |
||||
|
||||
underscore-keypath@~0.0.22: |
||||
version "0.0.22" |
||||
resolved "https://registry.yarnpkg.com/underscore-keypath/-/underscore-keypath-0.0.22.tgz#48a528392bb6efc424be1caa56da4b5faccf264d" |
||||
integrity sha1-SKUoOSu278QkvhyqVtpLX6zPJk0= |
||||
dependencies: |
||||
underscore "*" |
||||
|
||||
underscore@*: |
||||
version "1.13.1" |
||||
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.1.tgz#0c1c6bd2df54b6b69f2314066d65b6cde6fcf9d1" |
||||
integrity sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g== |
||||
|
||||
user-agents@^1.0.791: |
||||
version "1.0.791" |
||||
resolved "https://registry.yarnpkg.com/user-agents/-/user-agents-1.0.791.tgz#10ecbe32440ed341ecd62cb4d854bd9d3a01b67d" |
||||
integrity sha512-p/e0jbVFo+ugdRxYodbrbmTIxz5cgSYhdQEVCQYMks6iSY54zSL9WSOgJ6m8RwyGR3qR4ie2D/nYW9+9V7KMSg== |
||||
dependencies: |
||||
dot-json "^1.2.2" |
||||
lodash.clonedeep "^4.5.0" |
Loading…
Reference in new issue