6742532350f6a

674253235228e
1 Guest is here.
 

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

6742532352bc1unn_atropos

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

6742532352e37unn_atropos

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

67425323530f9unn_atropos

6742532353141
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
67425323533f3
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.
67425323534cc
I tested against Sys1_finished.html and Sys2_sgo.html
6742532353634
Haven't tried it, but the code looks fine.
I guess I would prepend the buttonContainer after appending the buttons to it.

6742532353712unn_atropos

6742532353764
 :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
6742532353868
It means there is something strange with the youtube url. They need to be manually checked for now...
6742532353957
About DragonAgeArchmage; it seems youtube automatically fixes the url by removing last 8 from the video id...
6742532353add
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.
¬_¬
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
6742532354835