我一直在寻找在iTunes上的m4a文件上编辑标签的方法,后来遇到un-istore,它提供了另一种编辑标签的方法。
源代码:
# Get user name and ID from command line
export SEEK_FOR_USERNAME=${1:-iTunes Store}
export SEEK_FOR_USERID=${2:-iTunes Store}
# Define new anonymous user names with the length of original user names
NEW_USERNAME="iTunes Store"
NEW_USERNAME=`printf "$NEW_USERNAME%${#SEEK_FOR_USERNAME}s"`
export NEW_USERNAME=${NEW_USERNAME:0:${#SEEK_FOR_USERNAME}}
NEW_USERID="iTunes Store"
NEW_USERID=`printf "$NEW_USERID%${#SEEK_FOR_USERID}s"`
export NEW_USERID=${NEW_USERID:0:${#SEEK_FOR_USERID}}
# Just show what is going to happen
echo "old: “$SEEK_FOR_USERNAME” • “$SEEK_FOR_USERID”
new: “$NEW_USERNAME” • “$NEW_USERID”" >&2
# Operate in binary mode so avoid Unicode interference, and increase speed
export LC_COLLATE=C
export LC_ALL=C
export LANG=C
# Do it, recursively...
find . -name "*m4a" | sort | while read f; do
if grep -m 1 -q "${SEEK_FOR_USERNAME}" "$f"; then
echo "Processing «$f»"
perl -mEnv=SEEK_FOR_USERNAME,NEW_USERNAME,SEEK_FOR_USERID,NEW_USERID -i -e '
undef $/;
$_=<>;
# User ID
s/user.{4}(.{4})cert/user\xFF\xFF\xFF\xFF$1cert/s;
# User Name in 2 instances
s/name$SEEK_FOR_USERNAME/name$NEW_USERNAME/;
s/ownr(.{4})data(.{8})$SEEK_FOR_USERNAME/ownr$1data$2$NEW_USERNAME/s;
# Apple Store Account
s/apID(.{4})data(.{8})$SEEK_FOR_USERID/apID$1data$2$NEW_USERID/s;
# Transaction ID
s/tran.{4}(sing|song)/tran\xFF\xFF\xFF\xFF$1/s;
# Item ID
# This doesnt need removal, its not personal info
# s/song.{4}tool/song\xFF\xFF\xFF\xFFtool/s;
# Apple Store Catalog ID
# Not sure if this needs removal
# s/cnID(.{4})data(.{8}).{4}/cnID$1data$2\xFF\xFF\xFF\xFF/s;
print;
' "$f"
else
echo "Skipping «$f»"
fi
done
TL; DR它基本上使用perl regex替换“不可编辑的”标记值(用户名,appleID等)。因此,替换的值不能大于原始值,这是我计划以某种方式克服的该脚本的唯一限制。
虽然我不确定文件的编辑方式,但我确实尝试过 为更长的用户名使用以下类似内容
s/name$SEEK_FOR_USERNAME(.*)/name$NEW_USERNAME$1/;
希望保留“字节”,但这只是使文件“砖化”。
那么关于如何修改和覆盖“字节”的任何想法?