Skip to content

Commit

Permalink
由于lib目录名称为特殊保留目录, 所以所有工具和依赖类方法移植到了utils包里.
Browse files Browse the repository at this point in the history
Signed-off-by: Sadam·Sadik <1903249375@qq.com>
  • Loading branch information
Haoke98 committed Apr 7, 2024
1 parent 4757a7d commit 4f3f72e
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion accountSystem/admin/tel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from simplepro.admin import LIST_DISPLAY

from lib.phoneNumHelper import get_carrier
from utils.phoneNumHelper import get_carrier
from ..models import Tel


Expand Down
2 changes: 1 addition & 1 deletion accountSystem/models/human.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from simplepro.lib import pkHelper
from simplepro.models import BaseModel

from lib import zodiacHelper
from utils import zodiacHelper
from .weibo import Weibo


Expand Down
2 changes: 1 addition & 1 deletion accountSystem/models/weibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from simplepro.models import BaseModel

from proj.settings import MEDIA_ROOT
from lib import weiboHelper
from utils import weiboHelper


# Create your models here.
Expand Down
12 changes: 6 additions & 6 deletions icloud/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from simplepro.dialog import MultipleCellDialog, ModalDialog
from simpleui.admin import AjaxAdmin

from lib import human_readable_bytes, human_readable_time, icloud
from utils import human_readable_bytes, human_readable_time, icloud
from .models import IMedia, Album, LocalMedia, AppleId
from .services import collect_all_medias, delete_from_icloud, migrateIcloudToLocal
from .views import DLT
Expand Down Expand Up @@ -905,11 +905,11 @@ def formatter(self, obj, field_name, value):
return f"""<span title="{value}">{human_readable_bytes(value)}</span>"""
if field_name == 'thumb':
if value:
STORAGE_END_POINT = get_setting("MINIO_STORAGE_ENDPOINT")
BUCKET_NAME = get_setting("MINIO_STORAGE_MEDIA_BUCKET_NAME")
final_url = "http://" + STORAGE_END_POINT + '/' + BUCKET_NAME + '/' + value
print(STORAGE_END_POINT, print(final_url))
return f"""<img src="{final_url}" style="height:100px;">"""
# STORAGE_END_POINT = get_setting("MINIO_STORAGE_ENDPOINT")
# BUCKET_NAME = get_setting("MINIO_STORAGE_MEDIA_BUCKET_NAME")
final_url = "/media/" + value
# print(STORAGE_END_POINT, print(final_url))
return f"""<el-image src="{final_url}" style="height:100px;" :preview-src-list="['{final_url}']" lazy >"""
if field_name == "duration":
if value:
return f"""<span title="{value}">{human_readable_time(value)}</span>"""
Expand Down
2 changes: 1 addition & 1 deletion icloud/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from moviepy.video.io.VideoFileClip import VideoFileClip
from pyicloud.services.photos import PhotoAsset

from lib.icloud import IcloudService
from utils.icloud import IcloudService
from .models import IMedia, LocalMedia, AppleId

CHUNK_SIZE = 1024 * 1024 # 每个文件块的大小(字节)1M
Expand Down
36 changes: 0 additions & 36 deletions lib/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion logAnalyser/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib import admin
from simplepro.decorators import button

from lib import human_readable_bytes
from utils import human_readable_bytes
from .models import NginxLog


Expand Down
28 changes: 28 additions & 0 deletions utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,31 @@
@Software: PyCharm
@disc:
======================================="""
import decimal
import math


def human_readable_bytes(num_bytes):
if num_bytes == 0:
return "0B"
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(num_bytes, 1024)))
p = math.pow(1024, i)
p_decimal = decimal.Decimal(p)
s = round(num_bytes / p_decimal, 2)
return "%s %s" % (s, size_name[i])


def human_readable_time(milliseconds):
seconds = milliseconds // 1000
minutes = seconds // 60
hours = minutes // 60

if hours > 0:
return f"{hours}小时 {minutes % 60}分钟 {seconds % 60}{milliseconds % 1000}毫秒"
elif minutes > 0:
return f"{minutes}分钟 {seconds % 60}{milliseconds % 1000}毫秒"
elif seconds > 0:
return f"{seconds}{milliseconds % 1000}毫秒"
else:
return f"{milliseconds}毫秒"
30 changes: 28 additions & 2 deletions lib/icloud.py → utils/icloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from urllib.parse import urlencode

from pyicloud import PyiCloudService as __iCloudService__
from pyicloud.exceptions import PyiCloudAPIResponseException, PyiCloudFailedLoginException
from pyicloud.services.photos import PhotoAsset, PhotosService

from lib import jpeg
from utils import jpeg


class IPhoto(PhotoAsset):
Expand All @@ -43,6 +44,30 @@ def __init__(self, apple_id,
self.SETUP_ENDPOINT = "https://setup.icloud.com.cn/setup/ws/1"
super().__init__(apple_id, password, cookie_directory, verify, client_id, with_family)

def _authenticate_with_token(self):
"""Authenticate using session token."""
data = {
"apple_id": self.user.get("accountName"),
"password": self.user.get("password"),
"accountCountryCode": self.session_data.get("account_country"),
"dsWebAuthToken": self.session_data.get("session_token"),
"extended_login": True,
"trustToken": self.session_data.get("trust_token", ""),
}

try:
req = self.session.post(
"%s/accountLogin" % self.SETUP_ENDPOINT, data=json.dumps(data)
)
self.data = req.json()
print("登陆结果:", self.data)
except PyiCloudAPIResponseException as error:
msg = "Invalid authentication token."
print("[登陆]有可能是密码错误:", msg)
raise PyiCloudFailedLoginException(msg, error) from error
except Exception as e:
print("[登陆]未知异常发生:", e)

def handle(self, outputDir: str, recent: int, photo: PhotoAsset, modify_olds: bool, auto_delete: bool):

def __modify_create_date__():
Expand Down Expand Up @@ -106,7 +131,8 @@ def download_photo(self, outputDir: str = "./Photos", transfer_album: str = None
modify_olds: bool = False, max_thread_count: int = 3):
def handle(album, recent):
_all = album.photos
logging.info(f"相册[{album.name}]里总共有{len(album)}个媒体对象(包括视频,短视频,Live实况图,动图,JPG,JPEG,PNG...etc.)")
logging.info(
f"相册[{album.name}]里总共有{len(album)}个媒体对象(包括视频,短视频,Live实况图,动图,JPG,JPEG,PNG...etc.)")
if recent is None:
recent = len(album)
if max_thread_count == 1:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4f3f72e

Please sign in to comment.