M3u Playlists: Replacing Paths & other data inside an M3u file
Hello & thanks for looking,
This is my first experience with Notepad++ so please bear with me. I have been running tests unsuccessfully to make aprpropriate changes to no avail.
I have over 200+ playlists which I have to change the path of the music files included in each playlist. Also, there is other data (of varying length) which I have to remove as well. I don’t understand the syntax in the m3u file. It has extra info such as “#EXTM3U”, “#EXTINF” with variable length data following it and, lastly the incorrect path “?:\mp3library” to the music file I am unable to change.
Please refer to several lines in the Playlist file “_Flo R&RHFmissing.m3u” file below. As a simple test using the dialog box I tried to:
Find what: ?:\mp3library
Search Mode: Normal
Replace with: [(no text) & also with text]
Filters: * [no filters]*
Directory: I:\Playlists(m3u) Exports\Didn’t convert
I get the response: Replace: no occurrence was found.
or, in another window below it says: Search “?:\mp3library” (0 hits in 0 files)
This failed for me. What is wrong?
When using the procedure above, but using #EXTM3U text string to change, it failed as well.
How would I go about deleting the variable length line that is proceded by #EXTINF
Lastly, once problem’s 1-3 or fixed, is it possible to include all the fixes in one Notepad++ in one fell swoop?
Thanks for your assistance in this matter. It is greatly appreciated.
excerpt from Playlist file "_Flo R&RHFmissing.m3u"
#EXTINF:266,Aerosmith - Dream On
?:\mp3library\Dream On - Aerosmith.mp3
#EXTINF:384,Afrika Bambaataa - Planet Rock
?:\mp3library\Planet Rock - Afrika Bambaataa.mp3
#EXTINF:1373,Allman Brothers Band - Whipping Post
?:\mp3library\Whipping Post - The Allman Brothers Band (191kbps).mp3
Terry R last edited by Terry R
@Jim K First off I’d say nothing appears to be wrong. I created a test.msu file with 3 lots of your sample text. I then used the same find what string you proposed and the same “everything else”. I got 9 changes of the ?:\mp3library in my test file.
So my first suggestion is to load 1 M3U file into Notepad++, attempt the “Find” function using the “?:\mp3library” string you provided and just use the Find Next button, or even the Count button to see if it can even spot the occurrences within the file. If you don’t get any, then close the find window, highlight that string within the file and re-open the Find or Replace function. This time you will see the string has been pre-loaded into the find what field. This time it should find occurrences within the file. At this point you should be able to point to the folder containing the M3U files and try the replace option.
As you are only using the find and replace in “normal” mode you don’t need to be concerned that some of the characters in your string are what we call metacharacters. These characters work differently in special conditions in Notepad++ (regular expression mode) , they mean something different from the actual character.
The other replacements should also be straight forward. Again you could highlight the text to replace, then open the replace window and it will pre-load the string in the find what field. If you need to entirely delete a line, when you highlight the text, start as normal, but extend the highlight to the left hand margin of the next line. This is so the highlight recognizes the CRLF (carriage return line feed) at the end of a line, and will then remove that line rather than just delete the text on that line leaving a blank line.
As for your last question, very likely they could all be combined together, but it does become more complicated and in your situation it may not be worth the effort, much easier to just have 2 or more runs through string changes. Another option, once you have the find and replacement strings working as expected, you could create a macro. Then you just run the macro and it will do all the changes very quickly. There is a downside however, once the macro is created it cannot be easily changed to suit new requirements.
Try my ideas above, come back to the forum with updated info, and any other issues and we will attempt to help.
Terry…thanks for the guidance. I’ll try it out. Yes, I figured my last problem solving is over the top, but I would be remiss if I didn’t ask ;)
Just thought I would ask: If I still have problems is it possible for me to upload a couple .m3u’s to you & several “Print Screen’s” to show you what I am doing. Possibly, you can check my Print Screens to see if I am on track. If not, you can send me a correct Print Screen showing where I went wrong. Is this possible? I can’t see any way to accomplish type of task. I hope this is not necesasry.
Thanks again Terrry for the quick response.
@Jim-K , by all means come back to the forum if you are still having difficulties. I would suggest reading a post in the FAQ, namely “Request for Help…” as it will help in the posting of images and the like. Also seriously consider giving us the “Debug Info” as stated earlier in that post. Given the issue you are having it may be that you have a corrupted installation.
The steps I outlined are to get you started, essentially breaking down your problem into steps, each building on the previous one. So highlighting the string to find, then attempting to find it is a sure way to determine if the find works or doesn’t. If not then we may well be looking at a installation issue.
Give my ideas a go, then come back to us.
I’ve have some successes per your instruction ;)
YES, I was able to find a character string.
YES, able to count.
YES, I was able to find & replace a character string.
YES, I could delete the text #EXTM3U, however,
NO, a blank line remained where #EXTM3U was. I tried to use your tip “extend the highlight to the left hand margin of the next line” to remove the CRLF. Note: when I think I selected the left hand margin I did not see a highlight as was on the text #EXTM3U. Any thoughts?
Baby steps first ;)
I’ll check out the FAQ’s & “Request for Help…” per your comment.
Great that you’ve managed to get so much achieved. There is a function under Edit, Line Operations that can remove blank lines. I would be careful using it if there are blank lines already in the file. Only you will be able to determine if blank lines existed before the editing started.
In my test I moved the cursor to the start of the next line, no highlight occurs past the text in the line above, but the cursor was in the first position on the 2nd line. Then when I used that to remove the string the line also disappeared. It’s possible this may be due to a configuration setting I had. In my case I may have had “show all characters”, which is under View menu option, Show Symbols, show all characters.
Alternative is to use the Replace function. But you’d need to do it under search mode
regular expression. This means some characters have special significance. So to remove the #EXTM3U line completely (including a line break) we would use:
empty field here<— this field should have nothing in it.
Also make sure wrap around is ticked. Remember use search mode
regular expression. The "\R’ refers to the CRLF (carriage return line feed) and the “^” means start of a line, this would prevent any strings occuring in the middle of a line being removed.
So when you hit "Replace All button, it will remove the line with that string in it.
Once you have ironed out the issues on the single file you will be ready to work on the whole folder of files.
YES, I’m still here working on your suggestions & started looking at "How to use regular expressions in Notepad++ (tutorial)i; a lot to digest.
YES, <View> I was able to use the view mode, shown was CR LF
YES, <Find> #EXTM3U <Replace> did delete line. FYI, the View setting you gave me worked. I then undid the View settings (for a test) and Find - Replace worked. For some reason, this all did not work last night. I may attribute this to operator error, but can’t see how ;(
NO, Replace function did not work to delete a line. I made the changes you mentioned. I see a lot of power in the Replace Function, especially removing the lines with this text “#EXTINF”. The replace function would allow me to remove the lines with #EXTINF regardless of the length of the text string. Awesome!
Here’s a weird observation I’ve made regarding the text string #EXTINF. When I select the EXTINF portion of the text/line all occurrences with EXTINF turn green, however, when I include “#’ " symbol, in the string I am selecting, all the green goes away.
Understandably, if I don’t select the “#”” the string, "EXTINF " and run Replace, EXTINF is eliminated in each line, but the line is still there.
Here are the steps I am taking when my Replace or Replace all fails.
- Select #EXTINF ↵
- VIEW ↵
- REPLACE (I change #EXTINF to ^ #EXTINF\R (REPLACE WITH is blank.) ↵ I feel this is where I am making the mistake??
- REPLACE ALL ↵
Result: "0 occurrences were replaced.
Slowly, I am making progress. I’ll hunkering down on the wiki’s. If I can get these basics down, I can make progress with my playlists and dig deeper into Notepad++
Again, thank you for taking the trouble to getting me started.
When I select the EXTINF portion of the text/line all occurrences with EXTINF turn green, however, when I include “#’ " symbol, in the string I am selecting, all the green goes away.
If you double-click select the EXTINF portion you should not get the
#symbol highlighted in green, but if you do a left-click drag selection over the entire thing (
#included) you should get the whole thing in green. Same for if you start at one end of the whole thing and then shift+arrow across it to the other side.
BTW the “green” is called the “Smart Highlighting” feature…see Settings menu -> Preferences… -> Highlighting -> Smart Highlighting for options to configure it. I tried the above things I suggested with only the Enable ticked.
@Jim-K great to see that you are still making progress. It can be a bit daunting at times, especially when exposed to something new, and yet you’ve started to see the power of regex.
As for your #EXTINF line with additional characters afterwards, this is where regex starts to show it’s true power. Normally you’d think to look for a static set of characters, with regex you can state a formula (sort of), that essentially filters the characters and can only select those that fit.
You’ve already seen the “^” (caret) and the “\R” end of line (this can be different depending on which OS is involved). Another one is the lowly “.” period character. In regular expression mode this means ANY character.
So “…” would mean any 2 characters. Because it can become tiresome to write a “.” for every character and sometimes the number may vary (this is where your issue comes in) we can instead write “.+”. This means any number (greedily) of characters. So that would consume characters up until the “\R”
So if we put ALL that together you would have:
empty field here<— so nothing in this field
remove the lines with #EXTINF regardless of the length of the text string
Another technique for removing lines containing a certain sequence of characters (in your case it seems to be
#EXTINF) is to do a Mark operation and “bookmark” the lines that have a hit. Then one can use the Bookmark menu to Remove Bookmarked Lines. Just a variation depending upon your need–I’m sure Terry’s suggestions for doing this removal are also spot-on.
Greetings Terry & Scott,
(This is getting weird. I have a sister Terry & my mother’s name is Scottie.)
First, Scott, Thanks for the “Smart Highlighting” direction:
YES, you double-click select the EXTINF portion you should not get the # symbol highlighted in green
YES, " if you do a left-click drag selection over the entire thing (# included) you should get the whole thing in green. Same for if you start at one end of the whole thing and then shift+arrow across it to the other side." “Enabled” did the trick. I unchecked all the other boxes.
PLANNED, “Mark operation and “bookmark” the lines that have a hit. Then one can use the Bookmark menu to Remove Bookmarked Lines.” Another way to skin the cat.*
Anyway, Terry, I’m getting chills; seriously…it’s been a long journey to get here from 1-year ago when all my playlists got corrupted and couldn’t be used in my application (MediaMonkey). Manually changing the playlists in their current form would have taken me the rest of my life.
YES, in 3-passes of <Find> & <Replace> I’ve been able to fix 193 .m3u files; removing #EXTM3U, #EXTINF lines and ?:\mp3library.
I’m getting numbers like 7808 & 66,301 replaces, etc. It’s exciting, but scares me at the same time ;)( What if I accidentally replaced something I didn’t mean to; Ouch! A little knowledge is dangerous. I better get myself some more disk space for backup for the original files, before I start tampering with them.
This is my first exposure to regex. There’s a lot more to dig into Notepad++ . I’ll read all the wikis & links on the Resources page. I’ll later look into creating a Macro for combining all steps into one.
This is a stupid question, however, I’m not afraid to ask ;) Here goes: When I have the <FIND>, REPLACE, FIND IN FILES & MARK open, each command line has a pull down menu from previous queries; nice feature. Is there away to delete these left-over queries in the drop down?. Why do I ask, because I have a lot of junk in them which are in error, so I’d like to delete those in the pull down.
I appreciate all your great instruction. I think I have hit a milestone and will dig deeper into NotePad++. I know of others who can benefit from your App.
Lastly, could you recommend a good place to start learning about Notepad++ . I earlier referenced the wikis and Resources page.
I see the Category:Usage(Basic Editing) Articles on NP++ Usage: “Basic Editing” Is this a good place to start, OR??? I see there are several YouTube videos I can check out.
I think I’m at a point that I can stop pestering you. I look forward to talking with you in the future as I travel this path.
@Jim-K , great to know that Notepad++ has come to your rescue. Yes it can be a bit daunting initially, thinking “did I ONLY change what I meant to”. Regex is very powerful and knowing what your data is beforehand will allow you to have confidence in the changes.
Having a backup of the original files makes a lot of sense, at least until you are confident in your changes. And the bookmarking of lines can help. So instead of deleting lines you could copy them to another tab within Notepad++, then quickly peruse those lines. If all good then back to the original tab and delete them.
Those previous search patterns are stored in a file called config.xml. It is commonly found in the %appdata%\Notepad++ folder. All the XML files “MAY” be written to by Notepad++ during or at the end of a session. Therefore if editing those XML files with Notepad++, make sure it’s the only thing you do in a session, then save, exit Notepad++ and re-enter Notepad++ for normal work.
However I wouldn’t worry too much about removing those previous searches. Given your “new found freedom” with regex I’m sure you will be doing lots of testing and trials. You will quickly fill up the history of search patterns again and again. The oldest ones drop off.
It’s not actually our App, most of us are just users of the product like yourself, albeit it a bit further on “in training” and we like to give others a leg up so to speak.
In terms of resources on the web, unfortunately it’s a bit here and a bit there. I assume you’ve already been to https://notepad-plus-plus.org/, being the home of Notepad++. This forum is a good starting point for questions. Google seems to be great at finding resources provided the right search pattern is used. As for regex, there are lots of flavours, so when you read up on it, you may find sometimes that the expression you use may not work as expected in Notepad++, that’s due to the different engines each product uses. Our FAQ has links to resources.
I personally use http://www.rexegg.com/regex-quickstart.html (and the other pages) as an excellent resource.
For testing a regex I also use:
https://regexr.com/ amongst others.
Good luck and feel free to ask when you get stumped, we’ve all been there.
PS: the day you stop learning is the day you die!
Is there away to delete these left-over queries in the drop down?
The best way to delete them is to just do more searches. There’s a limit to how many will be remembered, so when you go over that limit the old will disappear. There ARE methods to purge this information, but it is a little bit involved, and probably more trouble than it is worth.
Terry & Scott, Thanks again for the support & references to follow up…more food for thought.