News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • How to easily validate YouTube links?

    Posted on alpha128 Comment on the AskWoody Lounge

    Home Forums AskWoody support Questions: Browsers and desktop software How to easily validate YouTube links?

    Topic Resolution: Resolved
    Viewing 4 reply threads
    • Author
      Posts
      • #2264917 Reply
        alpha128
        AskWoody Plus

        I’ve created some .html pages for my personal web site that have links to YouTube, lots of links to YouTube.

        Since the links in question are to songs, they sometimes go bad. I try to use official record label sources wherever possible, but even so, link rot creeps in.

        Normal “link validator” applications, e.g., W3C Link Checker are not useful in this case. That is because YouTube doesn’t actually take the link down when they strike a video. The link will instead load a page that says, e.g., “This video is no longer available because…”

        I also have all the links saved in my browser bookmarks. So the only way I know to ensure that a particular link loads a real, playable, video is to mute my speakers and then launch it. I do this in groups of five, ten, sometimes twenty videos at a time.

        Needless to say, this is time consuming and wastes a lot of YouTube’s bandwidth, but I know of no better way to truly test the validity of YouTube links.

        Does anyone know of a better way? Please let me know. Thanks.

      • #2264956 Reply
        Paul T
        AskWoody MVP

        If the link is valid the only way to check it’s to a video is to open the link.
        To prevent pulling down the video you need to work out the point in an invalid link where the “no longer avail” message appears and stop the download just after that point.

        You can only do this programmatically, so there may not be an easy solution.

        cheers, Paul

        1 user thanked author for this post.
        • #2265060 Reply
          alpha128
          AskWoody Plus

          That’s what I thought, but thanks for the confirmation.

      • #2265247 Reply
        Kirsty
        Da Boss

        There are script methods that work to check your web links, depending on your method of checking.
        CHECK YOUTUBE VIDEO IS STILL VALID Home / PHP / Check youtube video is still valid

        1 user thanked author for this post.
        • #2265260 Reply
          anonymous
          Guest

          NOTE: the above link in #2265247, is not secure as it is http and not https and even when changed to https, is flagged up as a security issue in firefox.

          1 user thanked author for this post.
          • #2265265 Reply
            Paul T
            AskWoody MVP

            flagged up as a security issue in firefox

            Even though it is a valid site – Firefox pretending to be making you more secure.

            cheers, Paul

      • #2265256 Reply
        Paul T
        AskWoody MVP

        The method in Kirsty’s link is no longer valid, but this bit of PowerShell will do the trick.
        Can you post a link that is no longer available so we can test further?

        1. Copy the commands into an editor.
        2. Replace “yt_index” with the index of the link, e.g. R-t8qPldklc
        3. Copy the 4 lines.
        4. Open a PowerShell window.
        5. Paste (Ctrl V) and press Enter if required.

        Let us know how it goes and we can enhance it to do all your links in one go.

        cheers, Paul

        PowerShell Commands
        $ytdata = "http://img.youtube.com/vi/yt_index/mqdefault.jpg"
        try {$response = Invoke-RestMethod $ytdata}
        catch { echo "Video does not exist" }
        $response.Length  # greater than 9252 is OK

        • This reply was modified 6 months, 1 week ago by Paul T.
        • This reply was modified 6 months, 1 week ago by Paul T.
        • This reply was modified 6 months, 1 week ago by Paul T.
        1 user thanked author for this post.
        • #2265309 Reply
          alpha128
          AskWoody Plus

          Paul,

          I tested your Powershell commands with the following dead YouTube link, and it seemed to work:

          https://www.youtube.com/watch?v=X0tCBTzZJVA

          I’m very experienced with batch files, but not with Powershell.

          I think, in order for this solution to be practical, there would have be a .cmd file that reads a text file containing the URLs for the hundreds of links that need to be tested.  And there would need to be some way to save off only the “Video does not exist” results.

          Is something like that doable without a mammoth effort on your part?  Please let me know.  Thanks.

          • #2265415 Reply
            Paul T
            AskWoody MVP

            Thanks for testing and confirming the results.
            Now to package it for easy use.

            Can you post a sample HTML page / link to said page? We can work from it with PowerShell.

            cheers, Paul

        • #2265353 Reply
          Kirsty
          Da Boss

          The method in Kirsty’s link is no longer valid

          The method should be for a script within the website, instead of a Windows method like PowerShell.

          Glad the Powershell method was giving the required response 🙂

          • #2265410 Reply
            Paul T
            AskWoody MVP

            The issue is the URL is no longer available and you now need to use the YouTube API, which requires an individual key from Google.
            The method I borrowed downloads the thumbnail – fails if the video has been removed.

            cheers, Paul

            • This reply was modified 6 months, 1 week ago by Paul T.
            • #2265539 Reply
              alpha128
              AskWoody Plus

              Paul,

              I successfully implemented your idea of downloading the thumbnail into a robust solution to my problem.

              Using Find and Replace (FNR) tool, I created VID2IMG.BAT:

              @ECHO OFF
              IF “%1″==”” GOTO END
              IF “%1″==”/?” GOTO HELP
              :: Save off YouTube links to a separate file
              FIND “<DT>” %1 > img%1
              :: Change video links to image links, e.g., http://img.youtube.com/vi/X0tCBTzZJVA/mqdefault.jpg
              fnr.exe –cl –dir “%USERPROFILE%\Documents\DATA\WEB\FreeHost\music” –fileMask “img%1” –useEscapeChars –find “\”” –replace “char34” –silent
              fnr.exe –cl –dir “%USERPROFILE%\Documents\DATA\WEB\FreeHost\music” –fileMask “img%1” –find “<A HREF=char34https://www.youtube.com/watch?v=” –replace “<A HREF=char34http://img.youtube.com/vi/” –silent
              fnr.exe –cl –dir “%USERPROFILE%\Documents\DATA\WEB\FreeHost\music” –fileMask “img%1” –find “char34>” –replace “/mqdefault.jpgchar34>” –silent
              fnr.exe –cl –dir “%USERPROFILE%\Documents\DATA\WEB\FreeHost\music” –fileMask “img%1” –useEscapeChars –find “char34” –replace “\”” –silent
              GOTO END
              :HELP
              ECHO Creates a new file with image links instead of video links that can be tested with a standard link checker
              ECHO.
              ECHO VID2IMG [filename]
              ECHO.
              :END

              I created a img version of one web page. I then ran that through W3C Link Checker.

              I knew from my earlier manual check that my test file would have 3 invalid links out of 127 total links. W3C Link Checker found 2 of the 3 bad links.

              The third, https://www.youtube.com/watch?v=5I0dI0PjraE, still had the thumbnails in place – even though YouTube states “This video is not available”.

              So although the results weren’t perfect (YouTube’s fault, not yours), this is a MUCH better method than opening 127 YouTube links manually to see what fails to load.

              Thanks for your help (and yours too Kirsty)!

              1 user thanked author for this post.
      • #2265910 Reply
        Paul T
        AskWoody MVP

        That thumbnail downloaded is 9312 bytes, so a test for minimum length may fix that issue.

        You can use PowerShell commands in a batch file as long as they are not too complex, or learn to do the whole lot in PS.

        e.g. this runs the command and sets the error level to the jpg length, 0 = fail.

        powershell -command "$ytdata = 'http://img.youtube.com/vi/X0tCBTzZJVA/mqdefault.jpg'; try {$response = Invoke-RestMethod $ytdata} catch { echo 'Video does not exist' }; exit $response.Length"

        cheers, Paul

    Viewing 4 reply threads

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: How to easily validate YouTube links?

    You can use BBCodes to format your content.
    Your account can't use Advanced BBCodes, they will be stripped before saving.