def update_pic(pic_abs_path, exif_meta): tmp_abs_path = "%s.tmp" % pic_abs_path with open(pic_abs_path, "rb") as rp: with open(tmp_abs_path, "wb") as wp: exif.copy_on_write(rp, wp, exif_meta) os.remove(pic_abs_path) os.renames(tmp_abs_path, pic_abs_path)
if "HD video".lower() not in tp.lower(): continue parse_r = urlparse(pic_url) pic_type = parse_r.path[parse_r.path.rfind(".")+1:] ntime = datetime.strptime(time, "%b %d, %Y").strftime("%Y%m%d") pic_name = "%s - %s.%s" % (ntime, name, pic_type) pic_abs_path = os.path.join(conf.pic_root, pic_name) if not os.path.exists(pic_abs_path) or os.path.getsize(pic_abs_path) == 0: print(detail_url) detail_page = crawl(detail_url, "utf-8") m = re.search(regexs.rate, detail_page) rate = m.group(1) if m else None m = re.search(regexs.model_list, detail_page) model_list = m.group(1) if m else None if model_list: m = re.findall(regexs.model, model_list) models = ", ".join(m) if m else None else: models = None m = re.search(regexs.comment, detail_page) comment = _seek_comment(detail_page) print("saving pic: %s location: %s" % (pic_url, pic_name)) print("\tmodels:%s comment:%s rate:%s" % (models, comment, rate)) add_cnt += 1 img_data = crawl(pic_url) with open(pic_abs_path, "wb") as wp: exif.copy_on_write(io.BytesIO(img_data), wp, {"model":models, "rate":rate, "desc":comment}) if add_cnt == 0: print("first item is %s" % first_item) print("total add %d" % add_cnt)