674275064b597

674275064c30d
3 Guests are here.
 

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

674275064cb96unn_atropos

674275064cc0e
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  :)
674275064cdb8
I can do that. I think I can even go trough the posts and parse the links.

674275064ce5dunn_atropos

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

674275064d145unn_atropos

674275064d18f
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
674275064d480
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.
674275064d568
I tested against Sys1_finished.html and Sys2_sgo.html
674275064d6d1
Haven't tried it, but the code looks fine.
I guess I would prepend the buttonContainer after appending the buttons to it.

674275064d7a9unn_atropos

674275064d7f3
 :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
674275064d8d8
It means there is something strange with the youtube url. They need to be manually checked for now...
674275064d9c0
About DragonAgeArchmage; it seems youtube automatically fixes the url by removing last 8 from the video id...
674275064dac2
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.
3 Guests are here.
"eventually soon"
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
674275064e088