33import os .path
44import shutil
55
6- #Author: "Schallbert"
6+
7+ # Author: "Schallbert"
78
89# this function pads leading zeros to a number, returning a string.
910def playerFSnumbers (indx , maxCnt ):
@@ -13,40 +14,105 @@ def playerFSnumbers(indx, maxCnt):
1314 quitWithMessage ("Error: player cannot process more than 100 folders" )
1415 return str (indx ).zfill (len (str (maxCnt )))
1516
16- def replaceSpecialCharactersInPlaylist (lineOfPlaylist ):
17+
18+ def replaceSpecialCharactersInPlaylist (line_of_playlist ):
1719 """Make sure .m3u file's special characters are converted
18- Replace most commont HTML exclamations"""
19- lineOfPlaylist = lineOfPlaylist .replace ("%20" , " " )
20- lineOfPlaylist = lineOfPlaylist .replace ("%21" , "!" )
21- lineOfPlaylist = lineOfPlaylist .replace ("%22" , '"' )
22- lineOfPlaylist = lineOfPlaylist .replace ("%23" , "#" )
23- lineOfPlaylist = lineOfPlaylist .replace ("%24" , "$" )
24- lineOfPlaylist = lineOfPlaylist .replace ("%25" , "%" )
25- lineOfPlaylist = lineOfPlaylist .replace ("%26" , "&" )
26- lineOfPlaylist = lineOfPlaylist .replace ("%27" , "'" )
27- lineOfPlaylist = lineOfPlaylist .replace ("%28" , "(" )
28- lineOfPlaylist = lineOfPlaylist .replace ("%29" , ")" )
29- lineOfPlaylist = lineOfPlaylist .replace ("%2A" , "*" )
30- lineOfPlaylist = lineOfPlaylist .replace ("%2B" , "+" )
31- lineOfPlaylist = lineOfPlaylist .replace ("%2C" , "," )
32- lineOfPlaylist = lineOfPlaylist .replace ("%2D" , "-" )
33- lineOfPlaylist = lineOfPlaylist .replace ("%2E" , "." )
34- lineOfPlaylist = lineOfPlaylist .replace ("%2F" , "/" )
35- lineOfPlaylist = lineOfPlaylist .replace ("%3A" , ":" )
36- lineOfPlaylist = lineOfPlaylist .replace ("%3B" , ";" )
37- lineOfPlaylist = lineOfPlaylist .replace ("%3C" , "<" )
38- lineOfPlaylist = lineOfPlaylist .replace ("%3D" , "=" )
39- lineOfPlaylist = lineOfPlaylist .replace ("%3E" , ">" )
40- lineOfPlaylist = lineOfPlaylist .replace ("%3F" , "?" )
41- lineOfPlaylist = lineOfPlaylist .replace ("%7E" , "~" )
42- return lineOfPlaylist
20+ Replace most commont UTF8 special characters"""
21+ line_of_playlist = line_of_playlist .replace ("%20" , " " )
22+ line_of_playlist = line_of_playlist .replace ("%21" , "!" )
23+ line_of_playlist = line_of_playlist .replace ("%22" , '"' )
24+ line_of_playlist = line_of_playlist .replace ("%23" , "#" )
25+ line_of_playlist = line_of_playlist .replace ("%24" , "$" )
26+ line_of_playlist = line_of_playlist .replace ("%25" , "%" )
27+ line_of_playlist = line_of_playlist .replace ("%26" , "&" )
28+ line_of_playlist = line_of_playlist .replace ("%27" , "'" )
29+ line_of_playlist = line_of_playlist .replace ("%28" , "(" )
30+ line_of_playlist = line_of_playlist .replace ("%29" , ")" )
31+ line_of_playlist = line_of_playlist .replace ("%2A" , "*" )
32+ line_of_playlist = line_of_playlist .replace ("%2B" , "+" )
33+ line_of_playlist = line_of_playlist .replace ("%2C" , "," )
34+ line_of_playlist = line_of_playlist .replace ("%2D" , "-" )
35+ line_of_playlist = line_of_playlist .replace ("%2E" , "." )
36+ line_of_playlist = line_of_playlist .replace ("%2F" , "/" )
37+ line_of_playlist = line_of_playlist .replace ("%3A" , ":" )
38+ line_of_playlist = line_of_playlist .replace ("%3B" , ";" )
39+ line_of_playlist = line_of_playlist .replace ("%3C" , "<" )
40+ line_of_playlist = line_of_playlist .replace ("%3D" , "=" )
41+ line_of_playlist = line_of_playlist .replace ("%3E" , ">" )
42+ line_of_playlist = line_of_playlist .replace ("%3F" , "?" )
43+ line_of_playlist = line_of_playlist .replace ("%7E" , "~" )
44+ line_of_playlist = line_of_playlist .replace ("%C3%80" , "À" )
45+ line_of_playlist = line_of_playlist .replace ("%C3%81" , "Á" )
46+ line_of_playlist = line_of_playlist .replace ("%C3%82" , "Â" )
47+ line_of_playlist = line_of_playlist .replace ("%C3%83" , "Ã" )
48+ line_of_playlist = line_of_playlist .replace ("%C3%84" , "Ä" )
49+ line_of_playlist = line_of_playlist .replace ("%C3%85" , "Å" )
50+ line_of_playlist = line_of_playlist .replace ("%C3%86" , "Æ" )
51+ line_of_playlist = line_of_playlist .replace ("%C3%87" , "Ç" )
52+ line_of_playlist = line_of_playlist .replace ("%C3%88" , "È" )
53+ line_of_playlist = line_of_playlist .replace ("%C3%89" , "É" )
54+ line_of_playlist = line_of_playlist .replace ("%C3%8A" , "Ê" )
55+ line_of_playlist = line_of_playlist .replace ("%C3%8B" , "Ë" )
56+ line_of_playlist = line_of_playlist .replace ("%C3%8C" , "Ì" )
57+ line_of_playlist = line_of_playlist .replace ("%C3%8D" , "Í" )
58+ line_of_playlist = line_of_playlist .replace ("%C3%8E" , "Î" )
59+ line_of_playlist = line_of_playlist .replace ("%C3%8F" , "Ï" )
60+ line_of_playlist = line_of_playlist .replace ("%C3%90" , "Ð" )
61+ line_of_playlist = line_of_playlist .replace ("%C3%91" , "Ñ" )
62+ line_of_playlist = line_of_playlist .replace ("%C3%92" , "Ò" )
63+ line_of_playlist = line_of_playlist .replace ("%C3%93" , "Ó" )
64+ line_of_playlist = line_of_playlist .replace ("%C3%94" , "Ô" )
65+ line_of_playlist = line_of_playlist .replace ("%C3%95" , "Õ" )
66+ line_of_playlist = line_of_playlist .replace ("%C3%96" , "Ö" )
67+ line_of_playlist = line_of_playlist .replace ("%C3%98" , "Ø" )
68+ line_of_playlist = line_of_playlist .replace ("%C3%99" , "Ù" )
69+ line_of_playlist = line_of_playlist .replace ("%C3%9A" , "Ú" )
70+ line_of_playlist = line_of_playlist .replace ("%C3%9B" , "Û" )
71+ line_of_playlist = line_of_playlist .replace ("%C3%9C" , "Ü" )
72+ line_of_playlist = line_of_playlist .replace ("%C3%9D" , "Ý" )
73+ line_of_playlist = line_of_playlist .replace ("%C3%9E" , "Þ" )
74+ line_of_playlist = line_of_playlist .replace ("%C3%9F" , "ß" )
75+ line_of_playlist = line_of_playlist .replace ("%C3%A0" , "à" )
76+ line_of_playlist = line_of_playlist .replace ("%C3%A1" , "á" )
77+ line_of_playlist = line_of_playlist .replace ("%C3%A2" , "â" )
78+ line_of_playlist = line_of_playlist .replace ("%C3%A3" , "ã" )
79+ line_of_playlist = line_of_playlist .replace ("%C3%A4" , "ä" )
80+ line_of_playlist = line_of_playlist .replace ("%C3%A5" , "å" )
81+ line_of_playlist = line_of_playlist .replace ("%C3%A6" , "æ" )
82+ line_of_playlist = line_of_playlist .replace ("%C3%A7" , "ç" )
83+ line_of_playlist = line_of_playlist .replace ("%C3%A8" , "è" )
84+ line_of_playlist = line_of_playlist .replace ("%C3%A9" , "é" )
85+ line_of_playlist = line_of_playlist .replace ("%C3%AA" , "ê" )
86+ line_of_playlist = line_of_playlist .replace ("%C3%AB" , "ë" )
87+ line_of_playlist = line_of_playlist .replace ("%C3%AC" , "ì" )
88+ line_of_playlist = line_of_playlist .replace ("%C3%AD" , "í" )
89+ line_of_playlist = line_of_playlist .replace ("%C3%AE" , "î" )
90+ line_of_playlist = line_of_playlist .replace ("%C3%AF" , "ï" )
91+ line_of_playlist = line_of_playlist .replace ("%C3%B0" , "ð" )
92+ line_of_playlist = line_of_playlist .replace ("%C3%B1" , "ñ" )
93+ line_of_playlist = line_of_playlist .replace ("%C3%B2" , "ò" )
94+ line_of_playlist = line_of_playlist .replace ("%C3%B3" , "ó" )
95+ line_of_playlist = line_of_playlist .replace ("%C3%B4" , "ô" )
96+ line_of_playlist = line_of_playlist .replace ("%C3%B5" , "õ" )
97+ line_of_playlist = line_of_playlist .replace ("%C3%B6" , "ö" )
98+ line_of_playlist = line_of_playlist .replace ("%C3%B8" , "ø" )
99+ line_of_playlist = line_of_playlist .replace ("%C3%B9" , "ù" )
100+ line_of_playlist = line_of_playlist .replace ("%C3%BA" , "ú" )
101+ line_of_playlist = line_of_playlist .replace ("%C3%BB" , "û" )
102+ line_of_playlist = line_of_playlist .replace ("%C3%BC" , "ü" )
103+ line_of_playlist = line_of_playlist .replace ("%C3%BD" , "ý" )
104+ line_of_playlist = line_of_playlist .replace ("%C3%BE" , "þ" )
105+ line_of_playlist = line_of_playlist .replace ("%C3%BF" , "ÿ" )
106+ return line_of_playlist
107+
43108
44109def quitWithMessage (messageString ):
45110 """Quits script gracefully with message"""
46111 print (messageString )
47112 input ("Press Enter to quit..." )
48113 sys .exit ()
49114
115+
50116print ("\
51117 Starting Conversion script for structuring files for DFplayerMini.\n \
52118 This script analyzes .m3u playlists and restructures their contents to a format\n \
@@ -160,8 +226,10 @@ def quitWithMessage(messageString):
160226 shutil .copy2 (line , os .path .join (os .sep , tgtFldrPath ,
161227 tgtFileName )) # copies & renames file from playlist to tgt folder
162228 except :
163- quitWithMessage ("--- ERROR --- Couldn't copy file\n " + str (line ) + " to:\n " + str (tgtFldrPath ) + "\n Aborting." )
164- print ("...completed for folder %d of %d: %s with %d files" % (folderIndex , len (listOfPlaylists ), item , fileIndex ))
229+ quitWithMessage (
230+ "--- ERROR --- Couldn't copy file\n " + str (line ) + " to:\n " + str (tgtFldrPath ) + "\n Aborting." )
231+ print (
232+ "...completed for folder %d of %d: %s with %d files" % (folderIndex , len (listOfPlaylists ), item , fileIndex ))
165233 quitWithMessage ("--- SUCCESS --- All actions completed successfully." )
166234else :
167- quitWithMessage ("--- ERROR --- No playlists found in folder. Place .m3u file(s) here, please. Aborting." )
235+ quitWithMessage ("--- ERROR --- No playlists found in folder. Place .m3u file(s) here, please. Aborting." )
0 commit comments