Move plugins

This commit is contained in:
ForgQi committed 2021-04-20 16:09:04 +08:00
1 parent 23230d6479
commit c18d409d76
22 files changed
+94 -88

No files matched your search

+40 -22
View File
@@ -1,25 +1,43 @@
import asyncio
import platform
import sys
from .engine import main
from .common.Daemon import Daemon
from .common.reload import AutoReload
from .common.timer import Timer
from .engine.event import EventManager, Event
from .engine import config, invert_dict, Plugin
from . import plugins
def _main():
daemon = Daemon('watch_process.pid')
if platform.system() != 'Windows' and len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print('unknown command')
sys.exit(2)
sys.exit(0)
elif platform.system() == 'Windows' or len(sys.argv) == 1:
asyncio.run(main())
else:
print('usage: %s start|stop|restart' % sys.argv[0])
sys.exit(2)
def create_event_manager():
streamer_url = {k: v['url'] for k, v in config['streamers'].items()}
inverted_index = invert_dict(streamer_url)
urls = list(inverted_index.keys())
# 初始化事件管理器
app = EventManager(config)
app.context['urls'] = urls
app.context['url_status'] = dict.fromkeys(inverted_index, 0)
app.context['checker'] = Plugin(plugins).sorted_checker(urls)
app.context['inverted_index'] = inverted_index
app.context['streamer_url'] = streamer_url
return app
event_manager = create_event_manager()
async def main():
from .handler import CHECK_UPLOAD, CHECK
event_manager.start()
async def check_timer():
event_manager.send_event(Event(CHECK_UPLOAD))
for k in event_manager.context['checker'].keys():
event_manager.send_event(Event(CHECK, (k,)))
# 初始化定时器
timer = Timer(func=check_timer, interval=40)
# 模块更新自动重启
detector = AutoReload(event_manager, timer, interval=15)
await asyncio.gather(detector.astart(), timer.astart(), return_exceptions=True)
+26 -1
View File
@@ -1,6 +1,31 @@
#!/usr/bin/python3
# coding:utf8
from . import _main
import platform
import sys
import asyncio
from .common.Daemon import Daemon
from . import main
def _main():
daemon = Daemon('watch_process.pid', main)
if platform.system() != 'Windows' and len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print('unknown command')
sys.exit(2)
sys.exit(0)
elif platform.system() == 'Windows' or len(sys.argv) == 1:
asyncio.run(main())
else:
print('usage: %s start|stop|restart' % sys.argv[0])
sys.exit(2)
if __name__ == '__main__':
+4 -5
View File
@@ -5,20 +5,20 @@ import sys
import os
import time
import atexit
from ..engine import main
logger = logging.getLogger('log01')
# python模拟linux的守护进程
class Daemon(object):
def __init__(self, pidfile, change_currentdirectory=False, stdin='/dev/null', stdout='/dev/null',
def __init__(self, pidfile, fn, change_currentdirectory=False, stdin='/dev/null', stdout='/dev/null',
stderr='/dev/null'):
# 需要获取调试信息,改为stdin='/dev/stdin', stdout='/dev/stdout', stderr='/dev/stderr',以root身份运行。
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile
self.fn = fn
self.cd = change_currentdirectory
def _daemonize(self):
@@ -119,7 +119,6 @@ class Daemon(object):
self.stop()
self.start()
@staticmethod
def _run():
def _run(self):
""" run your fun"""
asyncio.run(main())
asyncio.run(self.fn())
@@ -3,7 +3,7 @@ import re
import time
from urllib.error import HTTPError
from ..common.decorators import Plugin
from .engine.decorators import Plugin
from .plugins import general, BatchCheckBase
logger = logging.getLogger('log01')
+2 -35
View File
@@ -1,11 +1,5 @@
import asyncio
import yaml
from ..common.decorators import Plugin
from ..common.event import Event, event_manager
from ..common.reload import AutoReload
from ..common.timer import Timer
from .decorators import Plugin
with open(r'config.yaml', encoding='utf-8') as stream:
config = yaml.load(stream, Loader=yaml.FullLoader)
@@ -19,31 +13,4 @@ def invert_dict(d: dict):
return inverse_dict
async def main():
from . import plugins
streamers = config['streamers']
streamer_url = {k: v['url'] for k, v in streamers.items()}
inverted_index = invert_dict(streamer_url)
urls = list(inverted_index.keys())
url_status = dict.fromkeys(inverted_index, 0)
checker = Plugin(plugins).sorted_checker(urls)
# 初始化事件管理器
event_manager.context = {**config, 'urls': urls, 'url_status': url_status,
'checker': checker, 'inverted_index': inverted_index, 'streamer_url': streamer_url}
from ..engine.handler import CHECK_UPLOAD, CHECK
event_manager.start()
async def check_timer():
event_manager.send_event(Event(CHECK_UPLOAD))
for k in checker.keys():
event_manager.send_event(Event(CHECK, (k,)))
# 初始化定时器
timer = Timer(func=check_timer, interval=40)
# 模块更新自动重启
detector = AutoReload(event_manager, timer, interval=15)
await asyncio.gather(detector.astart(), timer.astart(), return_exceptions=True)
__all__ = ['downloader', 'uploader', 'plugins', 'main']
__all__ = ['config', 'invert_dict', 'Plugin']
@@ -40,7 +40,7 @@ class Plugin:
@classmethod
def sorted_checker(cls, urls):
from ..engine.plugins import general
from ..plugins import general
curls = urls.copy()
checker_plugins = {}
for plugin in cls.download_plugins:
@@ -162,6 +162,3 @@ class Event:
type_: str # 事件类型
args: tuple = ()
dict: dict = field(default_factory=dict) # 字典用于保存具体的事件数据
event_manager = EventManager()
@@ -1,7 +1,7 @@
# import common
from .. import common
from ..common import logger
from ..common.event import Event, event_manager
from . import common
from biliup import event_manager
from .common import logger
from .engine.event import Event
from .downloader import download, check_url
from .plugins.upload import UploadBase
from .uploader import upload
File renamed without changes.
@@ -1,6 +1,6 @@
import requests
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from ..plugins import match1, logger
from .general import DownloadBase
@@ -1,6 +1,6 @@
from ykdl.common import url_to_module
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from .general import DownloadBase
@@ -3,7 +3,7 @@ import re
import requests
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from . import logger, fake_headers
from .general import DownloadBase
@@ -3,7 +3,7 @@ import platform
from ykdl.common import url_to_module
from ykdl.util.jsengine import chakra_available, quickjs_available, external_interpreter
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from ..plugins import logger
from .general import DownloadBase
@@ -8,8 +8,8 @@ import streamlink
import youtube_dl
from ykdl.common import url_to_module
from .. import config
from ..plugins import logger, fake_headers
from ..engine import config
from . import logger, fake_headers
class DownloadBase:
@@ -4,7 +4,7 @@ import json
import requests
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from ..plugins import match1, logger, fake_headers
from .general import DownloadBase
@@ -3,7 +3,7 @@ from urllib.parse import urlencode
import requests
from ...common.decorators import Plugin
from ..engine.decorators import Plugin
from ..plugins import BatchCheckBase, match1
from .general import DownloadBase
File renamed without changes.
@@ -9,8 +9,8 @@ from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from ... import config
from ....common.decorators import Plugin
from ...engine import config
from ...engine.decorators import Plugin
from ..upload import UploadBase, logger
from .slider import slider_cracker
@@ -19,8 +19,8 @@ import rsa
from requests import utils
from requests.adapters import HTTPAdapter, Retry
from ... import config
from ....common.decorators import Plugin
from ...engine import config
from ...engine.decorators import Plugin
from ..upload import UploadBase, logger
@@ -1,8 +1,8 @@
import inspect
from .. import engine
from ..common import logger
from ..common.decorators import Plugin
from biliup import engine
from .common import logger
from .engine.decorators import Plugin
def upload(platform, index, data):
+1 -1
View File
@@ -32,4 +32,4 @@ include = biliup*
[options.entry_points]
console_scripts =
biliup = biliup:_main
biliup = biliup.__main__:_main