Created
July 30, 2022 22:22
-
-
Save Markkop/d0e4e915609bf64b47c0c9df25a70c7c to your computer and use it in GitHub Desktop.
Compare webpage course videos with the downloaded files to check if you didn't miss one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fs = require('fs'); | |
| // Use this to obtain the video names and copy the resulting array | |
| // [...document.querySelectorAll('.heading h3')].map(el => el.innerText).sort((a,b) => (a.localeCompare(b))) | |
| // Paste and assing the array to this variable | |
| const webVideos = [] | |
| function compareDownloads() { | |
| try { | |
| const folderName = 'FOLDERNAME' // Change this | |
| const files = fs.readdirSync(folderName) | |
| const fileNameToRemove = detectBiggestSameSubstring(files[1], files[2]) | |
| const fileNames = files.map(file => file.replace(fileNameToRemove, '')); | |
| const courseVideos = webVideos.map(video => video.replace(/:/g, ' -')) | |
| const notFound = courseVideos.filter((webVideoName) => !fileNames.includes(webVideoName)) | |
| console.log({notFound}) | |
| } catch (err) { | |
| console.error(err) | |
| } | |
| } | |
| function detectBiggestSameSubstring(textA, textB) { | |
| const matchingStrings = [] | |
| for (i = textA.length; i >= 0; i--) { | |
| const slicedText = textA.slice(0, i) | |
| for (i = 0; i < slicedText.length; i++) { | |
| let evenMoreSlicedText = slicedText.slice(i, slicedText.length) | |
| if (textA.includes(evenMoreSlicedText) && textB.includes(evenMoreSlicedText)) { | |
| matchingStrings.push(evenMoreSlicedText) | |
| } | |
| } | |
| } | |
| matchingStrings.sort((a,b) => b.length - a.length) | |
| return matchingStrings[0] | |
| } | |
| compareDownloads() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment