Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiShi1313 committed Nov 18, 2021
1 parent e98f647 commit 2b02003
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 61 deletions.
28 changes: 12 additions & 16 deletions differential/plugins/base.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
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

from differential.torrent import TorrnetBase
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.binary import ffprobe, execute
from differential.utils.binary import execute
from differential.utils.uploader import EasyUpload, AutoFeed
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


Expand Down Expand Up @@ -588,16 +583,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"] = ""
Expand All @@ -608,10 +605,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:
Expand Down
4 changes: 2 additions & 2 deletions differential/plugins/chdbits_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions differential/plugins/gazelle.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
5 changes: 0 additions & 5 deletions differential/plugins/nexusphp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import re
import json
import argparse
from pathlib import Path

from loguru import logger

from differential.plugins.base import Base

Expand Down
8 changes: 0 additions & 8 deletions differential/plugins/unit3d.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion differential/torrent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import abstractmethod


class TorrnetBase:

@property
Expand Down Expand Up @@ -131,4 +132,4 @@ def other_tags(self):
@property
@abstractmethod
def comparisons(self):
raise NotImplementedError()
raise NotImplementedError()
1 change: 1 addition & 0 deletions differential/utils/binary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import sys
import shutil
import subprocess
Expand Down
2 changes: 1 addition & 1 deletion differential/utils/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
browser.open(link, new=1)
1 change: 1 addition & 0 deletions differential/utils/image/byr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions differential/utils/image/chevereto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
1 change: 1 addition & 0 deletions differential/utils/image/smms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
9 changes: 0 additions & 9 deletions differential/utils/mediainfo.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
22 changes: 12 additions & 10 deletions differential/utils/parse.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import re
from pathlib import Path


def parse_encoder_log(encoder_log: str):
log = ""
if encoder_log and Path(encoder_log).is_file():
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:
Expand Down
1 change: 1 addition & 0 deletions differential/utils/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion differential/utils/uploader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from differential.utils.uploader.easy_upload import EasyUpload
from differential.utils.uploader.auto_feed import AutoFeed
from differential.utils.uploader.auto_feed import AutoFeed

0 comments on commit 2b02003

Please sign in to comment.