|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# coding: utf-8 |
| 3 | + |
| 4 | +# YYeTsBot - add_dl.py |
| 5 | + |
| 6 | + |
| 7 | +import random |
| 8 | +import time |
| 9 | +from common import Mongo |
| 10 | + |
| 11 | + |
| 12 | +def prompt_default(text, default): |
| 13 | + value = input(f"{text} [{default}]: ").strip() |
| 14 | + return value if value else default |
| 15 | + |
| 16 | + |
| 17 | +def main(): |
| 18 | + mongo = Mongo() |
| 19 | + client = mongo.client["zimuzu"] |
| 20 | + col = client["yyets"] |
| 21 | + |
| 22 | + resource_id = int(input("请输入 resource id: ").strip()) |
| 23 | + |
| 24 | + doc = col.find_one({"data.info.id": resource_id}) |
| 25 | + if not doc: |
| 26 | + raise RuntimeError(f"resource id {resource_id} not found") |
| 27 | + |
| 28 | + season_num = prompt_default("请输入季", "0") |
| 29 | + video_format = prompt_default("请输入视频格式", "1080P").upper() |
| 30 | + episode = prompt_default("请输入集数", "0") |
| 31 | + |
| 32 | + size = input("请输入大小,比如 3GB / 7MB: ").strip() |
| 33 | + name = input("请输入名字: ").strip() |
| 34 | + |
| 35 | + address = "" |
| 36 | + while not address: |
| 37 | + address = input("请输入网盘地址 address: ").strip() |
| 38 | + |
| 39 | + passwd = input("请输入网盘密码 passwd,默认空: ").strip() |
| 40 | + |
| 41 | + new_item = { |
| 42 | + "itemid": str(random.randint(10_0000, 20_0000)), |
| 43 | + "episode": str(episode), |
| 44 | + "name": name, |
| 45 | + "size": size, |
| 46 | + "yyets_trans": 0, |
| 47 | + "dateline": str(int(time.time())), |
| 48 | + "files": [ |
| 49 | + { |
| 50 | + "way": "9", |
| 51 | + "way_cn": "网盘", |
| 52 | + "address": address, |
| 53 | + "passwd": passwd, |
| 54 | + } |
| 55 | + ], |
| 56 | + } |
| 57 | + |
| 58 | + target_season = None |
| 59 | + |
| 60 | + for season in doc["data"]["list"]: |
| 61 | + if str(season.get("season_num")) == str(season_num): |
| 62 | + target_season = season |
| 63 | + break |
| 64 | + |
| 65 | + # 不存在这个季就自动创建 |
| 66 | + if target_season is None: |
| 67 | + target_season = { |
| 68 | + "season_num": str(season_num), |
| 69 | + "season_cn": "正片" if str(season_num) == "0" else f"第{season_num}季", |
| 70 | + "items": {}, |
| 71 | + "formats": [], |
| 72 | + } |
| 73 | + doc["data"]["list"].append(target_season) |
| 74 | + |
| 75 | + items = target_season.setdefault("items", {}) |
| 76 | + formats = target_season.setdefault("formats", []) |
| 77 | + |
| 78 | + # 不存在这个格式就创建 |
| 79 | + if video_format not in items: |
| 80 | + items[video_format] = [] |
| 81 | + |
| 82 | + # append 新数据 |
| 83 | + items[video_format].append(new_item) |
| 84 | + |
| 85 | + # formats 顺便补一下 |
| 86 | + if video_format not in formats: |
| 87 | + formats.append(video_format) |
| 88 | + |
| 89 | + # 写回 mongodb |
| 90 | + result = col.replace_one( |
| 91 | + {"_id": doc["_id"]}, |
| 92 | + doc, |
| 93 | + ) |
| 94 | + |
| 95 | + print("\n写入成功") |
| 96 | + print("matched:", result.matched_count) |
| 97 | + print("modified:", result.modified_count) |
| 98 | + print("新增 itemid:", new_item["itemid"]) |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == "__main__": |
| 102 | + while True: |
| 103 | + main() |
0 commit comments