Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Sort the index.txt file for standard Playlist Switcher (Read 797 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Sort the index.txt file for standard Playlist Switcher

Since Playlist Organizer 2.6 (foo_plorg) was broken when updating to foobar2000 v2 I've tried other playlist managers such as SMP Playlist and this Playlist Organizer (aka foo_plorg) replacement.

But, with the amount of playlists I have, I found the replacement foo_plorg slow to load with foobar and in the case of SMP which isn't that slow it doesn't have treeview and with the amount of playlist I have, it's impossible to use efficiently so I see no benefit in it any more and there's too many bugs with it and just overly complex to make it usable.

I just find the built in Playlist Swither much faster overall and it has most of what I need. It really is only missing the count for the files in each playlist for me. I can live without a tree view as long as it's quicker than anything else.

So, for now, I'm going to use the standard Playlist Switcher until the original foo_plorg is updated.

The only downside for me is that there's no easy way to sort the playlists, so I've written a small .ps1 file to sort the contents of the index.txt.

Here's the code with explanations on how to install it and to a toolbar in columns UI.

Code: [Select]
<#

  _Sort Playlist.ps1

.SYNOPSIS
  This program sorts the 'index.txt'

.NOTES RELEASES AND UPDATES
  First Release - 2024.05.26 by stevehero

.DESCRIPTION
  This program sorts the 'index.txt' file located here on my machine at least:
  W:\Apps (Portable)\Music Apps\foobar2000\profile\playlists-v2.0

  Tested using a portable installation, so this should work with regular
  installs.

  .CAVEATS
  You need to restart foobar2000 to see the updated order.

.NOTES INSTALLING
  Copy this code and save it to a "_Sort Playlist.ps1" file and place it in the
  playlist folder.

  The playlist folder can be located by searching for the index.txt file where
  foobar2000 is installed.

  There should be a bunch of files like these below:

  playlist-00B9060C-EC93-4499-BCDC-6C688C392125-props.sqlite
  playlist-00B9060C-EC93-4499-BCDC-6C688C392125.fplite
  playlist-00C7A713-B487-48DC-9EE0-93E72FCBF94D-props.sqlite
  playlist-00C7A713-B487-48DC-9EE0-93E72FCBF94D.fplite

.EXAMPLE ADDING TO A TOOLBAR IN FOOBAR USING COLUMNS UI
  Note: I don't know if this is possible with the vanilla install.

  1.  Install run services component:
      https://www.foobar2000.org/components/view/foo_run

  2.  With foobar2000 open, go to:
      File>Preferences>Tools>Run Services

  3.  Click A̲dd

  4.  Label:
      Sort Playlists '('The index.txt File')'

  5.  Path: Paste this (Replace the location of the .ps1 file to yours) Ensure
      that the path is wrapped in quotes and any ( or ) are wrapped with
      semi-colons like '(' and ')'.
      cmd /c start /min "" powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File "W:\Apps '('Portable')'\Music Apps\foobar2000\profile\playlists-v2.0\_Sort Playlists.ps1"

  6.  Using columns UI for this step.

  7.  Right-click on the toolbar area and click Button Options.

  8.  Click Add>Click Context menu items

  9.  Select "Active Selection" for the item group. I've tried "None" here but it
      needs something to be selected to run this program.

  10. Under command scroll down to you see
      Run service/Sort Playlists '('The index.txt File')'

  11. From here it's fairly self-explanatory to set an icon or custom text for
      the toolbar. I used display mode: Text and checked the custom text
      checkbox and for that is used "Sort Playlists".

  12. You can order the button by dragging it to your desired location on the
      toolbar.

  13. Click "OK".

  14. Then click that on the toolbar. The index.txt file will be sorted but not
      show correctly until foobar2000 is restarted.

.NOTES DISCLAIMER
  Use at your own risk and pretty please, DO NOT MODIFY.

#>

#####
##### FUNCTIONS CODE BELOW
##### FUNCTIONS CODE BELOW
##### FUNCTIONS CODE BELOW
#####

Function Show-MessageBox_UI_Independant {

<#

  .SYNOPSIS
  Show a messagebox modal message box even when it's not used with an UI.

  .DESCRIPTION
  Shows a messagebox that can be modal which the standard one doesn't and can be
  used independently of a UI such as a stand-alone script.

  Add-Type -AssemblyName PresentationFramework
  $msgBoxInput =  [System.Windows.MessageBox]::Show("Message", 'Title','OK')

  .NOTES
  Author: stevehero
  Date Created: 2024.05.26
  Tested with PowerShell 5.1 and 7.1.
  Posted the other example here: https://stackoverflow.com/questions/51066978/convert-to-json-with-comments-from-powershell

  .BUGS: NA

  .TODO: NA

  .PARAMETER Modal
  Switch to show messagebox as Modal, which means it stays on top of all other
  applications until the user clicks a button.

  .PARAMETER Title
  The title of the messagebox that appears in the title bar of the dialog.

  .PARAMETER Message
  The main message of the messagebox.

  .PARAMETER Buttons
  The Buttons to show, please see below.

  Member                  Value         Description
  OKOnly                  0             Displays OK button only.
  OKCancel                1             Displays OK and Cancel buttons.
  AbortRetryIgnore        2             Displays Abort, Retry, and Ignore buttons.
  YesNoCancel             Displays      Yes, No, and Cancel buttons.
  YesNo                   Displays      Yes and No buttons.
  RetryCancel             Displays      Retry and Cancel buttons.
  Critical                16            Displays Critical Message icon.
  Question                32            Displays Warning Query icon.
  Exclamation             Displays      Warning Message icon.
  Information             Displays      Information Message icon.
  DefaultButton1          0             First button is default.
  DefaultButton2          256           Second button is default.
  DefaultButton3          512           Third button is default.
  ApplicationModal        0             Application is modal. The user must respond to the message box before continuing work in the current application.
  SystemModal             System        is modal. All applications are suspended until the user responds to the message box.
  MsgBoxSetForeground     Specifies     the message box window as the foreground window.
  MsgBoxRight             Text          is right-aligned.
  MsgBoxRtlReading        1048576       Specifies text should appear as right-to-left reading on Hebrew and Arabic systems.

  .INPUTS
  None. You cannot pipe objects to this.

  .OUTPUTS
  Based on the button you press, this returns these below.

  OK
  Cancel
  Abort
  Retry
  Ignore
  Yes
  No

  To incorporate that into you main program, you can do something like this:

  $resultMsg = Show-MessageBox_UI_Independant -Modal -Title "Hi there!" -Message "Important message goes here`nImportant message goes here." -Buttons "OkCancel,DefaultButton1"

  if ($resultMsg -eq 'OK') {Write-Host "It's okay to press me.."}

  .EXAMPLE Shows a Modal messagebox that stays on top of all other app until the user clicks a button
  PS> Show-MessageBox_UI_Independant -Modal -Title "Hi there!" -Message "Important message goes here`nImportant message goes here." -Buttons "OkCancel"

  .EXAMPLE Show a normal messagebox
  PS> Show-MessageBox_UI_Independant -Title "Hi there!" -Message "Important message goes here`nImportant message goes here." -Buttons "OkCancel"

  .EXAMPLE Show a normal messagebox with the default button being the OK button
  PS> Show-MessageBox_UI_Independant Title "Hi there!" -Message "Important message goes here`nImportant message goes here." -Buttons "OkCancel,DefaultButton1"

#>

  [CmdletBinding()]
  Param (
    [Parameter(Mandatory = $false)]
    [string]$Title = 'MessageBox in PowerShell',

    [Parameter(Mandatory = $true)]
    [string]$Message,

    [Parameter(Mandatory = $false)]
    [string]$Buttons = 'OKCancel',

    [Parameter(Mandatory = $false)]
    [ValidateRange(1, 3)]
    [int]$DefaultButton = 1,

    [Parameter(Mandatory = $false)]
    [Switch]$Modal = $false
  )

  # Determine the modal parameter
  if ($Modal -eq $true) { $ModalOn = 'SystemModal,' } else { $ModalOn = '' }

  Add-Type -AssemblyName System.Windows.Forms
  [void][System.Windows.Forms.Application]::EnableVisualStyles()

  [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
  [Microsoft.VisualBasic.Interaction]::MsgBox($Message, "$($ModalOn)$($Buttons)", $Title)

}

################################################################################
# Get-PSScriptPath function (Must be at the top)
################################################################################

Function Get-PSScriptPath {

  <#

  .SYNOPSIS
  Returns the current file path of the .ps1 or compiled .exe with Win-PS2EXE.

  .DESCRIPTION
  This will return the path of the file. This will work when the .ps1 file is
  converted with Win-PS2EXE

  .NOTES
  Author: stevehero
  Date Created: 2021.05.03
  Tested with PowerShell 5.1 and 7.1.
  Posted here: https://stackoverflow.com/q/60121313/8262102

  .PARAMETER None
  NA

  .INPUTS
  None. You cannot pipe objects to Get-PSScriptPath.

  .OUTPUTS
  Returns the current file path of the .ps1 or compiled .exe with Win-PS2EXE.

  .EXAMPLE (When run from a .ps1 file)
  PS> Get-PSScriptPath
  PS> C:\Users\Desktop\temp.ps1

  .EXAMPLE (When run from a compiled .exe file with Win-PS2EXE.
  PS> Get-PSScriptPath
  PS> C:\Users\Desktop\temp.exe

  #>

  if ([System.IO.Path]::GetExtension($PSCommandPath) -eq '.ps1') {
    $psScriptPath = $PSCommandPath
  }
  else {
    # This enables the script to be compiled and get the directory of it.
    $psScriptPath = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName
  }
  return $psScriptPath

}

#####
##### MAIN PROGRAM START
##### MAIN PROGRAM START
##### MAIN PROGRAM START
#####

# Define the input filename
$inputFileName = "index.txt"
# Define the output filename (You can change this to test before you try this program)
$outputFileName = "index.txt"
# Define the path to the input file
$inputFilePath = (Split-Path -LiteralPath (Get-PSScriptPath)) + "\" + $inputFileName
# Define the path to the output file
$outputFilePath = (Split-Path -LiteralPath (Get-PSScriptPath)) + "\" + $outputFileName

# Read all lines from the input file (Uses encoding to not mess up special characters)
$lines = Get-Content -Encoding UTF8 -LiteralPath $inputFilePath

# Extract the sortable key after the first colon and sort the lines
$sortedLines = $lines | Sort-Object {
    # Split the line at the first occurrence of the colon
    $lineParts = $_ -split ':', 2
    if ($lineParts.Length -gt 1) {
        # Use the part after the first colon for sorting
        $lineParts[1].Trim()
    } else {
        # Fall back in case there is no colon in the line
        $_
    }
}

# Write the sorted lines to the output file (Uses encoding to not mess up special characters)
$sortedLines | Set-Content -Encoding UTF8 -Path $outputFilePath

# Show message box to restart foobar2000 to see the changes
Show-MessageBox_UI_Independant -Modal -Title "Playlist File Sorted..." -Message ("Playlist File $inputFileName sorted:`n`n$outputFilePath`n`n(Please restart foobar2000 to see the changes)") -Buttons "OkOnly"

#####
##### MAIN PROGRAM END
##### MAIN PROGRAM END
##### MAIN PROGRAM END
#####

What you'll see when you run program.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #1
This playlist switcher included with JScript Panel 3 has a right click option to sort playlists by name.

https://jscript-panel.github.io/gallery/smooth-playlist-manager/

I'd be interested if it's "slow" like the plorg replacement you tried.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #2
Marc!! That blows anything I've used out of the water. Speed is everything and that is as quick as the built in one. Thanks for showing me this.

Is single left click possible to activate the playlist like the default Switcher?

If this had tree view then it would be the ideal playlist manager.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #3
Right click the header/scrollbar>Configure, you can add this bit of code to override the mouse click...

Code: [Select]
function on_mouse_lbtn_down(x, y) {
brw.on_mouse("lbtn_dblclk", x, y);
}

Re: Sort the index.txt file for standard Playlist Switcher

Reply #4
Nice one, thanks.

One thing I did notice is the arrow keys don't work when your editing the name of a playlist.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #5
The original script works but that mod I posted breaks it. Try replacing it with this instead...

Code: [Select]
function on_mouse_lbtn_down(x, y) {
if (brw.inputboxID > -1) {
brw.on_mouse("lbtn_down", x, y);
} else {
brw.on_mouse("lbtn_dblclk", x, y);
}
}

Re: Sort the index.txt file for standard Playlist Switcher

Reply #6
I had a fairly recent version of JScript Panel 3 but updated it just in case.

But the arrows still don't work for me when editing playlist name.


Re: Sort the index.txt file for standard Playlist Switcher

Reply #8
Yes. Did that also. No joy. 

Re: Sort the index.txt file for standard Playlist Switcher

Reply #9
Biting on this because your comment was unrealistic, involves misinformation and is not representative of the plugins you mentioned. Not sure which SMP manager are you talking about but for sure mine has a tree view (since it has folders) xd

X

No one has complained about "too many bugs", but you. I mean, just because you have found "2 bugs" lately, doesn't mean you are right. Specially when every single report I have got about any of my scripts on github, has been usually fixed and closed in less than a week (saying this because I usually offer support and care about making things work, even when people have exotic setups, Wine or whatever). More funny is your "bugs" are not bugs... just you not understanding the usage or the settings you used.

Also, you are comparing a manager with thousand of features with things that mainly sort UI playlists in a tree view. I mean, if that's what you need, then fine. It's an apples/oranges comparison. My manager is meant for people who are tired of having 2000 ui playlists loaded everytime on foobar, so it's meant to be used along playlist files. Using it as a foo_plorg replacement was just an extra, but it's clearly not the intended usage as stated everywhere on github, the HA topic, the readme PDF, ... Also most complex functionalities can be removed (and menus simplified) at the features submenu.

I simply found ironic that you complain about something being more complex than whatever you need... then clearly the problem is you used something not suited for your needs.  I am glad there are other options, like foo_plorg replacement or the js smooth manager, so we have choice. It's perfectly fine some people need simple things, it's also fine if some people need more complex things (which are not unusable just because you don't get them).

Finally, about the other JSP manager, maybe and just maybe it's more productive to report in their thread your performance problems so the author can take care of it (or warn about a limit with the number of playlists).

PD: Would also like to clarify and rectify your info about foo_plorg being broken after V2. It was already broken on V1, as reported multiple times.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #10
SMP doesn't suit my needs (you're dead right about that). Sorry if I offended you by not liking it. Don't put your software on public domain if you don't like criticism.

Let me point out what I don't like about it, since you asked.
  • It's very slow in comparison to Marc's Playlist manager.
  • UI keeps jumping around the place, that last bug report I posted on github, you say isn't one. If that's by design then, it's a new one on me. Imagine deleting a folder in File Explorer and the scrolling goes way off to somewhere else. If you deleted a track from a playlist and the scroll went elsewhere would you class that as by design?
  • Playlist numbers don't update quickly (If at all).
  • Overly complex for what it is.
  • Playlist duplicates themselves for no reason. Latest Github report I put up, you say it's how I've set up your component that's causing it. Then remove it, if that's the case.
  • Would also like to clarify and rectify your info about only 2 bugs lately. It's been 13 bugs in total in the last year. https://github.com/regorxxx/Playlist-Manager-SMP/issues?q=author%3Astephen147+label%3Abug

I wouldn't get too hung up on what I think. I mentioned your plugin as I don't like it anymore and if you feel aggrieved by that, well that's not my issue.

I'm looking for an alternative now. Sorry about that.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #11
I can not care less if you like it or not, it's totally fine. Really.

Is just that you are writing nonsense without reason. You simply don't understand how to use it and are complaining things don't work how you want without reading the manual or understanding the script.

1. No. You simply didn't care to change the timeouts to update the playlist list. (which again is there for files, not just UI playlists).
2. I gave you the explanation on github.
3. Read 1. xd You can make it refresh on real time.
4. This is like saying foobar is overly complex when you only need WMP.
5. Again you don't understanding the features YOU have set. Because that feature is not active by default.
6. Wow 13 bugs on a year. Incredible. All fixed within a week. Do you know how ridiculous that sounds? I mean, if you read marc's threads, it's like sometimes he updates a plugin 3 times a day because of bugs or errors xd does that make him or his plugins bad? too many bugs? I don't think so.

I'm out of this conver, have no time to waste with people not reading manuals and just asking devs to set things to their liking.

Re: Sort the index.txt file for standard Playlist Switcher

Reply #12
Yes. Did that also. No joy.

Well it's certified "working on my pc".



Do you get the bug with the original unmodified script in the panel? That would be weird...


Re: Sort the index.txt file for standard Playlist Switcher

Reply #13
Do you get the bug with the original unmodified script in the panel? That would be weird...
Yes, with the stock playlist.

I think it's a focus issue. I've the left/right keys mapped and the spacebar to play/pause.

Just to let you know, I don't have any issue typing in any another part of the UI

See here:



Re: Sort the index.txt file for standard Playlist Switcher

Reply #14
So you completely missed this prompt when assigning keys without modifiers?



edit: I'm guessing other components work through using proper edit controls as a child window. My component doesn't support that and it's not likely to either.


 

Re: Sort the index.txt file for standard Playlist Switcher

Reply #15
No worries. That was about 5 years ago I mapped my keyboard shortcuts when I moved to foobar2000 and there's been no issues so far.