• Welcome to RadioDJ - Free Radio Automation Software Forum. Please log in or sign up.

.M3U Splitter?

Started by PROducer, December 06, 2017, 07:39:41 PM

PROducer

I'm toying with the idea of using MusicGen to schedule my music, but it seems to only output a single .m3u playlist per day.  RadioDJ really doesn't like loading playlists that large, even if the files are already in the database, so I'm wondering if anybody on here knows of any software that will split a .m3u playlist into multiple files?

Thanks
PROducer. 

Jhonny

#1
Yep.

Check if it is what you looking for.

M3Util.zip

On a small test working fine.
Currently on
RDJ V 2.0.4.8
MariaDB V 10.6.21
WIN 11 PRO

mitomito


Hello, is there a pdf help file? My Windows 7 Pro does not allow me to open the downloaded file.  >:( >:( >:( >:(
Thank you all.

Jhonny

I don't have a pdf help file, sorry.
Currently on
RDJ V 2.0.4.8
MariaDB V 10.6.21
WIN 11 PRO

mitomito

 Thanks Jhonny,   could someone please explain how this software works?  :bash: :bash: :bash: :bash:

marcbeinder

I've got a php script that does this. I'm not at my computer right now (on my phone) but I'll attach it when I'm back there. You'll need server software to use FYI. I use XAMPP.
RiseRadio.org // Podtrics.com

marcbeinder

Quote from: marcbeinder on December 10, 2017, 06:35:05 PM
I've got a php script that does this. I'm not at my computer right now (on my phone) but I'll attach it when I'm back there. You'll need server software to use FYI. I use XAMPP.


<?php
error_reporting
(0);

$playlistname file_get_contents("playlist.txt");
$month file_get_contents("month.txt");
$date file_get_contents("date.txt");


$outputlocation="B:";
$emptydata="";

file_put_contents("$outputlocation\\$month$date-00.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-01.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-02.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-03.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-04.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-05.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-06.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-07.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-08.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-09.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-10.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-11.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-12.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-13.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-14.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-15.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-16.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-17.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-18.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-19.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-20.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-21.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-22.58.15.m3u""$emptydata");
file_put_contents("$outputlocation\\$month$date-23.58.15.m3u""$emptydata");

$file="Export\\$playlistname";

//Use an array, it's more concise and readable
$date =[
    
'month'      => "$month",
    
'day'        => "$date",
    
'hour'       => 0,
    
'minute'     => 58//added for extendability
    
'second'     => 15 //added for extendability
];

$outputlocation="B:";
/*** Create Playlist Files Code Here and Working ***/

//open file. We can't proceed without the file, might as well stop here if we can't open it.
if(false === ($handle fopen("$file.m3u""r"))) die("Failed to open file.");

//while each line in the file
while (($line fgets($handle)) !== false) {  
    if(
trim(strtoupper($line)) =="END OF HOUR"){//If $line = End Of Hour

       //trim removes whitespace from front and back, strtoupper should be self explanitory

       
if($hour 24 ){
            
//if less the 12pm (and $line = 'END-OF-HOUR' ) 
            //increment hour and left pad.
             //you may need to use < 23 your logic forgot about it.

            
++$date['hour'];
        }else{
            
//else if 12pm (and $line = 'END-OF-HOUR' ) 
            
echo "<script>alert('MusicMaster File Processing Complete')</script>";
        }
        continue; 
        
/*  
           goes to next line ( iteration of the loop )
           none of the code below this runs.
           logically this is essentially what you had ^
           so there is no need to continue
        */
    
}

    
// 0 pad left any parts that are len of 1 lenght  
    
$fixed array_map(function($i){
        return (
strlen($i) == 1) ? "0$i":$i;
    }, 
$date);

    
/*
      create the filename just before we use it
      not that it matter in PHP, but the original array stays as INT's
      the month is strlen() = 3, so it's unchanged by the above.
     */
    
$outputfile $fixed['month'].$fixed['day'].'-'.$fixed['hour'].'.'.$fixed['minute'].'.'.$fixed['second'];

    
//this is all you..
    
$ofile=file_get_contents("$outputlocation\\$outputfile.m3u");
    
$nfile="$ofile
$line";
    
file_put_contents("$outputlocation\\$outputfile.m3u""$nfile");

$linenumber $linenumber 1;
echo 
"$linenumber -- $line";
echo 
"</br>";

 } 
//end while
 

echo "</br>";
echo 
"END OF MUSICMASTER FILE";
echo 
"</br>";
echo 
"</br>";

?>



Here is the script. Customize it however you want. Just keep in mind that you will need an END OF HOUR marker.
RiseRadio.org // Podtrics.com

PROducer

Been almost a week since I asked this question, but I've been busy trying a number of different methods.  Thanks Jhonny for your solution... it works, but I couldn't figure out how to split files hourly instead of the default 80 minutes.  It was just too weird of a split for my needs.

Marc, thanks also for sharing your php script.  I'm using MusicGen Lite to schedule, which has it's own foibles, especially when outputting an .m3u file.  Only certain things wind up in the .m3u export which extremely complicates how to build the categories, etc.  I'm sure someone may find a use on their own system.

My solution: I wound up searching for a "text file splitter" which there are a lot out there. (I'm thinking it must be a project in some computing courses... there's really that many simple text file splitters) but most split at xx lines.  What I needed was something to split at an hour marker. I found a program called TextWedge Text File Splitter.  My only issue with it is it doesn't "remember" how you want to split your files, so you need to set it up each time.  It's a simple process, but would be nice if you didn't need to.

I just got everything setup and working this morning in RadioDJ and it's sounding great!  The main reason I'm doing this is because my weekends are double-play, and I was noticing I wasn't getting great artist separation using an SQL Query to create playlists.  The setup for artist separation works great if you're using rotations, but if you switch to SQL queries for the weekend like I do, suddenly you'll get stuff close together that you don't want.

TextWedge exports sequentially numbered files, starting with 01, so that required me to create a new event for every hour of the day (by day) and it loads the playlist for every "hour +1" because there is no 00 file.  I load the next hour to the bottom of the queue at the :45 minute mark, so if an hour is a little short, it doesn't run out of music before the next hour load.  The only time I don't is at midnight, when I load the hour at 2 seconds past midnight.  I also clear the queue before I do this to get everything back into sync.

So far, I'm very happy with what I'm hearing.  My double-plays are now separated better, and I'm getting pairs of Bands and their solo artists together instead of two Band feat. Artist!

;D  :)  :P  :cool:  :hihi:

Now, to figure out how to make it simpler to voice track with the scheduling software!