-
-
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: 批量支持按照稿件发布时间过滤 #146
Conversation
yutto/api/ugc_video.py
Outdated
@@ -123,15 +123,15 @@ async def get_ugc_video_info(session: ClientSession, avid: AvId) -> _UgcVideoInf | |||
} | |||
|
|||
|
|||
async def get_ugc_video_list(session: ClientSession, avid: AvId) -> UgcVideoList: | |||
async def get_ugc_video_list(session: ClientSession, avid: AvId, pubdata_fmt: str = "%Y-%m-%d") -> UgcVideoList: |
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.
async def get_ugc_video_list(session: ClientSession, avid: AvId, pubdata_fmt: str = "%Y-%m-%d") -> UgcVideoList: | |
async def get_ugc_video_list(session: ClientSession, avid: AvId, pubdate_fmt: str = "%Y-%m-%d") -> UgcVideoList: |
- 参数 `--batch-filter-start-time` 和 `--batch-filter-end-time` 分别表示`开始`和`结束`时间,该区间左右都是闭区间 | ||
- 默认 `不限制` | ||
- 格式 `%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.
这里给出一个示例吧~
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,我来处理
yutto/__main__.py
Outdated
@@ -110,6 +110,9 @@ def cli() -> argparse.ArgumentParser: | |||
"-af", "--alias-file", type=argparse.FileType("r", encoding="utf-8"), help="设置 url 别名文件路径" | |||
) | |||
|
|||
group_common.add_argument("--batch-filter-start-time", help="批量下载时,只下载该时间之后发布的稿件") |
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.
仅批量下载使用的话,应该加在 group_batch
里?
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.
咦我看下,没太注意这个参数分组
yutto/utils/filter.py
Outdated
Filter.batch_filter_start_time | ||
<= datetime.datetime.strptime(datestr, "%Y-%m-%d %H:%M:%S") | ||
<= Filter.batch_filter_end_time | ||
) |
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.
if start is None:
start = datetime.datetime.min
if end is None:
end = datetime.datetime.max
return start <= datetime.datetime.strptime(datestr, "%Y-%m-%d %H:%M:%S") <= end
这样是不是会简单些?
yutto/api/ugc_video.py
Outdated
video_info = await get_ugc_video_info(session, avid) | ||
if avid not in [video_info["aid"], video_info["bvid"]]: | ||
avid = video_info["avid"] | ||
video_title = video_info["title"] | ||
result: UgcVideoList = { | ||
"title": video_title, | ||
"avid": avid, | ||
"pubdate": get_time_str_by_stamp(video_info["pubdate"], "%Y-%m-%d"), # TODO: 可自由定制 | ||
"pubdate": get_time_str_by_stamp(video_info["pubdate"], pubdata_fmt), |
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.
唔,我觉得在这里格式化是不是不太合适,我们这里返回时间戳吧,在 resolve_path_template
处格式化
然后格式化时候支持如下语法 "{pubdate@%Y-%m-%d}"
,以允许用户自由定制
这个我稍后提一个 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.
好,那这个你来处理~
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.
只是一点点格式上的建议~
Co-authored-by: Nyakku Shigure <[email protected]>
Co-authored-by: Nyakku Shigure <[email protected]>
默认值看来没法用:
|
动机
related #133
解决方案
提供了
--batch-filter-start-time
和--batch-filter-end-time
,定义了一个时间过滤闭区间,并在utils
定义了一个filter
作为全局静态变量,在批量ugc视频信息获取时根据该区间过滤。类型