diff --git a/differential/plugins/base.py b/differential/plugins/base.py index a9e454f..064f84c 100644 --- a/differential/plugins/base.py +++ b/differential/plugins/base.py @@ -1,19 +1,15 @@ import os -import re import sys import json -import shutil import tempfile import argparse from pathlib import Path -from decimal import Decimal from typing import Optional from urllib.parse import quote from abc import ABC, ABCMeta, abstractmethod import requests from PIL import Image -from torf import Torrent from loguru import logger from pymediainfo import MediaInfo @@ -22,12 +18,11 @@ from differential.version import version from differential.constants import ImageHosting from differential.utils.browser import open_link -from differential.utils.mediainfo import get_track_attr from differential.utils.torrent import make_torrent from differential.utils.parse import parse_encoder_log from differential.utils.uploader import EasyUpload, AutoFeed from differential.utils.binary import ffprobe, execute, execute_with_output -from differential.utils.mediainfo import get_track_attr, get_full_mediainfo, get_resolution, get_duration +from differential.utils.mediainfo import get_full_mediainfo, get_resolution, get_duration from differential.utils.image import byr_upload, ptpimg_upload, smms_upload, imgurl_upload, chevereto_api_upload, chevereto_username_upload @@ -627,16 +622,18 @@ def other_tags(self): def comparisons(self): return [] - # Auto feed @property - def uploader_auto_feed(self): - return AutoFeed(plugin=self) + def easy_upload_torrent_info(self): + return EasyUpload(plugin=self).torrent_info + + @property + def auto_feed_info(self): + return AutoFeed(plugin=self).info def upload(self): self._prepare() if self.easy_upload: - easy_upload = EasyUpload(plugin=self) - torrent_info = easy_upload.torrent_info + torrent_info = self.easy_upload_torrent_info if self.trim_description: # 直接打印简介部分来绕过浏览器的链接长度限制 torrent_info["description"] = "" @@ -647,10 +644,9 @@ def upload(self): logger.info(f"种子描述:\n{self.description}") open_link(link) elif self.auto_feed: - auto_feed = AutoFeed(plugin=self) - link = f"{self.upload_url}{quote(auto_feed.info, safe='#:/=@')}" - if self.trim_description: - logger.info(f"种子描述:\n{self.description}") + link = f"{self.upload_url}{quote(self.auto_feed_info, safe='#:/=@')}" + # if self.trim_description: + # logger.info(f"种子描述:\n{self.description}") logger.trace(f"已生成自动上传链接:{link}") open_link(link) else: diff --git a/differential/plugins/chdbits_encode.py b/differential/plugins/chdbits_encode.py index 291dec9..1b0646c 100644 --- a/differential/plugins/chdbits_encode.py +++ b/differential/plugins/chdbits_encode.py @@ -204,7 +204,7 @@ def _generate_nfo(self): f.write(self.media_info.encode()) @property - def torrent_info(self): - torrent_info = super().torrent_info + def easy_upload_torrent_info(self): + torrent_info = super().easy_upload_torrent_info torrent_info["team"] = self.team.lower() return torrent_info diff --git a/differential/plugins/gazelle.py b/differential/plugins/gazelle.py index 8129d8c..698a0fd 100644 --- a/differential/plugins/gazelle.py +++ b/differential/plugins/gazelle.py @@ -1,14 +1,6 @@ -import re -import json import argparse -from pathlib import Path -from urllib.parse import quote - -from loguru import logger from differential.plugins.base import Base -from differential.utils.browser import open_link -from differential.utils.mediainfo import get_track_attr class Gazelle(Base): diff --git a/differential/plugins/nexusphp.py b/differential/plugins/nexusphp.py index c40586d..44ec274 100644 --- a/differential/plugins/nexusphp.py +++ b/differential/plugins/nexusphp.py @@ -1,9 +1,4 @@ -import re -import json import argparse -from pathlib import Path - -from loguru import logger from differential.plugins.base import Base diff --git a/differential/plugins/unit3d.py b/differential/plugins/unit3d.py index 86ac706..034e2cd 100644 --- a/differential/plugins/unit3d.py +++ b/differential/plugins/unit3d.py @@ -1,14 +1,6 @@ -import re -import json import argparse -from pathlib import Path -from urllib.parse import quote - -from loguru import logger from differential.plugins.base import Base -from differential.utils.browser import open_link -from differential.utils.mediainfo import get_track_attr class Unit3D(Base): diff --git a/differential/torrent.py b/differential/torrent.py index c857302..664530c 100644 --- a/differential/torrent.py +++ b/differential/torrent.py @@ -1,5 +1,6 @@ from abc import abstractmethod + class TorrnetBase: @property @@ -131,4 +132,4 @@ def other_tags(self): @property @abstractmethod def comparisons(self): - raise NotImplementedError() \ No newline at end of file + raise NotImplementedError() diff --git a/differential/utils/binary.py b/differential/utils/binary.py index 3337264..9feed08 100644 --- a/differential/utils/binary.py +++ b/differential/utils/binary.py @@ -2,6 +2,7 @@ import re import sys import shutil +import platform import subprocess from pathlib import Path from typing import Optional diff --git a/differential/utils/browser.py b/differential/utils/browser.py index 491c871..758abc6 100644 --- a/differential/utils/browser.py +++ b/differential/utils/browser.py @@ -12,4 +12,4 @@ def open_link(link: str): if browser is None or isinstance(browser, webbrowser.GenericBrowser): logger.info(f"未找到浏览器,请直接复制以下链接:{link}") else: - browser.open(link, new=1) \ No newline at end of file + browser.open(link, new=1) diff --git a/differential/utils/image/byr.py b/differential/utils/image/byr.py index 3894756..86237ae 100644 --- a/differential/utils/image/byr.py +++ b/differential/utils/image/byr.py @@ -5,6 +5,7 @@ import requests from loguru import logger + def byr_upload(img: Path, authorization: str, url: Optional[str] = None) -> Optional[str]: headers = {'authorization': f'{authorization if authorization.startswith("Basic") else "Basic "+authorization}'} params = {'command': 'QuickUpload', 'type': 'Images', 'CKEditor': 'descr', 'CKEditorFuncNum': 2} diff --git a/differential/utils/image/chevereto.py b/differential/utils/image/chevereto.py index 71aaabe..5660dd3 100644 --- a/differential/utils/image/chevereto.py +++ b/differential/utils/image/chevereto.py @@ -8,6 +8,7 @@ sessions = {} + def chevereto_api_upload(img: Path, url: str, api_key: str) -> Optional[str]: data = {'key': api_key} files = {'source': open(img, 'rb')} diff --git a/differential/utils/image/smms.py b/differential/utils/image/smms.py index c1a6f7b..8629831 100644 --- a/differential/utils/image/smms.py +++ b/differential/utils/image/smms.py @@ -5,6 +5,7 @@ import requests from loguru import logger + def smms_upload(img: Path, api_key: str) -> Optional[str]: data = {'Authorization': api_key} files = {'smfile': open(img, 'rb'), 'format': 'json'} diff --git a/differential/utils/mediainfo.py b/differential/utils/mediainfo.py index c900275..4a04666 100644 --- a/differential/utils/mediainfo.py +++ b/differential/utils/mediainfo.py @@ -1,21 +1,12 @@ -import os import re -import sys -import shutil -import platform -import argparse -import subprocess -import webbrowser from pathlib import Path from decimal import Decimal from typing import Optional, List -from configparser import ConfigParser from loguru import logger from pymediainfo import Track, MediaInfo from differential.utils.binary import ffprobe -from differential.constants import ImageHosting, BOOLEAN_STATES, BOOLEAN_ARGS def get_track_attr( diff --git a/differential/utils/parse.py b/differential/utils/parse.py index 72e324d..279a3e0 100644 --- a/differential/utils/parse.py +++ b/differential/utils/parse.py @@ -1,4 +1,6 @@ import re +from pathlib import Path + def parse_encoder_log(encoder_log: str): log = "" @@ -6,21 +8,21 @@ def parse_encoder_log(encoder_log: str): with open(encoder_log, "r") as f: log = f.read() m = re.search( - r".*?(x264 \[info\]: frame I:.*?)\n" - r".*?(x264 \[info\]: frame P:.*?)\n" - r".*?(x264 \[info\]: frame B:.*?)\n" - r".*?(x264 \[info\]: consecutive B-frames:.*?)\n", + r".*?(x264 \[info]: frame I:.*?)\n" + r".*?(x264 \[info]: frame P:.*?)\n" + r".*?(x264 \[info]: frame B:.*?)\n" + r".*?(x264 \[info]: consecutive B-frames:.*?)\n", log, ) if m: return "\n".join(m.groups()) m = re.search( - r".*?(x265 \[info\]: frame I:.*?)\n" - r".*?(x265 \[info\]: frame P:.*?)\n" - r".*?(x265 \[info\]: frame B:.*?)\n" - r".*?(x265 \[info\]: Weighted P\-Frames:.*?)\n" - r".*?(x265 \[info\]: Weighted B\-Frames:.*?)\n" - r".*?(x265 \[info\]: consecutive B\-frames:.*?)\n", + r".*?(x265 \[info]: frame I:.*?)\n" + r".*?(x265 \[info]: frame P:.*?)\n" + r".*?(x265 \[info]: frame B:.*?)\n" + r".*?(x265 \[info]: Weighted P-Frames:.*?)\n" + r".*?(x265 \[info]: Weighted B-Frames:.*?)\n" + r".*?(x265 \[info]: consecutive B-frames:.*?)\n", log, ) if m: diff --git a/differential/utils/torrent.py b/differential/utils/torrent.py index ca4ec97..5963463 100644 --- a/differential/utils/torrent.py +++ b/differential/utils/torrent.py @@ -10,6 +10,7 @@ def make_torrent_progress(torrent, filepath, pieces_done, pieces_total): logger.info(f'制种进度: {pieces_done/pieces_total*100:3.0f} %') + def make_torrent(path: Path, trackers: List[str]): logger.info("正在生成种子...") t = Torrent(path=path, trackers=trackers, diff --git a/differential/utils/uploader/__init__.py b/differential/utils/uploader/__init__.py index 3ac4661..e810fd6 100644 --- a/differential/utils/uploader/__init__.py +++ b/differential/utils/uploader/__init__.py @@ -1,2 +1,2 @@ from differential.utils.uploader.easy_upload import EasyUpload -from differential.utils.uploader.auto_feed import AutoFeed \ No newline at end of file +from differential.utils.uploader.auto_feed import AutoFeed