YouTube permet visualitzar d’un cop 10, 30, 50 llistas. si tens mes de 50 la creació de totes.htm sa de fer en fases totes1-50.htm, totes51-100.htm …fins aconseguir un totes.htm que contingui les nostres llistes per example 154 llistes. un cop es té el fitxer es fa el procés descrit.
1 salvar les llistes (pegades previament de youtube studio/contingut/llistes de reproducció) a un document en blanc de word a S:/0-llistes_you_tube/totes.htm

2 Traure la brosa del word amb l’escript : netejar_paragrafs.php i aconseguir totes_net.htm
<?php
/**
* netejar_paragrafs.php
* ----------------------
* Llegeix un fitxer HTML exportat de Word (totes.htm), neteja els paràgrafs
* i genera:
*
* - totes_net.htm → HTML net
* - linies.txt → només les línies "linia N, nom_llista, ID, data, vídeos"
*/
$input = "totes.htm";
$output = "totes_net.htm";
$output2 = "linies.txt";
$in = fopen($input, "r");
$out = fopen($output, "w");
$out2 = fopen($output2, "w");
$buffer = "";
$inside_p = false;
$anterior_es_numeric = null;
$linia = 1;
$hist = [];
/* -------------------------------
FUNCIONS D’EXTRACCIÓ
--------------------------------*/
// Extreu ID de playlist
function extreure_id_playlist($text) {
if (preg_match('/playlist\/(PL[A-Za-z0-9_-]+)/', $text, $m)) {
return $m[1];
}
return "";
}
// Extreu nom_llista (6 línies amunt)
function extreure_nom_llista($hist) {
$index = count($hist) - 6;
if ($index < 0) return "(sense nom)";
return strip_tags(trim($hist[$index]));
}
// Extreu data_creacio (2 línies amunt)
function extreure_data_creacio($hist) {
$index = count($hist) - 2;
if ($index < 0) return "(sense data)";
return strip_tags(trim($hist[$index]));
}
// Extreu nombre de vídeos (1 línia amunt)
function extreure_num_videos($hist) {
$index = count($hist) - 1;
if ($index < 0) return "(sense vídeos)";
$txt = strip_tags(trim($hist[$index]));
if (preg_match('/(\d+)/', $txt, $m)) {
return $m[1];
}
return "(sense vídeos)";
}
/* -------------------------------
PROCÉS PRINCIPAL
--------------------------------*/
while (($line = fgets($in)) !== false) {
$line = trim($line);
if ($line === "") continue;
// --- PARÀGRAF EN UNA SOLA LÍNIA ---
if (preg_match('/<p\b/i', $line) && stripos($line, '</p>') !== false) {
$clean = $line;
// Neteja Word
$clean = preg_replace('/<o:p>.*?<\/o:p>/i', '', $clean);
$clean = preg_replace('/<!--\s*
\[if.*?
\[endif\]
\s*-->/is', '', $clean);
$clean = preg_replace('/\s*mso-[^=]+="[^"]*"/i', '', $clean);
$clean = preg_replace('/\s*mso-[^\s>]+/i', '', $clean);
$clean = preg_replace('/\s+/', ' ', $clean);
// Text del paràgraf
if (preg_match('/<p[^>]*>(.*?)<\/p>/i', $clean, $m)) {
$text_actual = trim($m[1]);
} else {
$text_actual = "";
}
$actual_es_numeric = is_numeric($text_actual);
// --- INSERCIÓ DE LINIA N COMPLETA ---
if ($anterior_es_numeric === true && $actual_es_numeric === true) {
$id = extreure_id_playlist($hist[count($hist) - 6] ?? "");
$nom_llista = extreure_nom_llista($hist);
$data_creacio = extreure_data_creacio($hist);
$num_videos = extreure_num_videos($hist);
$linia_txt = "<p>linia $linia, $nom_llista, $id, $data_creacio, $num_videos</p>";
fwrite($out, $linia_txt . "\n");
$hist[] = $linia_txt;
$linia++;
}
fwrite($out, trim($clean) . "\n");
$hist[] = trim($clean);
$anterior_es_numeric = $actual_es_numeric;
continue;
}
// --- INICI PARÀGRAF MULTI-LÍNIA ---
if (preg_match('/<p\b/i', $line)) {
$inside_p = true;
$buffer = $line;
continue;
}
// --- CONTINUACIÓ PARÀGRAF MULTI-LÍNIA ---
if ($inside_p) {
$buffer .= ' ' . $line;
if (stripos($line, '</p>') !== false) {
$clean = $buffer;
// Neteja Word
$clean = preg_replace('/<o:p>.*?<\/o:p>/i', '', $clean);
$clean = preg_replace('/<!--\s*
\[if.*?
\[endif\]
\s*-->/is', '', $clean);
$clean = preg_replace('/\s*mso-[^=]+="[^"]*"/i', '', $clean);
$clean = preg_replace('/\s*mso-[^\s>]+/i', '', $clean);
$clean = preg_replace('/\s+/', ' ', $clean);
if (preg_match('/<p[^>]*>(.*?)<\/p>/i', $clean, $m)) {
$text_actual = trim($m[1]);
} else {
$text_actual = "";
}
$actual_es_numeric = is_numeric($text_actual);
// --- INSERCIÓ DE LINIA N COMPLETA ---
if ($anterior_es_numeric === true && $actual_es_numeric === true) {
$id = extreure_id_playlist($hist[count($hist) - 6] ?? "");
$nom_llista = extreure_nom_llista($hist);
$data_creacio = extreure_data_creacio($hist);
$num_videos = extreure_num_videos($hist);
$linia_txt = "<p>linia $linia, $nom_llista, $id, $data_creacio, $num_videos</p>";
fwrite($out, $linia_txt . "\n");
$hist[] = $linia_txt;
$linia++;
}
fwrite($out, trim($clean) . "\n");
$hist[] = trim($clean);
$anterior_es_numeric = $actual_es_numeric;
$inside_p = false;
$buffer = "";
}
continue;
}
}
fclose($in);
fclose($out);
/* -------------------------------
GENERAR linies.txt
--------------------------------*/
foreach ($hist as $h) {
if (strpos($h, "<p>linia ") === 0) {
fwrite($out2, strip_tags($h) . "\n");
}
}
fclose($out2);
echo "Fitxers generats:\n - $output\n - $output2\n";
?>
3 traure la brosa script 192.168.1.4 1/0-llistes/netejar_crlf.php
entrada: llistes2.htm
sortida: llista2_final_corregit.htm
sortida taula:i N de vídeos:
| num | Llista de reproducció | link | data de creació | N de vídeos |
|---|---|---|---|---|
| 1 | llit al sostre | https://studio.youtube.com/playlist/PLiEjFzGbAzg5LJoS6BVP2E5Ikrb_yH8Jn/edit | 24 de maig 2026 | 8 |
| 2 | Eines: fusta | https://studio.youtube.com/playlist/PLiEjFzGbAzg7IwdXNiWRXeijQQAvbiuWs/edit | 23 de maig 2026 | 1 |
| 3 | Exercices | https://studio.youtube.com/playlist/PLiEjFzGbAzg4W9eJ64PH-2fStoHf2e_DL/edit | 22 de maig 2026 | 1 |
| 4 | valvulas / orkli | https://studio.youtube.com/playlist/PLiEjFzGbAzg6aGE3BeBWBqTdfR7ByuAF0/edit | 21 de maig 2026 | 1 |
| 5 | Persiana | https://studio.youtube.com/playlist/PLiEjFzGbAzg5C3w9VjzDKUzqwsl-QBEpo/edit | 20 de maig 2026 | 1 |