Skip to content

Commit

Permalink
Merge pull request #24 from nichuanfang/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nichuanfang authored May 23, 2024
2 parents 15b5c9e + 91baf10 commit abec06d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**music-tool-kit**,主要使用场景为提取[youtube](https://www.youtube.com)[bilibili](https://www.bilibili.com)视频中的音频,支持**音频下载**,**元信息自动补全**,**音频截取**,**提取伴奏**,**youtube 列表批量下载**,**自定义批量下载**等.配合[spotify](https://open.spotify.com)**本地文件**功能可以极大的提升音乐体验([教程](https://www.bilibili.com/video/BV1VL411T7mp/?vd_source=04c6a0d121b6fb871e3d3c0a2554b29b))
**music-tool-kit**,主要使用场景为提取[youtube](https://www.youtube.com)[bilibili](https://www.bilibili.com)视频中的音频,支持**音频下载**,**元信息自动补全**,**音频截取**,**提取伴奏**,**youtube 列表批量下载**,**自定义批量下载**等.配合[itunes](https://www.bilibili.com/video/BV1sK4y1w75o/?spm_id_from=333.337.search-card.all.click&vd_source=04c6a0d121b6fb871e3d3c0a2554b29b)**本地文件**功能可以极大的提升音乐体验([教程](https://www.bilibili.com/video/BV1VL411T7mp/?vd_source=04c6a0d121b6fb871e3d3c0a2554b29b))

> [!NOTE]
>
Expand Down
35 changes: 35 additions & 0 deletions download_um.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import tarfile

import requests

# 音乐解锁软件的版本号 更新地址: https://git.unlock-music.dev/um/-/packages/generic/cli-build
um_version = '92'

def download_and_extract_um():
url = f'https://git.unlock-music.dev/api/packages/um/generic/cli-build/{um_version}/um-windows-amd64.tar.gz'
dest_dir = os.path.join(os.path.dirname(__file__), 'mk', 'bin')
os.makedirs(dest_dir, exist_ok=True)
tar_path = os.path.join(dest_dir, 'um-windows-amd64.tar.gz')

# Download the file with User-Agent header
print(f'Downloading {url}...')
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open(tar_path, 'wb') as out_file:
out_file.write(response.content)
else:
raise Exception(f"Failed to download file: {response.status_code} {response.reason}")

# Extract the tar.gz file
print(f'Extracting {tar_path}...')
with tarfile.open(tar_path, 'r:gz') as tar:
tar.extractall(path=dest_dir)

# Clean up
os.remove(tar_path)
print('Download and extraction complete.')

if __name__ == '__main__':
download_and_extract_um()
22 changes: 20 additions & 2 deletions mk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ def clip(path: str, start: str, end: str):
os.rename('output.m4a', path)
console.log(f"剪辑完成!")

# 破解音乐(暂时只支持网易云)
def unblock_music(path:str):
# 根据bin/um.exe解锁当前目录 目的是方便itunes导入 . 当前指令需要在网易云音乐指定的下载目录执行!
# 1. 获取um.exe文件目录
# 2. 目录判断,判断是否存在VipSongsDownload的同级目录,提醒用户需要在VipSongsDownload同级目录(即网易云音乐设置的本地下载路径)执行此指令;
# 3. 扫描当前目录获取所有音频文件
# 4. 扫描当前目录的子目录VipSongsDownload的音频文件
# 5. 无需破解的mp3,m4a格式直接移动到dist,flac文件则需要转换为m4a格式再移动到dist
# 6. 处理ncm文件 转换为flac等,再转m4a,移动到dist目录,删除已破解的ncm文件



pass


# 获取两个字符串相似度
# def get_similarity(s1: str, s2: str):
Expand All @@ -215,8 +229,6 @@ def clip(path: str, start: str, end: str):
# """
# return difflib.SequenceMatcher(lambda x: x in ["【", "】", "(", ")", "-", "_", ".", "[", "]", "|"], s1.lower(),
# s2.lower()).ratio()


# 从youtube搜索歌曲
async def search_youtube(name: str):
"""搜索歌曲
Expand Down Expand Up @@ -388,6 +400,7 @@ def main(args=None):
'批量下载: mk csv_path\n'
'搜索: mk -s name\n'
'剪辑: mk -c audio_path start end\n'
'破解: mk -u audio_path\n'
'---------------------------------------------\n'
)
return
Expand Down Expand Up @@ -450,6 +463,11 @@ def main(args=None):
# 下载地址 标题 开始时间 结束时间 是否生成伴奏(true or false)
writer.writerow(['url', 'title', 'start_time', 'end_time'])
print('生成成功!')
elif flag == '-u':
# 通过bin/um.exe来破解网易云音乐(暂时只支持网易云)
path = args[1]
unblock_music(path)
print('破解音乐成功!')
else:
# 判断flag是否是网址
if flag.startswith(('http://', 'https://')):
Expand Down

0 comments on commit abec06d

Please sign in to comment.