Advertisement
Thunder-Menu

Info_Youtube_GoogleVideo.html

Nov 1st, 2023 (edited)
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 8.90 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="fr">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Informations de flux vidéo YouTube et Détection de plateforme</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12. <h2 id="platformLabel">Enregistrement Vidéo et Audio</h2>
  13.  
  14. <input type="text" id="youtubeUrl" placeholder="Entrez l'URL de la vidéo YouTube">
  15. <button onclick="fetchHtmlContent()">Obtenir le contenu HTML</button>
  16. <button onclick="saveHtmlContentToFile()">Sauvegarder le contenu HTML</button>
  17. <button onclick="loadHtmlContentFromFile()">Charger le contenu HTML depuis un fichier</button>
  18. <h3>Contenu HTML:</h3>
  19. <textarea id="htmlOutput" rows="10" cols="50"></textarea>
  20. <br>
  21. <button onclick="extractVideoInfo()">Extraire les informations de flux vidéo</button>
  22. <button onclick="visitStreamUrl()">Visiter l'URL</button> <!-- Bouton ajouté ici -->
  23. <br>
  24. <h3>Informations de flux vidéo:</h3>
  25. <textarea id="videoInfoOutput" rows="10" cols="50"></textarea>
  26. <div>
  27.     <label id="cipherWarning" style="display: none; color: red;">Signature Cipher</label>
  28.     <select id="qualityDropdown"></select>
  29. </div>
  30. <div>
  31.     <label>Informations de flux vidéo:</label>
  32.     <select id="videoUrlDropdown"></select> <!-- ComboBox pour les URLs -->
  33.     <pre id="videoInfoOutput"></pre>
  34. </div>
  35.  
  36. <script>
  37.     let userAgent = navigator.userAgent || navigator.vendor || window.opera;
  38.  
  39.     if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
  40.        document.getElementById('platformLabel').innerText = "Enregistrement Vidéo et Audio pour iPhone/iPad/iPod";
  41.     } else if (/android/i.test(userAgent)) {
  42.         document.getElementById('platformLabel').innerText = "Enregistrement Vidéo et Audio pour Android";
  43.     } else if (/Windows/.test(userAgent) && ('ontouchstart' in window || navigator.maxTouchPoints)) {
  44.        document.getElementById('platformLabel').innerText = "Enregistrement Vidéo et Audio pour Windows (Tactile)";
  45.     } else {
  46.         document.getElementById('platformLabel').innerText = "Enregistrement Vidéo et Audio pour autres plateformes";
  47.     }
  48.  
  49.     class StreamInfo {
  50.         constructor() {
  51.             this.Url = "";
  52.             this.MimeType = "";
  53.             this.Quality = "";
  54.             this.Itag = 0;
  55.             this.ContentLength = 0;
  56.             this.Width = 0;
  57.             this.Height = 0;
  58.             this.Fps = 0;
  59.         }
  60.     }
  61.  
  62.     let downloadedHtmlContent = "";
  63.  
  64.     async function fetchHtmlContent() {
  65.         const youtubeUrl = document.getElementById("youtubeUrl").value;
  66.         downloadedHtmlContent = await downloadHtml(youtubeUrl);
  67.         document.getElementById("htmlOutput").textContent = downloadedHtmlContent;
  68.     }
  69.  
  70.     async function downloadHtml(url) {
  71.         const corsProxy = "https://cors-anywhere.herokuapp.com/";
  72.         const response = await fetch(corsProxy + url, {
  73.             headers: {
  74.                 "X-Requested-With": "XMLHttpRequest"
  75.             }
  76.         });
  77.         if (!response.ok) {
  78.             throw new Error('Erreur lors de la tentative de récupération du contenu.');
  79.         }
  80.         return await response.text();
  81.     }
  82.  
  83. function extractVideoInfo() {
  84.     const streamInfos = getVideoStreamInfos(downloadedHtmlContent);
  85.     const videoInfoOutput = document.getElementById("videoInfoOutput");
  86.     const qualityDropdown = document.getElementById("qualityDropdown");
  87.     const videoUrlDropdown = document.getElementById("videoUrlDropdown");
  88.     const cipherWarning = document.getElementById("cipherWarning");
  89.  
  90.     videoInfoOutput.textContent = '';
  91.     qualityDropdown.innerHTML = '';
  92.     videoUrlDropdown.innerHTML = '';
  93.  
  94.     let cipherDetected = false;
  95.     const addedQualities = new Set();
  96.    
  97.     if (streamInfos && streamInfos.length > 0) {
  98.        // Filtrer les formats qui ont à la fois vidéo et audio
  99.        const validStreamInfos = streamInfos.filter(stream => stream.MimeType.startsWith("video/mp4"));
  100.  
  101.         validStreamInfos.forEach(streamInfo => {
  102.             const info = `Itag: ${streamInfo.Itag}\nURL: ${streamInfo.Url}\nMimeType: ${streamInfo.MimeType}\nQuality: ${streamInfo.Quality}\nWidth: ${streamInfo.Width}\nHeight: ${streamInfo.Height}\nContentLength: ${streamInfo.ContentLength}\nFps: ${streamInfo.Fps}\n\n`;
  103.             videoInfoOutput.textContent += info;
  104.  
  105.             if (streamInfo.Signature) {
  106.                 cipherDetected = true;
  107.             }
  108.  
  109.             if (!addedQualities.has(streamInfo.Quality)) {
  110.                 const option = document.createElement("option");
  111.                 option.value = streamInfo.Url;
  112.                 option.textContent = streamInfo.Quality;
  113.                 qualityDropdown.appendChild(option);
  114.                 addedQualities.add(streamInfo.Quality);
  115.             }
  116.  
  117.             // Add each URL to the URL dropdown
  118.             const urlOption = document.createElement("option");
  119.             urlOption.value = streamInfo.Url;
  120.             urlOption.textContent = streamInfo.Url;
  121.             videoUrlDropdown.appendChild(urlOption);
  122.         });
  123.        
  124.         cipherWarning.style.display = cipherDetected ? "block" : "none";
  125.     } else {
  126.         videoInfoOutput.textContent = "Aucune information de flux vidéo trouvée ou impossible de récupérer les données.";
  127.         cipherWarning.style.display = "none";
  128.     }
  129. }
  130.  
  131.  
  132. const resolutionsPriority = [137, 136, 135, 18, 133, 160];
  133.  
  134. function getVideoStreamInfos(htmlContent) {
  135.     const regex = /ytInitialPlayerResponse\s*=\s*({.*?});/;
  136.     const match = htmlContent.match(regex);
  137.     if (!match) {
  138.         console.error('Impossible de trouver les informations de flux vidéo.');
  139.         return [];
  140.     }
  141.     const json = JSON.parse(match[1]);
  142.     const formats = json.streamingData && json.streamingData.formats;
  143.     const adaptiveFormats = json.streamingData && json.streamingData.adaptiveFormats;
  144.    
  145.     if (!formats && !adaptiveFormats) return [];
  146.  
  147.     const allFormats = [...(formats || []), ...(adaptiveFormats || [])];
  148.  
  149.     let sortedFormats = allFormats.sort((a, b) => {
  150.         return getQualityRanking(b) - getQualityRanking(a);
  151.     });
  152.  
  153.     return sortedFormats.map(format => {
  154.         const streamInfo = new StreamInfo();
  155.         streamInfo.Itag = format.itag;
  156.  
  157.         if (format.signatureCipher) {
  158.             streamInfo.Url = getVideoUrlFromCipher(format.signatureCipher);
  159.             streamInfo.Signature = extractSignatureFromCipher(format.signatureCipher);
  160.         } else {
  161.             streamInfo.Url = format.url;
  162.         }
  163.  
  164.         streamInfo.MimeType = format.mimeType;
  165.         streamInfo.Quality = format.qualityLabel || '';
  166.         streamInfo.Width = format.width;
  167.         streamInfo.Height = format.height;
  168.         streamInfo.ContentLength = parseInt(format.contentLength, 10) || 0;
  169.         streamInfo.Fps = format.fps;
  170.         return streamInfo;
  171.     });
  172. }
  173.  
  174. function getVideoUrlFromCipher(cipher) {
  175.     const urlMatch = cipher.match(/url=(https?[^&]*)/);
  176.     if (urlMatch && urlMatch[1]) {
  177.        return decodeURIComponent(urlMatch[1]);
  178.     }
  179.     return null;
  180. }
  181.  
  182. function extractSignatureFromCipher(cipher) {
  183.     const signatureMatch = cipher.match(/s=([^&]*)\&sp=sig/);
  184.     if (signatureMatch && signatureMatch[1]) {
  185.        return decodeURIComponent(signatureMatch[1]);
  186.     }
  187.     return null;
  188. }
  189.  
  190. function getQualityRanking(format) {
  191.     const index = resolutionsPriority.indexOf(format.itag);
  192.     if (index !== -1) {
  193.         return resolutionsPriority.length - index;
  194.     }
  195.     return 0;
  196. }
  197.  
  198.  
  199.  
  200.  
  201.     async function saveHtmlContentToFile() {
  202.         try {
  203.             const fileHandle = await window.showSaveFilePicker();
  204.             const writable = await fileHandle.createWritable();
  205.             await writable.write(downloadedHtmlContent);
  206.             await writable.close();
  207.             alert('Contenu HTML sauvegardé!');
  208.         } catch (err) {
  209.             console.error('Erreur lors de la sauvegarde du fichier:', err);
  210.         }
  211.     }
  212.  
  213.     async function loadHtmlContentFromFile() {
  214.         try {
  215.             const [fileHandle] = await window.showOpenFilePicker();
  216.             const file = await fileHandle.getFile();
  217.             const content = await file.text();
  218.             document.getElementById("htmlOutput").textContent = content;
  219.             downloadedHtmlContent = content;
  220.         } catch (err) {
  221.             console.error('Erreur lors de la lecture du fichier:', err);
  222.         }
  223.     }
  224.     // Fonction ajoutée pour ouvrir l'URL du flux vidéo sélectionné
  225. function visitStreamUrl() {
  226.     const videoUrlDropdown = document.getElementById("videoUrlDropdown");
  227.     const selectedUrl = videoUrlDropdown.value;
  228.     if (selectedUrl) {
  229.         window.open(selectedUrl, '_blank');
  230.     } else {
  231.         alert("Veuillez sélectionner une URL.");
  232.     }
  233. }
  234.  
  235. </script>
  236.  
  237. <footer>
  238.     <a href="https://cors-anywhere.herokuapp.com/corsdemo" target="_blank">Accédez à CORS Anywhere</a>
  239. </footer>
  240.  
  241. </body>
  242.  
  243. </html>
  244.  
  245.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement