-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Conversation
yutto/utils/metadata.py
Outdated
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 |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,这里用.copy进formatter处理得到一个dict吧,待会改下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 PR 稍后我接手吧,因为我那边的改动可能会影响这边,你可以专注改另一个~
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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 是不是不太合适?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的了解~那就不改了
麻烦看一下这个 PR 修改后有没有什么问题~没有的话我就 merge 啦~
yutto/utils/metadata.py
Outdated
for key, value in metadata.items(): | ||
if key in metadata_format: | ||
assert isinstance(value, int) | ||
value = get_time_str_by_stamp(value) |
There was a problem hiding this comment.
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),第二个参数才是格式..
- 默认值 `%Y-%m-%d` | ||
- 常用值 `%Y-%m-%d %H:%M:%S` | ||
- 默认值 `"%Y-%m-%d"` | ||
- 常用值 `"%Y-%m-%d %H:%M:%S"` |
There was a problem hiding this comment.
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"
但是双引号本身并不是值的一部分
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
唔,这里目前是对齐现有的文档,是用来表示 Python 里表示字面量的方法,不是用户在传入时的写法,不过你说的也有道理,也许默认值使用用户的写法是更为友好的,但整体上都需要修改了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
都ok。我是担心有用户复制的时候..多复制了引号(
动机
fixes #139
related #133
不同刮削工具可能格式要求不一致,这里先支持自定义
premiered
的格式,如果还有需要,可以再进行扩展。解决方案
修改
Metadata
的结构,通过metadata_value_format()
和自定义参数,使其在最终write_metadata
时再进行格式化输出。类型