python - 使用正则表达式(或类似的)通过脚本更改 itunes 中的歌曲名称(或其他标签)

标签 python string applescript itunes

所以我遇到了脚本问题(并且找不到特定的应用程序来与 itunes 结合执行此操作)。

我可以对 Python 中的任何脚本执行类似的操作,假设我有歌曲标题:

我的心跳 - 原创混音

我想将其更改为我的心跳(原始混音)

在Python中我会:

string = 'Beat of my heart - original mix'
location = string.index(' - ')
fixed_string = string[,location] + '(' + string[location+3,] + ')'

简单吧? 但我想在 iTunes(在 Mac 上)中对我已标记为此类的轨道进行批处理

有什么建议吗?

谢谢

最佳答案

尝试:

tell application "iTunes"
    set myTracks to get selection
    repeat with aTrack in myTracks
        set trackName to aTrack's name
        set newTrackName to do shell script "sed 's/ - \\(.*\\)/ (\\1)/' <<< " & quoted form of trackName
        if newTrackName ≠ trackName then set aTrack's name to newTrackName
    end repeat
end tell

关于python - 使用正则表达式(或类似的)通过脚本更改 itunes 中的歌曲名称(或其他标签),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18601725/

相关文章:

php - 退出 HTML 页面时停止在 PHP 文件中调用的 Python 脚本

python - 运行使用 folium 的可执行文件时,Branca Python 模块无法找到 2 个必要的 json 文件

regex - 如何检查字符串是否包含一组条件

shell - 使用 Applescript 和 Shell 在终端中显示今天的事件

Applescript 将显示切换到灰度模式

javascript - 使用 `runScript`函数运行JXA脚本不允许参数

python - 将具有给定 C header 的深层嵌套结构解包到字典中?

python - lambda 函数对字典中值的乘积求和

c++ - vector 字符串 push_back 在 C++ 中不起作用

c - 将字符串拆分为整数