diff --git a/biliup/common/reload.py b/biliup/common/reload.py index 6dd8b2e..db490e1 100644 --- a/biliup/common/reload.py +++ b/biliup/common/reload.py @@ -1,15 +1,13 @@ import asyncio +import logging +import subprocess import sys import os -import subprocess -import logging - from .timer import Timer logger = logging.getLogger('biliup') global global_reloader -global program_args def has_extension(fname_list, *extension): @@ -87,26 +85,10 @@ class AutoReload(Timer): # else: # args = [path, 'start'] if not is_docker(): - args = unparser_args(program_args) - subprocess.Popen(args) + subprocess.Popen(sys.argv) return logger.info('重启') -def unparser_args(args): - s = ['biliup', 'start'] - for i, j in args.items(): - if i == 'start': - continue - elif type(j) == str or type(j) == int: - s.append(f'--{i}={j}') - elif type(j) == bool: - s.append(f'--{i}') - return s - - -import os - - def is_docker(): path = '/proc/self/cgroup' return ( diff --git a/biliup/plugins/afreecaTV.py b/biliup/plugins/afreecaTV.py index 524502c..9480971 100644 --- a/biliup/plugins/afreecaTV.py +++ b/biliup/plugins/afreecaTV.py @@ -20,7 +20,8 @@ class AfreecaTV(DownloadBase): def check_stream(self): logger.debug(self.fname) username = match1(self.url, VALID_URL_BASE) - res_bno = requests.post(CHANNEL_API_URL + "?bjid=" + username,data={"bid": username, "mode": "landing", "player_type": "html5"},timeout=5) + res_bno = requests.post(CHANNEL_API_URL + "?bjid=" + username, + data={"bid": username, "mode": "landing", "player_type": "html5"}, timeout=5) res_bno.close() if res_bno.json()["CHANNEL"]["RESULT"] == 0: return diff --git a/biliup/plugins/douyu.py b/biliup/plugins/douyu.py index 06e9b8f..83ef914 100644 --- a/biliup/plugins/douyu.py +++ b/biliup/plugins/douyu.py @@ -1,7 +1,6 @@ from urllib.parse import urlencode from collections import namedtuple import requests -from ykdl.extractors.douyu.util import ub98484234 from ykdl.util.http import get_content, get_response from ykdl.util.match import match1 @@ -18,6 +17,7 @@ class Douyu(DownloadBase): def check_stream(self): logger.debug(self.fname) + from ykdl.extractors.douyu.util import ub98484234 if len(self.url.split("douyu.com/")) < 2: logger.debug("直播间地址:" + self.url + " 错误") return False diff --git a/biliup/plugins/general.py b/biliup/plugins/general.py index 49d54cf..1dd6c52 100644 --- a/biliup/plugins/general.py +++ b/biliup/plugins/general.py @@ -1,8 +1,6 @@ from threading import Event - -import streamlink -import yt_dlp from ykdl.common import url_to_module +import yt_dlp from ..engine.download import DownloadBase from . import logger @@ -52,6 +50,7 @@ class SDownload(DownloadBase): def check_stream(self): logger.debug(self.fname) + import streamlink try: streams = streamlink.streams(self.url) if streams: diff --git a/biliup/plugins/twitch.py b/biliup/plugins/twitch.py index 930f982..199352b 100644 --- a/biliup/plugins/twitch.py +++ b/biliup/plugins/twitch.py @@ -1,15 +1,14 @@ import random import subprocess import time -from urllib.parse import urlencode import requests import yt_dlp -from ..engine.decorators import Plugin -from ..plugins import BatchCheckBase, match1 -from ..engine.download import DownloadBase from . import logger +from ..engine.decorators import Plugin +from ..engine.download import DownloadBase +from ..plugins import BatchCheckBase VALID_URL_BASE = r'(?:https?://)?(?:(?:www|go|m)\.)?twitch\.tv/(?P[0-9_a-zA-Z]+)' _OPERATION_HASHES = { @@ -99,7 +98,7 @@ class Twitch(DownloadBase): self.proc = subprocess.Popen([ "streamlink", "--player-external-http", "--twitch-disable-ads", "--twitch-disable-hosting", "--twitch-disable-reruns", - "--player-external-http-port", str(port),self.url, "best" + "--player-external-http-port", str(port), self.url, "best" ]) self.raw_stream_url = f"http://localhost:{port}" i = 0 diff --git a/biliup/plugins/youtube.py b/biliup/plugins/youtube.py index 65f7190..d975ad2 100644 --- a/biliup/plugins/youtube.py +++ b/biliup/plugins/youtube.py @@ -8,6 +8,7 @@ from . import logger VALID_URL_BASE = r'https?://(?:(?:www|m)\.)?youtube\.com/(?P.*?)\??(.*?)' + @Plugin.download(regexp=VALID_URL_BASE) class Youtube(DownloadBase): def __init__(self, fname, url, suffix='webm'): @@ -15,7 +16,8 @@ class Youtube(DownloadBase): self.cookiejarFile = config.get('youtube_cookie') def check_stream(self): - with yt_dlp.YoutubeDL({'download_archive': 'archive.txt', 'ignoreerrors': True, 'extract_flat': True, 'cookiefile': self.cookiejarFile}) as ydl: + with yt_dlp.YoutubeDL({'download_archive': 'archive.txt', 'ignoreerrors': True, 'extract_flat': True, + 'cookiefile': self.cookiejarFile}) as ydl: info = ydl.extract_info(self.url, download=False, process=False) if info is None: logger.warning(self.cookiejarFile) @@ -38,7 +40,7 @@ class Youtube(DownloadBase): return True for entry in info['entries']: # 取 Playlist 内视频标题 - # self.title = entry['title'] + # self.room_title = entry['title'] if ydl.in_download_archive(entry): continue # ydl.record_download_archive() @@ -46,7 +48,7 @@ class Youtube(DownloadBase): def download(self, filename): try: - self.ydl_opts = { + ydl_opts = { 'outtmpl': filename, 'cookiefile': self.cookiejarFile, # 'proxy': proxyUrl, @@ -54,7 +56,7 @@ class Youtube(DownloadBase): 'max_downloads': 1, 'download_archive': 'archive.txt' } - with yt_dlp.YoutubeDL(self.ydl_opts) as ydl: + with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([self.url]) except MaxDownloadsReached: return False