{"id":74,"date":"2024-11-25T21:50:46","date_gmt":"2024-11-25T21:50:46","guid":{"rendered":"https:\/\/paulmcgrath.net\/?p=74"},"modified":"2024-11-27T21:47:37","modified_gmt":"2024-11-27T21:47:37","slug":"m3u-playlist-file-creation-before-importing-into-plex","status":"publish","type":"post","link":"https:\/\/paulmcgrath.net\/?p=74","title":{"rendered":"m3u playlist file creation before importing into Plex"},"content":{"rendered":"\n<p><strong>What I did in order to create m3u files I could import into Plex<\/strong><\/p>\n\n\n\n<p>Creating the playlist files in Plex is tedious.  It is better to import them.  This cannot be done simply through the Plex web interface, you need to use the API.<\/p>\n\n\n\n<p>This is not as difficult as it sounds.  I am not a programmer\/developer by profession but I am tech savvy.<\/p>\n\n\n\n<p>Some things to consider:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>the m3u content file path for each mp3 file has to match your Plex media path<\/li>\n\n\n\n<li>characters in the folder and file names that can be supported, accented characters from French, Spanish and other languages may be difficult to import in code<\/li>\n<\/ul>\n\n\n\n<p>The steps I took:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>created m3u files using VBScript<\/li>\n\n\n\n<li>captured a list of the m3u files generated<\/li>\n\n\n\n<li>converted the m3u file list into a batch file for import.  I cover this in <a href=\"https:\/\/paulmcgrath.net\/?p=63\" target=\"_blank\" rel=\"noopener\" title=\"\">another post<\/a><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>VBScript to generate m3u files<\/strong><\/p>\n\n\n\n<p>I found a VBScript which someone has developed to create m3u files trawling through folders and subfolders looking for specific files types (mp3, wma, m4a).  I modified it to create the m3u file with the content for each mp3 file with a prefix that matches my Plex media path AND using the artist and album name in the m3u file name title.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Const ForReading = 1, ForWriting = 2, ForAppending = 8\n\n' Parse command-line arguments\ndelete = false\nset args = WScript.Arguments\nif args.Count &gt; 0 then\nif LCase(args(0)) = \"-d\" then\ndelete = true\nend if\nend if\n\n' Write m3u files for current directory tree\nset fso = CreateObject(\"Scripting.FileSystemObject\")\nwscript.echo WriteM3u(fso.GetAbsolutePathName(\".\"), delete) &amp; \" files written\"\n\n' Recursive function to write m3u files for a given path\nfunction WriteM3u(path, delete)\ncount = 0\nset fso = CreateObject(\"Scripting.FileSystemObject\")\nset fdr = fso.GetFolder(path)\n\n' Write m3u file for each subfolder\nif fdr.SubFolders.Count &gt; 0 then\nfor each subFolder in fdr.SubFolders\ncount = count + WriteM3u(subFolder.path, delete)\nnext\nend if\n\n' If no files found in subfolders, write m3u file for this folder\nif count = 0 then\nrem wscript.echo \"Scanning \"\"\" &amp; fdr.Path &amp; \"\"\"\"\n' Build list of mp3\/wma files\nmp3List = \"\"\nm3uName = fdr.ParentFolder.Name\nfor each f in fdr.Files\nif right(f.Name, 3) = \"mp3\" or right(f.Name, 3) = \"wma\" or right(f.Name, 3) = \"m4a\" then\nmp3List = mp3List &amp; \"\/media\/music\/artists\/\" &amp; fdr.ParentFolder.Name &amp; \"\/\" &amp; fdr.Name &amp; \"\/\" &amp; f.Name &amp; VBCrLf\nend if\nnext\n\n' If any files found, write m3u file\nif mp3List &lt;&gt; \"\" then\n' Multi-disc folder handling\nif len(fdr.Name) = 6 and left(fdr.Name, 5) = \"Disc \" then\nm3uName = fdr.ParentFolder.Name &amp; \" - \" &amp; \" (\" &amp; fdr.Name &amp; \").m3u\"\nelse\nm3uName = fdr.ParentFolder.Name &amp; \" - \" &amp; fdr.Name &amp; \".m3u\"\nend if\n\n' Existing m3u file handling\nm3u = path &amp; \"\\\" &amp; m3uName\nif fso.FileExists(m3u) then\n'fso.DeleteFile m3u\nend if\n\n' Write new m3u file\nrem wscript.echo \"... writing \"\"\" &amp; m3uName &amp; \"\"\"\"\nset m3uFile = fso.OpenTextFile(m3u, ForWriting, True)\nm3uFile.Write(mp3List)\nm3uFile.Close\ncount = 1\nelse\nrem wscript.echo \"... no mp3\/wma files found\"\nend if\nend if\n\n' Return m3u file count\nWriteM3u = count\nend function<\/code><\/pre>\n\n\n\n<p>The lines that need to be modified for you configuration are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Path in the m3u for your Plex media &#8211; mp3List = mp3List &amp; &#8220;\/media\/music\/artists\/&#8221; <\/li>\n\n\n\n<li>m3u file name  &#8211; m3uName = fdr.ParentFolder.Name &amp; &#8221; &#8211; &#8221; &amp; &#8221; (&#8221; &amp; fdr.Name &amp; &#8220;).m3u&#8221;<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>List of m3u files on your system<\/strong><\/p>\n\n\n\n<p>In CMD you can dir &gt; txt in order to find all the m3u files.  To get the minimum information you need then use this command:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>dir \/s \/b *.m3u &gt; my-m3u-files.txt<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Create batch file to import into Plex<\/strong><\/p>\n\n\n\n<p>Using Excel and a notepad editor like notepad++ you can create a batch file.<\/p>\n\n\n\n<p>In notepad you need to replace the spaces with %20 and other characters with URL codes, see my other post which details this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"332\" src=\"https:\/\/paulmcgrath.net\/wp-content\/uploads\/2024\/11\/image-1024x332.png\" alt=\"\" class=\"wp-image-75\" srcset=\"https:\/\/paulmcgrath.net\/wp-content\/uploads\/2024\/11\/image-1024x332.png 1024w, https:\/\/paulmcgrath.net\/wp-content\/uploads\/2024\/11\/image-300x97.png 300w, https:\/\/paulmcgrath.net\/wp-content\/uploads\/2024\/11\/image-768x249.png 768w, https:\/\/paulmcgrath.net\/wp-content\/uploads\/2024\/11\/image.png 1178w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>You have to modify the server address, sectionID and Token value.  Insert your modified m3u list in column B.<\/p>\n\n\n\n<?php pvc_stats_update( $postid, 1 ); ?> \n","protected":false},"excerpt":{"rendered":"<p>What I did in order to create m3u files I could import into Plex Creating the playlist files in Plex is tedious. It is better to import them. This cannot be done simply through the Plex web interface, you need to use the API. This is not as difficult as it sounds. I am not &hellip; <a href=\"https:\/\/paulmcgrath.net\/?p=74\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;m3u playlist file creation before importing into Plex&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-general"],"a3_pvc":{"activated":false,"total_views":0,"today_views":0},"_links":{"self":[{"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":4,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paulmcgrath.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}