664a246d76456

664a246d769ad
1 Guest is here.
 

Topic: A script for checking youtube videos? Read 720 times  

664a246d7727eunn_atropos

664a246d772e6
Once or twice a year I go through all of my let's play posts in the runtime section by clicking the option "show posts" in my profile.
That lists about 24 post on every page and then I spent hours (!) by going through 172 pages to check for deleted youtube links.

I'm wondering if there is an easier way. It would be nice to have a script that checks the links for me and reports if a video is gone.

As a first step I would create a list of the links I already have and put them in a file (mabye even excel if it can't be avoided).
Then I would need help of someone to write this script for me, because I have no knowledge of programming whatsoever.

For example:
Bob Witherspoon-Jerkward LP's     link  | ok
theIdiotwhowascreatedforthislist  link  | video not found
MrTestman                                         link  | ok
xx!sausage                                         link  | ok

There would be separate lists for Sys/Sys2 videos that are still going on, finished, speedruns and I would add new LPs whenever I find them.

I'm aware that few people are looking into the runtime section and almost noone is using the alphabetical lists, but over the years I've grown fond of the ritual of posting LPs, and sometimes I just wish that maintaining the lists could be a bit easier.

So, if you can help me that would be awesome  :)
664a246d7744f
I can do that. I think I can even go trough the posts and parse the links.

664a246d774edunn_atropos

664a246d77551
Wohoo! :awesome:
The A-Z list are html pages. Maybe that can be helpful?
664a246d7763e
Do you want to make lists or should I try to parse trough the forum?
HTML, textfile, google doc (spreadsheet) etc. is fine.

664a246d777c9unn_atropos

664a246d77813
Nice!

So that means If I want to do the check, I can use the A-Z list instead of maintaining an additional list?
Acknowledged by: Gawain
664a246d77b22
Code: [Select]
    <script>
      const checkLinks = operation => {
        const youtubeLinks = Array.from(document.querySelectorAll('li > a[href*=youtu]'))
        for (const link of youtubeLinks) {
          const url = link.getAttribute('href')
          fetch(`https://www.youtube.com/oembed?format=json&url=${encodeURIComponent(url)}`)
            .then(async response => {
              const payload = await response.text()
              if (!response.ok) {
                if (response.status === 401) return // Video is available. Embedding not allowed.

                if (response.status === 404) {
                  if (operation === 'mark')
                    link.parentElement.style.backgroundColor = '#8B0000'
                  else if (operation === 'remove')
                    link.parentElement.remove()
                } else if (response.status === 403) {
                  if (operation === 'mark')
                    link.parentElement.style.backgroundColor = '#CC5500'
                  else if (operation === 'remove')
                    link.parentElement.remove()
                } else if (response.status === 400) {
                  console.info(`${response.status}:${response.statusText} ${url}`)
                  link.parentElement.style.backgroundColor = '#D4AF37'
                } else {
                  console.warn(`${response.status}:${response.statusText} ${url}`)
                }
              }
            })
        }
      }

      const createButtons = () => {
        const buttonContainer = document.createElement('div')
        document.body.prepend(buttonContainer)

        const markButton = document.createElement('button')
        markButton.textContent = 'Mark'
        markButton.addEventListener('click', () => checkLinks('mark'))
        const removeButton = document.createElement('button')
        removeButton.textContent = 'Remove'
        removeButton.addEventListener('click', () => checkLinks('remove'))

        buttonContainer.append(markButton, removeButton)
      }

      if (document.readyState === 'loading')
        document.addEventListener('DOMContentLoaded', createButtons)
      else
        createButtons()
    </script>

Throw that into header or body.
It will create two buttons on top of the page.
"Mark" will mark missing, private or somehow broken/nonworking links (will also print the nonworking urls into browser console).
"Remove" will remove missing and private links.

You can for example press remove and then copy the page source and replace the .html file with that (just remember to remove the buttons on top of the body that was added by the script).

If you need more features or find bugs let me know.
664a246d77c3c
I tested against Sys1_finished.html and Sys2_sgo.html
664a246d77d99
Haven't tried it, but the code looks fine.
I guess I would prepend the buttonContainer after appending the buttons to it.

664a246d77e57unn_atropos

664a246d77e9f
 :stroke: Woah! Thanks! It's working!

What's does the gold/brown/#D4AF37 response.status === 400) stand for?

For example Sys 2:
DragonAgeArchmage & Predation: fine
Fairycage Reviews: ah, links to another entry
UltraNova5000: same
gwm9797, blind: fine
664a246d77f76
It means there is something strange with the youtube url. They need to be manually checked for now...
664a246d7804a
About DragonAgeArchmage; it seems youtube automatically fixes the url by removing last 8 from the video id...
664a246d78133
I got some improvement ideas for next version:
* Remove buttons when "remove" is pressed.
* const payload = await response.text() is not needed
* Show progress (x/total) and message when all is done.
1 Guest is here.
It is absurdly, impossibly cool.
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
664a246d78220