quiethost
This commit is contained in:
1 parent
9c379af76b
commit
b3c06c0a80
47 files changed
+2116
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
def write_to_quodlibet(file, lines):
|
||||
with open(os.path.join(quodlibet_path, file), 'w') as fp:
|
||||
for item in lines:
|
||||
if not item.startswith("#"):
|
||||
item = item.replace("\\", "/").replace("D:", "/data").replace("&","&")
|
||||
if os.path.exists(item):
|
||||
fp.write("%s\n" % item)
|
||||
else:
|
||||
print("File does not exist: %s in %s" % (item, os.path.join(win_dir_path, file + ".m3u")))
|
||||
ret = input("Continue?(y/n)\n")
|
||||
if ret == "n":
|
||||
print("Exit")
|
||||
exit()
|
||||
if os.path.exists(os.path.join(quodlibet_path, file + ".xspf")):
|
||||
os.remove(os.path.join(quodlibet_path, file + ".xspf"))
|
||||
|
||||
def write_to_linux(file, lines):
|
||||
with open(os.path.join(linux_dir_path, file), 'w') as fp:
|
||||
for item in lines:
|
||||
if not item.startswith("#"):
|
||||
fp.write("%s\n" % item.replace("\\", "/").replace("D:", "/data").replace("../..","/data/Nextcloud/Music"))
|
||||
|
||||
def write_to_nextcloud(file, lines):
|
||||
with open(os.path.join(nc_dir_path, file), 'w') as fp:
|
||||
for item in lines:
|
||||
item = item.replace("/data/Nextcloud/Music", "../..").replace("&","&")
|
||||
if not item.startswith("#"):
|
||||
fp.write("%s\n" % item)
|
||||
|
||||
def write_to_win(file, lines):
|
||||
with open(os.path.join(win_dir_path, file), 'w') as fp:
|
||||
for item in lines:
|
||||
item = item.replace("../..","/data/Nextcloud/Music").replace("/data", "D:").replace("/", "\\")
|
||||
if not item.startswith("#"):
|
||||
fp.write("%s\n" % item)
|
||||
|
||||
def copy_to_garmin(lines):
|
||||
for sourceFile in lines:
|
||||
if not sourceFile.startswith("#"):
|
||||
|
||||
sourceFile = sourceFile.replace("../..","/data/Nextcloud/Music").replace("&","&")
|
||||
if os.path.isfile(sourceFile):
|
||||
shutil.copy(sourceFile, "/data/Nextcloud/Music/Garmin")
|
||||
else:
|
||||
|
||||
print("WARNING: %s not found"%sourceFile)
|
||||
|
||||
def read_linux(file):
|
||||
if os.path.exists(os.path.join(quodlibet_path, file + ".xspf")):
|
||||
with open(os.path.join(quodlibet_path, file + ".xspf")) as f:
|
||||
linux_file_lines = f.read().split("</location>")[:-1]
|
||||
linux_file_lines = [line.split("<location>")[1] for line in linux_file_lines]
|
||||
elif os.path.exists(os.path.join(quodlibet_path, file)):
|
||||
with open(os.path.join(quodlibet_path, file)) as f:
|
||||
linux_file_lines = f.read().splitlines()
|
||||
return linux_file_lines
|
||||
|
||||
arguments = sys.argv[1:]
|
||||
print(arguments)
|
||||
win_dir_path = "/data/Nextcloud/Music/Playlists/Win10"
|
||||
linux_dir_path = "/data/Nextcloud/Music/Playlists/Ubuntu"
|
||||
nc_dir_path = "/data/Nextcloud/Music/Playlists/Nextcloud"
|
||||
quodlibet_path = "/home/lucas/.config/quodlibet/playlists"
|
||||
|
||||
win_files = os.listdir(win_dir_path)
|
||||
linux_files = os.listdir(linux_dir_path)
|
||||
nc_files = os.listdir(nc_dir_path)
|
||||
|
||||
linux_files = [os.path.splitext(file)[0] for file in linux_files]
|
||||
win_files = [os.path.splitext(file)[0] for file in win_files]
|
||||
nc_files = [os.path.splitext(file)[0] for file in nc_files]
|
||||
file_set = set(nc_files)
|
||||
for file in file_set:
|
||||
if file[0] == ".":
|
||||
print("Skip: %s" % file)
|
||||
continue
|
||||
file_path_m3u = os.path.join(nc_dir_path, file + ".m3u")
|
||||
file_path_m3u8 = os.path.join(nc_dir_path, file + ".m3u8")
|
||||
file_path = ""
|
||||
if os.path.exists(file_path_m3u):
|
||||
file_path = file_path_m3u
|
||||
elif os.path.exists(file_path_m3u8):
|
||||
file_path = file_path_m3u8
|
||||
with open(file_path) as f:
|
||||
nc_files_lines = f.read().splitlines()
|
||||
write_to_linux(file.replace(".m3u", ""), nc_files_lines)
|
||||
print("Copy to Linux: %s" % file)
|
||||
write_to_win(file + ".m3u", nc_files_lines)
|
||||
print("Copy to Win: %s" % file)
|
||||
if file in arguments:
|
||||
copy_to_garmin(nc_files_lines)
|
||||
print("Copy to Garmin")
|
||||
|
||||
|
||||
Reference in new issue
Block a user