meta tag containing convenient publication date isn't always present on youtube
When the first page you load isn't a video, the meta tag, found using document.querySelector('meta[itemprop="datePublished"]'), isn't present on any pages afterward.
If you start with a video it's present on every pages!
This tag is useful because it has a nice "yyyy-mm-dd" format (like "2022-07-31").
We can find the publication date using document.querySelector("#info-strings > yt-formatted-string").innerText but it returns a localeDateString (ex: Jul 31, 2022 or 7 avr. 2023 in french)
For now, I just set a condition to use "0000-00-00" when we can't find the meta tag, because I don't want to waste too much time, I don't want to deal with a build step right now, I want to be done with the overall logic before!
But once I am done, here what I can do:
Known issues
meta tag containing convenient publication date isn't always present on youtube
When the first page you load isn't a video, the meta tag, found using
document.querySelector('meta[itemprop="datePublished"]')
, isn't present on any pages afterward. If you start with a video it's present on every pages!This tag is useful because it has a nice "yyyy-mm-dd" format (like "2022-07-31").
We can find the publication date using
document.querySelector("#info-strings > yt-formatted-string").innerText
but it returns alocaleDateString
(ex: Jul 31, 2022 or 7 avr. 2023 in french)But these strings are annoying to parse, I will need to use something like date-fns to help me:
I found the list of country code used by google using the API:
For now, I just set a condition to use "0000-00-00" when we can't find the meta tag, because I don't want to waste too much time, I don't want to deal with a build step right now, I want to be done with the overall logic before! But once I am done, here what I can do:
prerequisites:
[ ] find list of all possible locale (https://www.localeplanet.com/icu/ or https://stackoverflow.com/a/3191729 or something else) (put them in excel sheet, or program array)
[ ] compare them to the one supported by youtube
(for the one not supported by youtube → delete them? associate them to english?)
[ ] get list of locale supported by date-fns https://github.com/date-fns/date-fns/blob/main/src/locale/index.ts
[ ] associate locale from navigator.language with existing date-fns locales.
[ ] what to do when locale is missing?
[ ] set up the thing
bun init
bun add date-fns
algo:
const userLocale = navigator.language;
document.querySelector("#info-strings > yt-formatted-string").innerText
build:
bun build ./index.ts --outdir ./out --minify
Originally posted by @ComputerBread in https://github.com/yt-react-db/issue-tracker/issues/3#issuecomment-1728090549