Skip to content

Instantly share code, notes, and snippets.

@JichunMa
Last active November 20, 2022 07:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JichunMa/d155141dc6a375bd1da5e242f82512ca to your computer and use it in GitHub Desktop.
Save JichunMa/d155141dc6a375bd1da5e242f82512ca to your computer and use it in GitHub Desktop.
Mac numdump helper (need: Python3)
import os
import time
COMPLETE_FILE_DIR = './done/'
# 文件名两边添加双引号
def str_transform(source):
return '\"{}\"'.format(source)
if __name__ == '__main__':
# numdump也在/Users/majichun/Music/网易云音乐 路径下
os.chdir('/Users/majichun/Music/网易云音乐')
files = os.listdir('./') # 得到文件夹下的所有文件名称
for fileName in files:
new_fileName = str_transform(fileName)
if fileName.endswith('.ncm'):
commandResponse = os.popen('ncmdump ' + new_fileName)
convertedFileName = commandResponse.readline()
print('convert name is: ' + convertedFileName)
# 停留1秒
time.sleep(1)
os.system('rm ' + new_fileName)
# 转化好的mp3不在files里所以需要手动执行一次mv操作
if not os.path.isdir(COMPLETE_FILE_DIR):
os.mkdir(COMPLETE_FILE_DIR)
os.system('mv ' + str_transform(convertedFileName.strip('\n')) + ' ' + COMPLETE_FILE_DIR)
elif fileName.endswith('.mp3'):
# 将生成好的文件放到./done目录下
if not os.path.isdir(COMPLETE_FILE_DIR):
os.mkdir(COMPLETE_FILE_DIR)
os.system('mv ' + new_fileName + ' ' + COMPLETE_FILE_DIR)
@LJJHD
Copy link

LJJHD commented Aug 7, 2020

请问一下你这个放到哪个文件夹里面运行?我放在了ncmdump 这个文件夹里面。运行报错:./numdump_helper.py: line 1: import: command not found
./numdump_helper.py: line 2: import: command not found
./numdump_helper.py: line 4: COMPLETE_FILE_DIR: command not found
./numdump_helper.py: line 8: syntax error near unexpected token (' ./numdump_helper.py: line 8: def str_transform(source):'

@JichunMa
Copy link
Author

JichunMa commented Aug 7, 2020

import: command not found
建议google

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment