Welcome to World of IPTV

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Forum Rules

Our Rules: Read to avoid getting banned!

Advertising

Introduce Yourself to the World with Us!

Resource Database

Find the newest resources around IPTV!

Account upgrade

Upgrade your account to unlock more benefits!

Tutorial Export m3u base on catigory

gzowner

Extended Member
Ext. Member
Joined
Mar 14, 2020
Messages
180
Reaction score
402
Points
74
Location
home
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);
}
 
scrypt python

Python:
import os

def getCategoryFromLine(line):
    start = line.find('group-title="') + 13
    end = line.find('"', start)
    return line[start:end]

# Define the file path of the M3U playlist
m3u_file_path = 'movies.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
with open('movies.m3u', 'r', errors='ignore') as f:
    m3u_content = f.read()


# Split the M3U content into an array of lines
m3u_lines = m3u_content.split('\n')

# Initialize a dictionary to store the category-based playlists
category_playlists = {}

# Loop through the array of M3U lines and create a separate M3U playlist file for each category
category = None
for line in m3u_lines:
    if line.startswith('#EXTINF'):
        category = getCategoryFromLine(line)
        if category not in category_playlists:
            category_playlists[category] = "#EXTM3U\n\n"
        category_playlists[category] += line + "\n"
    elif not line.startswith('#EXTM3U') and category is not None:
        category_playlists[category] += line + "\n"

# Loop through the dictionary of category-based playlists and save each one to a separate file in the output directory
for category, playlist_data in category_playlists.items():
    # Replace the '|' character with '_'
    safe_category = category.replace('|', '_')

    # Define the output file path
    output_file_path = os.path.join(output_directory_path, safe_category + '.m3u')

    # Save the playlist data to the output file, overwriting any existing file
    with open(output_file_path, 'w') as f:
        f.write(playlist_data)
 
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top