跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[分享创造] 一个简单的批量重命名/链接/移动文件的 CLI 工具

发表于

因为我在自己的媒体服务器里使用的都是 PT 站上的资源,而媒体服务器通常都要求文件名遵循一定的格式(比如 Jellyfin),所以需要重命名做种的文件。虽然我用的 qBittorrent 可以重命名文件并继续做种,但一个一个重命名实在麻烦,后面就通过 Bash 脚本来干这个事,批量将视频文件软链接到对应的媒体文件夹,这样就可以同时做种和提供媒体服务。

但由于 Bash 语言的局限,这个脚本的扩展性不太好,现在重新用 Python 写了一个专门批量重命名/链接/移动文件的 CLI 工具:batchlink。Python 自带电池,很多我需要的函数标准库里都有,所以实现起来很简单。

举一个我自己的例子:

batchlink -s \
  -S "/srv/resources/Videos/Animation/死亡笔记/" \
  -d "/srv/emby/Animation/Death Note: Desu nôto (2006)/Season 01/" \
  '*.mkv' 'Death Note: Desu nôto S01E{num:02}.mkv'

-s 表示创建软链接;-S 指定源文件夹;-d 指定目标文件夹;第一个位置参数是一个 glob 通配符,用来筛选需要链接的文件;第二个位置参数是一个 Python f-string ,是创建链接名的模板。模板里的 {num:02} 会按字母表顺序被替换成从 1 开始的序号,还有一些其他的替换变量可以使用,比如从 0 开始的序号 i

希望有需求的 V 友可以尝试一下、提提意见:)

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.