Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: 元数据支持指定premiered的格式 #145

Merged
merged 7 commits into from
Jun 10, 2023

Conversation

lc4t
Copy link
Contributor

@lc4t lc4t commented Jun 8, 2023

动机

fixes #139
related #133

不同刮削工具可能格式要求不一致,这里先支持自定义premiered的格式,如果还有需要,可以再进行扩展。

解决方案

修改Metadata的结构,通过metadata_value_format()和自定义参数,使其在最终write_metadata时再进行格式化输出。

类型

  • ✨ feat: 添加新功能
  • 🐛 fix: 修复 bug
  • 📝 docs: 对文档进行修改
  • ♻️ refactor: 代码重构(既不是新增功能,也不是修改 bug 的代码变动)
  • ⚡ perf: 提高性能的代码修改
  • 🧑‍💻 dx: 优化开发体验
  • 🔨 workflow: 工作流变动
  • 🏷️ types: 类型声明修改
  • 🚧 wip: 工作正在进行中
  • ✅ test: 测试用例添加及修改
  • 🔨 build: 影响构建系统或外部依赖关系的更改
  • 👷 ci: 更改 CI 配置文件和脚本
  • ❓ chore: 其它不涉及源码以及测试的修改
  • ⬆️ deps: 依赖项修改
  • 🔖 release: 发布新版本

for key, fmt in metadata_format.items():
if fmt and key in metadata:
if isinstance(metadata[key], (time.struct_time)): # TODO: datetime.datetime
metadata[key]: str = time.strftime(fmt, metadata[key]) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的类型提示写法是不合法的,这里直接创建一个 copy 吧,不要 set 回原来的 dict 了,返回 dict[str, Any]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,这里用.copy进formatter处理得到一个dict吧,待会改下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 PR 稍后我接手吧,因为我那边的改动可能会影响这边,你可以专注改另一个~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


当前仅支持`premiered`

- 参数 `--metadata-format-premiered`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lc4t 我这边不太了解 metadata 相关的,请问我直接改成 --metadata-date-format 是否合适呢?因为还有一个 dateadded 字段,只为其中一个添加 format 是不是不太合适?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lc4t 我这边不太了解 metadata 相关的,请问我直接改成 --metadata-date-format 是否合适呢?因为还有一个 dateadded 字段,只为其中一个添加 format 是不是不太合适?

目前争议在于premiered,是因为不同APP中识别premiered的格式不同,至于dateadded,这个字段的含义是添加日期,不太确定是否会遇到争议(现在没遇到);
更稳妥的做法是整个metadata格式都开放自定义,例如--metadata-{field}-format={formatter}这样子;
另外未来可能遇到需要添加metadata自定义字段,比如用户需要手动添加一个tag=bilibili

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的了解~那就不改了

麻烦看一下这个 PR 修改后有没有什么问题~没有的话我就 merge 啦~

for key, value in metadata.items():
if key in metadata_format:
assert isinstance(value, int)
value = get_time_str_by_stamp(value)
Copy link
Contributor Author

@lc4t lc4t Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯..这里应该是value = get_time_str_by_stamp(value, metadata_format[key])吧,因为此时value是元数据(int),第二个参数才是格式..

yutto/utils/metadata.py Outdated Show resolved Hide resolved
- 默认值 `%Y-%m-%d`
- 常用值 `%Y-%m-%d %H:%M:%S`
- 默认值 `"%Y-%m-%d"`
- 常用值 `"%Y-%m-%d %H:%M:%S"`
Copy link
Contributor Author

@lc4t lc4t Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

奇怪..为什么要带上引号.. 虽然用户输入确实一般是--metadata-format-premiered="%Y-%m-%d %H:%M:%S"但是双引号本身并不是值的一部分

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

唔,这里目前是对齐现有的文档,是用来表示 Python 里表示字面量的方法,不是用户在传入时的写法,不过你说的也有道理,也许默认值使用用户的写法是更为友好的,但整体上都需要修改了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都ok。我是担心有用户复制的时候..多复制了引号(

@SigureMo SigureMo merged commit b5ff4b6 into yutto-dev:main Jun 10, 2023
@lc4t lc4t deleted the nfo_format branch June 10, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 元数据时间精度
2 participants