reformat code

This commit is contained in:
ForgQi committed 2022-07-31 23:31:12 +08:00
1 parent 7721b44748
commit 4ce2124ffe
6 files changed
+18 -35

No files matched your search

+3 -21
View File
@@ -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 (
+2 -1
View File
@@ -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
+1 -1
View File
@@ -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
+2 -3
View File
@@ -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:
+4 -5
View File
@@ -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<id>[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
+6 -4
View File
@@ -8,6 +8,7 @@ from . import logger
VALID_URL_BASE = r'https?://(?:(?:www|m)\.)?youtube\.com/(?P<id>.*?)\??(.*?)'
@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