m3u playlist search script

Discuss and share scripts and script files...
CodeLobster

Re: m3u playlist search script

Post by CodeLobster »

updated above script to check and report missing items if any.

missing items will not be listed among existing list items anymore.

i guess this is all that can be done regarding the OP?

the user may try to find his way to generate his own cleansed list then if he wants to? its easy, get the final $list and do a writefile out of it.

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

remove this
Last edited by kotlmg on 22 Jul 2011 09:20, edited 1 time in total.

CodeLobster

Re: m3u playlist search script

Post by CodeLobster »

basically this
asks for a file if none is selected
detects and plays .m3u, .pls files {warns when a different extension is selected}
supports playlists in portable format {file must be on <curpath> as expected for a portable playlist}
removes unavailable files from playlist popping just playable ones
has the option {disabled by default} to pop a list of missing files
copies quoted names of each available music on a single line {whatever this means; kotlmg, can you tell me what use you do out of this?}

and finally

plays selected file :mrgreen:

Code: Select all

   end(getinfo("CountSelected") < 1), "please select a file to run this script!";

   $ext = <curext>;

   IF ($ext == pls) {

   $cp = "<curpath>";
   $d = readfile(<curitem>);
   $flux = gettoken($d, "count", "<crlf>");
   $ring = 3;
   $list = "";
   $miss = "";
   WHILE ($ring <= $flux)
   {
   $play = gettoken($d, "$ring", "<crlf>");
   IF ($play == "") { break; }
   $split = gettoken($play, 2, "=");
   $test = substr($split, 1, 1);
   IF ($test == ":") {   }
   ELSEIF ($test != ":") { $split = "$cp\" . "$split"; }
   $exists = exists($split);
   IF ($exists == 1) { $list = "$list" . "$split|"; }
   ELSEIF ($exists == 0) { $miss = "$miss" . "$split<crlf>"; }
   $ring++;
   }

//enable those 2 lines to see the list of missing items
//   IF ($miss == "") {   }
//   IF ($miss != "") { text "item(s) found missing:<crlf>$miss", , , , w; }
   open inputselect("Pick the file you want to play", $list);
   $qt = "";
   foreach($i, $list, "|")
   {
      IF ($i == "") { break; }
   $q = quote($i);
   $qt = "$qt" . "$q";
   }
   copytext $qt;
   end 1;

                  }

   ELSEIF ($ext != pls) {   }

   IF ($ext == m3u) {

   $d = readfile(<curitem>);
   $e = regexreplace ($d, "#(.*?)(.*)", "");
   replace $e, $e, "<crlf>", "|";
   replace $e, $e, "<crlf>", "";
   $f = substr("$e", 0, 1);
   replace $g, $e, "$f", "";

   $cp = "<curpath>";
   $flux = gettoken($d, "count", "<crlf>");
   $ring = 1;
   $list = "";
   $miss = "";
   WHILE ($ring <= $flux)
   {
   $play = gettoken($g, "$ring", "|");
   IF ($play == "") { break; }
   $test = substr($play, 1, 1);
   IF ($test == ":") {   }
   ELSEIF ($test != ":") { $play = "$cp\" . "$play"; }

   $exists = exists($play);
   IF ($exists == 1) { $list = "$list" . "$play|"; }
   ELSEIF ($exists == 0) { $miss = "$miss" . "$play<crlf>"; }
   $ring++;
   }

//enable those 2 lines to see the list of missing items
//   IF ($miss == "") {   }
//   IF ($miss != "") { text "item(s) found missing:<crlf>$miss", , , , w; }

   open inputselect("Pick the file you want to play", $list);
   $qt = "";
   foreach($i, $list, "|")
   {
      IF ($i == "") { break; }
   $q = quote($i);
   $qt = "$qt" . "$q";
   }
   copytext $qt;
   end 1;

                  }

   ELSEIF ($ext != m3u) { end 1, "this script supports only .m3u and .pls files!"; }
Last edited by CodeLobster on 18 Jul 2011 23:30, edited 1 time in total.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: m3u playlist search script

Post by highend »

One feature wish:

is it possible to feed the inputselect with only the names of the .mp3 files (instead of full path) and assign the corresponding path to each file back afterwards?

My playlists and their music are in deep subfolders and the selection window has to be very large to see the file names on the right side. To avoid the "bad icon" in front of the list items, you could use the style element for inputselect in this case.

Regards,
highend
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

remove this
Last edited by kotlmg on 22 Jul 2011 09:21, edited 1 time in total.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: m3u playlist search script

Post by highend »

You have to indent the last 4 lines (from the popup) in your script (at least by one space) to get the script working.
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

remove this.
Last edited by kotlmg on 22 Jul 2011 10:28, edited 2 times in total.

CodeLobster

Re: m3u playlist search script

Post by CodeLobster »

by looking the modified code id tell you forgot to remove the quoting code out of pls files' part. which wont do much other than preserve your clipboard content intact then.

if i give you the vb code then you owe the coder {me} 20% of the profit, 5% to xyplorer authors and 5% to the top 10 user contributors on this forum plus kpmg's auditing services' costs. deal?

ps: edited the code anyway so other users may not complain.
Last edited by CodeLobster on 19 Jul 2011 00:25, edited 1 time in total.

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: m3u playlist search script

Post by PeterH »

If I'm not wrong code in this forum looks much better, if shown in a code-box...

...and for people who want to "play" with it it would be much more simple. :roll:
Win11 Pro 223H2 Gerrman

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

how to send clipboard contents to list view or list in xyplorer using the script. you have told that from list drag and drop and search options are possible.

CodeLobster

Re: m3u playlist search script

Post by CodeLobster »

kotlmg wrote:how to send clipboard contents to list view or list in xyplorer using the script. you have told that from list drag and drop and search options are possible.
regular list {panes} on xyplorer, not the list popped by script.

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

remove this
Last edited by kotlmg on 22 Jul 2011 09:22, edited 1 time in total.

admin
Site Admin
Posts: 60531
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: m3u playlist search script

Post by admin »

I had to remove the previous posts and the poster. Sorry for everybody involved here. Please do not respond to obvious trolls. I don't need no defense by others; I will take care myself. :)

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: m3u playlist search script

Post by highend »

I don't like the path names in the selection dialog (especially when the directory structure is relatively deep) so I modified the code a bit and made it more readable (at least for me). The script strips the full path from all .mp3 files to make the selection dialog more readable and adds them back in a later step before they're send to the actual player.

*EDIT*: I've changed the script again to remove the limitation to albums. The playlist can now contain files with different paths. *EDIT*:

Just for m3u playlists but modifying it for pls should be easy enough.

Code: Select all


/* 07.09.2011, play mp3 files from playlists
   ::load "<xyscripts>\PlaylistPlayer.xys";

   Remarks: 
*/

	$Extension = "<curext>";
	$WMP_Cmd = quote("%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe");

	// Quit if no file is selected
	end(getinfo("CountSelected") < 1), "No file selected, aborted!";

	// Check if a supported playlist file is selected
	end($Extension != "m3u" && $Extension != "pls"), "No supported playlist file selected, aborted!";

	$PlaylistFile = readfile("<curitem>");
	
	if($Extension == "m3u") {

		// Remove all unnecessary lines with #...
		$CleanupPlaylist = regexreplace("$PlaylistFile", "^#.*$", "");

		// Remove all empty lines
		$CleanupPlaylist = regexreplace("$CleanupPlaylist", "^\r?\n?", "");

		// Replace one or more line breaks (including any preceding white space) with "<crlf>"
		$CleanupPlaylist = regexreplace("$CleanupPlaylist", "\s*[\r\n]+", "<crlf>");

		// Create a list for the manual selection (without paths)
		$PlaylistWithoutPaths = "";
		foreach($Item, $CleanupPlaylist, "<crlf>") {
			if($Item == "") { break; }
			$Song = regexreplace($Item, "^(.*\\)(.*)", "$2");
			$PlaylistWithoutPaths = $PlaylistWithoutPaths . $Song . "<crlf>";
		}
		
		$FilesToPlayWithoutPath = inputselect("Pick the file(s) you want to play", "$PlaylistWithoutPaths", "<crlf>", 2);

		// Compare $FilesToPlayWithoutPath with $CleanupPlaylist; if there is a match take the corresponding file from $CleanupPlaylist
		$PlaylistWithPaths = "";
		foreach($FileToPlay, $FilesToPlayWithoutPath, "<crlf>") {
			if($FileWithoutPath == "") { break; }

			foreach($FileWithPath, $CleanupPlaylist, "<crlf>") {
				if($FileWithPath == "") { break; }
				$CompareSong = strpos("$FileWithPath", "$FileToPlay", , 1);
				if($CompareSong != "-1") { // Compare found a match
					$PlaylistWithPaths = $PlaylistWithPaths . $FileWithPath . "|";
				}
			}
		}

		// Quote all selected songs (to pass them as parameters to e.g. WMP)
		$PlayFiles = "";
		foreach($Song, $PlaylistWithPaths) {
			if($Song == "") { break; }
			$QuotedSong = quote("$Song");
			$PlayFiles = $PlayFiles . $QuotedSong . " ";
		}

		run "$WMP_Cmd $PlayFiles";
	}

One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: m3u playlist search script

Post by kotlmg »

hello highend, i modified your code to get the search results to be played with kmplayer. it is working perfectly.
can you please give the combined code for m3u and pls files search.

i am attaching the modified code as follows.

Code: Select all

/* 07.09.2011, play mp3 files from playlists
   ::load "<xyscripts>\PlaylistPlayer.xys";

   Remarks: 
*/

   $Extension = "<curext>";
   

   // Quit if no file is selected
   end(getinfo("CountSelected") < 1), "No file selected, aborted!";

   // Check if a supported playlist file is selected
   end($Extension != "m3u" && $Extension != "pls"), "No supported playlist file selected, aborted!";

   $PlaylistFile = readfile("<curitem>");
   
   if($Extension == "m3u") {

      // Remove all unnecessary lines with #...
      $CleanupPlaylist = regexreplace("$PlaylistFile", "^#.*$", "");

      // Remove all empty lines
      $CleanupPlaylist = regexreplace("$CleanupPlaylist", "^\r?\n?", "");

      // Replace one or more line breaks (including any preceding white space) with "<crlf>"
      $CleanupPlaylist = regexreplace("$CleanupPlaylist", "\s*[\r\n]+", "<crlf>");

      // Create a list for the manual selection (without paths)
      $PlaylistWithoutPaths = "";
      foreach($Item, $CleanupPlaylist, "<crlf>") {
         if($Item == "") { break; }
         $Song = regexreplace($Item, "^(.*\\)(.*)", "$2");
         $PlaylistWithoutPaths = $PlaylistWithoutPaths . $Song . "<crlf>";
      }
      
      $FilesToPlayWithoutPath = inputselect("Pick the file(s) you want to play", "$PlaylistWithoutPaths", "<crlf>", 2);

      // Compare $FilesToPlayWithoutPath with $CleanupPlaylist; if there is a match take the corresponding file from $CleanupPlaylist
      $PlaylistWithPaths = "";
      foreach($FileToPlay, $FilesToPlayWithoutPath, "<crlf>") {
         if($FileWithoutPath == "") { break; }

         foreach($FileWithPath, $CleanupPlaylist, "<crlf>") {
            if($FileWithPath == "") { break; }
            $CompareSong = strpos("$FileWithPath", "$FileToPlay", , 1);
            if($CompareSong != "-1") { // Compare found a match
               $PlaylistWithPaths = $PlaylistWithPaths . $FileWithPath . "|";
            }
         }
      }

      // Quote all selected songs (to pass them as parameters to e.g. WMP)
      $PlayFiles = "";
      foreach($Song, $PlaylistWithPaths) {
         if($Song == "") { break; }
         $QuotedSong = quote("$Song");
         $PlayFiles = $PlayFiles . $QuotedSong . " ";
      }

      
      $app = "C:\Program Files (x86)\The KMPlayer\KMPlayer.exe";
    
      run """$app"" $PlayFiles";
   }




Post Reply