-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alert if ytdl-core is old #779
Conversation
Nice. If someone would merge this that would be great. |
I'll test this out. |
Looks like the linter hates me, but that's because code written to be small is naturally difficult to read. miniget("https://api.github.com/repos/fent/node-ytdl-core/releases/latest", {
headers: {
"User-Agent": "a/b"
}
}).text().then(response => {
if ("v4.0.5" !== JSON.parse(response).tag_name) {
console.log("\x1B[31mWARNING:\x1B[0m ytdl-core is out of date! Update it using 'npm i ytdl-core'.");
}
}); |
Yea I have Eslint too. I will make some changes so my linter doesn't give me an error or something. |
Just finished changes that will probably fit with the linter. |
These are the new changes I made. However, I get an error. |
...hopefully. why is readability so important in a line that serves no more than utility?
I'd really like to see all the checks pass for once. This code is absolutely readable, I dare you to say otherwise.
After being unable to read the eslintrc for 2 minutes, I realised that lint will always fail since "no-console" is set. take a look at the first commit for the original code, and the second one for more readable code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi! this is a good idea, i've left some comments.
additionally
- could use some sort of rate limiting. maybe a local file that stores the last time the version was checked, and only check once a day at most. but i'd feel better about an in memory variable due to the point below
- could be moved into the
getInfo
functions, in case an app runs for a long time, they'd be able to check for a new version whenever they callgetInfo()
, rate limited of course. - should have an option to disable this. i've seen a few occasions of people using an older version for "reasons". i woudn't recommend it, but you can't stop someone from using the program how they like. maybe
checkUpdates/Release
orskip(Update/Release)Check
?
lib/index.js
Outdated
@@ -8,6 +8,14 @@ const miniget = require('miniget'); | |||
const m3u8stream = require('m3u8stream'); | |||
const parseTime = require('m3u8stream/dist/parse-time'); | |||
|
|||
const current = 'v4.0.5'; | |||
const message = '\x1B[31mWARNING:\x1B[0m ytdl-core is out of date! Update it using "npm i ytdl-core".'; | |||
miniget('https://api.github.com/repos/fent/node-ytdl-core/releases/latest', { headers: { 'User-Agent': 'a/b' } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the User-Agent
header needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while I was testing this, I got 403s from the service if it wasn't there. weird, but any valid user-agent fixed it.
Using node-fetch seems to solve that entirely, but i didnt want to add another dependency.
As suggested by fent Co-authored-by: fent <[email protected]>
or maybe and environment variable to more easily disable for tests |
This pull request introduces 1 alert when merging 801a47a into fcfbc8e - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The things you have requested should now be done in patch-1. Let me know if there's more you'd like to see or something I've missed. Feel free to change anything obvious.
env var UPDATE if not set: check twice daily settings: 'always', 'never'
Specifically: change env var to YTDL_NO_UPDATE which takes true or false Drop code outside of functions (that's what I think you meant by that request. will it still run during long-uptime?) Clearer message, calc ms number. gonna drop the env definition into nock, hold on
I'm migrating to a new computer so I'm doing this all from GH web, it's a nightmare
I fixed this already, huh whuh? Useful commit comment goes here
Would someone mind fixing the code formatting according to eslint? |
Ok, here's some changes to the current one that I made so it fits with my linter. Don't know how Github will handle it though. |
If not, please fix it for me.
Fixed the indents for eslint (hopefully, it seems to dislike me) Implemented request of not checking until the first 12 hrs are over Made it a function, and called it inside the getInfo cache thing directly above it. Also exported it so it could be used programatically (seems like a good idea?) Please lmk if there's anything else you'd like to see.
subtitle: my brain is big and smart coming to theaters near y'all
lib/info.js
Outdated
let lastUpdateCheck = Date.now(); | ||
const checkForUpdates = () => { | ||
if (!process.env.YTDL_NO_UPDATE && Date.now() - lastUpdateCheck >= 1000 * 60 * 60 * 12) { | ||
miniget('https://api.github.com/repos/fent/node-ytdl-core/releases/latest', { headers: { 'User-Agent': 'a/b' } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was looking at github's docs for their api
https://developer.github.com/v3/#user-agent-required
let's put "ytdl-core" here for the User-Agent. they're hosting the repo after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fails the linter bc the line's too long. what do you suggest i do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add line breaks between the options
..., {
headers: { 'User-Agent': 'ytdl-core' },
})
what is codecov, and is the error something i can resolve? |
it's for code coverage, as in is the how you introduced tested. if you're up for it, you can add tests. otherwise, i can do it after the merge. and there are some eslint warnings again |
Lint's throwing |
you can run |
going to merge this as is, then correct the lint errors and add tests. thanks @redbrain! looking forward to the next update |
shouldn't it be part of https://github.com/fent/node-ytdl and not the core? People use core as a library in their projects |
The goal is to alert library users. (it will alert node-ytdl users as well since it relies on the library) |
gotcha 😞 I'd use and there's https://github.blog/2020-06-01-keep-all-your-packages-up-to-date-with-dependabot/ and other bots |
See the first message in this discussion for why this was implemented:
|
@@ -426,6 +426,21 @@ const getM3U8 = async(url, options) => { | |||
return formats; | |||
}; | |||
|
|||
// Check for updates. | |||
const { version } = require('../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks when bundling with webpack, not sure why. It imports the package.json from my project root, instead of ytdl-core's package.json. Workaround for me was to add a "version" field to my package.json, so it doesn't error out with
TypeError: pkg.version is undefined
Might very well be me configuring webpack incorrectly, but thought I'd mention it here.
Repo to reproduce the issue: https://github.com/stoically/humanetube/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird. i'd ask webpack about it. otherwise, not sure what's causing webpack to import the wrong package.json
node's require
works a bit different for relative paths, it looks for files relatively to the file it is required from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bundled it with Browserify and it worked fine; I don't know enough about Webpack to help you further.
From my experience in the YTDL support server, upgrading the package to latest seems to be something many users forget to do, and they encounter errors because of it.
If merged, this PR would add an alert in the console if ytdl-core is outdated, along with instructions to update.
This requires no extra dependencies and has been made as minimal as possible so as not to add overhead.
To function, it relies on the GitHub API.
To maintain this feature, all that is required is to update the tag ('v4.0.5') in the if statement with each new release.
This was written in 5 minutes, so please make edits if desired.
By the way, thank you for keeping this library up-to-date; it's quite a gift.