make a php file and input the following code. Edit line 3 with your m3u file. This will export the line into its own categories.
<?php
// Define the file path of the M3U playlist
$m3u_file_path = 'path/to/playlist.m3u';
// Define the output directory path where the category-based playlists will be saved
$output_directory_path = 'output/';
// Read the contents of the M3U playlist into a variable
$m3u_content = file_get_contents($m3u_file_path);
// Split the M3U content into an array of lines
$m3u_lines = explode("\n", $m3u_content);
// Initialize an array to store the category-based playlists
$category_playlists = array();
// Loop through the array of M3U lines and create a separate M3U playlist file for each category
foreach ($m3u_lines as $line) {
if (strpos($line, '#EXTINF') === 0) {
$category = getCategoryFromLine($line);
if (!isset($category_playlists[$category])) {
$category_playlists[$category] = "#EXTM3U\n\n";
}
$category_playlists[$category] .= "{$line}\n";
} elseif (strpos($line, '#EXTM3U') === false) {
$category_playlists[$category] .= "{$line}\n";
}
}
// Loop through the array of category-based playlists and save each one to a separate file in the output directory
foreach ($category_playlists as $category => $playlist_data) {
// Define the output file path
$output_file_path = $output_directory_path . $category . '.m3u';
// Save the playlist data to the output file, overwriting any existing file
file_put_contents($output_file_path, $playlist_data, FILE_APPEND | LOCK_EX);
}
// Function to extract the category from an M3U line that starts with #EXTINF
function getCategoryFromLine($line) {
$start = strpos($line, 'group-title="') + 13;
$end = strpos($line, '"', $start);
return substr($line, $start, $end - $start);
}