diff bandm3u/bandm3u.py @ 0:dcd610585610

INIT
author prymula <prymula76@outlook.com>
date Thu, 21 Sep 2023 22:32:14 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bandm3u/bandm3u.py	Thu Sep 21 22:32:14 2023 +0200
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# bandm3u- skrypt do tworzenia playlist m3u
+# 16-02-2023
+# Edytor: Geany
+# (c) by P.R.P
+# Mój pierwszy skrypt stworzony w Windows 11
+
+import os 
+
+dir = os.getcwd()
+
+data_files = []
+data_out = []
+extension = ['mp3', 'ogg', 'wav']
+
+def check(string, sub_str):
+	if (string.find(sub_str) == -1):
+		return False
+	else:
+		return True
+
+for data in os.listdir(dir):
+	for e in extension:
+		if check(data, e):
+			data_files += [os.path.basename(data)]
+
+#print (data_files)
+for n in range(100):
+	for f in data_files:
+		if n > 9:
+			nn = str(n)+" "
+		else:
+			nn = "0"+str(n)+" "
+		# sprawdza liczbę porządkową
+		if check(f, nn):
+			data_out.insert(n, f)
+
+
+c = '\\' 
+
+# indeksy wysępowania znaku slash/unslash w łańcuchu
+slash = [pos for pos, char in enumerate(dir) if char == c]
+# zdejmuje ostatni indeks
+last_slash  = slash.pop()
+
+
+f=open(dir[last_slash+1:]+".m3u","w+") # file name and mode
+for x in range(0, len(data_out)):
+    f.writelines(data_out[x])
+    f.writelines("\r\n")
+f.close()
+
+print (dir)
+print (data_out)