6648fd7f60da2

6648fd7f613f1
1 Guest is here.
 

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

6648fd7f61eceunn_atropos

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

6648fd7f621d5unn_atropos

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

6648fd7f6257funn_atropos

6648fd7f625cd
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
6648fd7f6289f
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.
6648fd7f62992
I tested against Sys1_finished.html and Sys2_sgo.html
6648fd7f62b13
Haven't tried it, but the code looks fine.
I guess I would prepend the buttonContainer after appending the buttons to it.

6648fd7f62be9unn_atropos

6648fd7f62c31
 :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
6648fd7f62d18
It means there is something strange with the youtube url. They need to be manually checked for now...
6648fd7f62dff
About DragonAgeArchmage; it seems youtube automatically fixes the url by removing last 8 from the video id...
6648fd7f62f0b
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.
Excuses, excuses, excuses. What a week. Hard times are back.
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
6648fd7f63034