Last active
September 6, 2021 05:25
-
-
Save feeedback/915338390ea39f0f85a0e0b260a2b179 to your computer and use it in GitHub Desktop.
youtube playlist to Trello list
This file contains 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
// Open page Youtube playlist in browser | |
// Paste this JS code in console => Copy text on screen(or from console.log output) | |
// Paste to Trello card => new task in task list => press [Enter] | |
{ | |
console.clear(); | |
const formatS = (s = 0) => | |
`${Math.floor(s / 3600)}:${`${Math.floor(s / 60) % 60}`.padStart(2, 0)}:${`${s % 60}`.padStart(2, 0)}`; | |
const getPlaylistToTrelloList = () => { | |
const parentElPL = document.querySelector('ytd-playlist-video-list-renderer').parentElement; | |
const videos = [ | |
...parentElPL.querySelectorAll('ytd-playlist-video-list-renderer ytd-playlist-video-renderer'), | |
]; | |
const videosTime = [...parentElPL.querySelectorAll('span.ytd-thumbnail-overlay-time-status-renderer')]; | |
let indexHasCount = 0; | |
const videosList = videos.map((video, index) => { | |
const timeEl = videosTime[index]; | |
const [s = 0, m = 0, h = 0] = timeEl.textContent.split(':').map(Number).reverse(); | |
const duration = 3600 * h + 60 * m + s; | |
const textEl = video.querySelector('#meta a'); | |
let text = textEl.title.trim(); | |
const link = textEl.href.trim(); | |
if (!/^\s*.?\s*\d{1,2}[^\d]/.test(text) || indexHasCount > videos.length / 4) { | |
text = `${index + 1}. ${text}`; | |
indexHasCount += 1; | |
} | |
return { duration, text: `${text} ⏳ ${formatS(duration)} ${link}` }; | |
}); | |
const durationSum = videosList.reduce((sum, { duration }) => sum + duration, 0); | |
const titleList = document.querySelector('#title a').textContent.trim(); | |
console.log(`${titleList} ⏳ ${formatS(durationSum)}`); | |
return videosList.map(({ text }) => text); | |
}; | |
console.log(`${getPlaylistToTrelloList().join('\n')}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment