Passer au contenu principal

Yt-dlp dans France.tv

En construction.png

{
  const maxWidth = 1000;
  const shebang = "#!/bin/sh\n";
  const createTmpFile = "tempFile=$(mktemp)\n";
  const autoClean = '\n\nwhile read line; do\nsed -i '' -e "${line}s/^/#/" script.sh\ndone < "${tempFile}"';
  class Video {
    constructor(video) {
      const getElContent = (parent, selector) => parent.querySelector(selector).textContent.trim()
      const title = getElContent(video, '.c-card-16x9__title');
      const subtitle = getElContent(video, '.c-card-16x9__subtitle');
      this.title = `${title} - ${subtitle}`;
      this.link = video.firstChild.href;
    }
    dlp() {
      const cli = `[ ! -e "${this.title}" ] && yt-dlp -w -f "b[width<${maxWidth}]/bv[width<${maxWidth}]+ba" -o "${this.title}.%(ext)s" ${this.link}  && grep -nF "${this.title}" script.sh | awk -F ':' '{print $1;}' >> "$tempFile"`
      return cli;
    }
  }
  const videos = Array.from(document.querySelectorAll(".c-wall__item")).map((video) => (new Video(video)).dlp()).sort().filter((el,i,a) => i===a.indexOf(el)).join('\n');
  const result = shebang.concat(createTmpFile, videos, autoClean);
  
  console.log(result);
}