From 63a7662be40e38ab8ab7fb64a3d4841c9ff96910 Mon Sep 17 00:00:00 2001 From: "gr.zhu" <55681140@163.com> Date: Sun, 25 Jul 2021 11:02:05 +0800 Subject: [PATCH] =?UTF-8?q?Q:=20Hello,=20developers,=20I=20have=20encounte?= =?UTF-8?q?red=20a=20problem,=20I=20need=20use=20you-get=20three=20times?= =?UTF-8?q?=20to=20obtain=20the=20data.=20However,=20problems=20were=20fou?= =?UTF-8?q?nd=20in=20the=20following=20code.=20After=20performing=20getjso?= =?UTF-8?q?n=20and=20getDefaultDownloadInfo,=20execute=20Download,=20with?= =?UTF-8?q?=20redirect=20output,=20the=20text=20exception=20is=20obtained,?= =?UTF-8?q?=20and=20the=20download=20video=20will=20be=20invalid.=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9A=E4=BD=A0=E5=A5=BD=EF=BC=8C=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=80=85=EF=BC=8C=E6=88=91=E9=81=87=E5=88=B0=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E9=97=AE=E9=A2=98=EF=BC=8C=E6=88=91=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=80=9A=E8=BF=87=E4=B8=89=E6=AC=A1=E8=B0=83=E7=94=A8?= =?UTF-8?q?you-get=20=E6=96=B9=E6=B3=95=E6=9D=A5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=88=91=E6=83=B3=E8=A6=81=E7=9A=84=E6=95=B0=E6=8D=AE=E3=80=82?= =?UTF-8?q?=E4=BD=86=E6=98=AF=EF=BC=8C=E5=9C=A8=E5=A6=82=E4=B8=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=AD=E5=8F=91=E7=8E=B0=E4=BA=86=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82=E6=89=A7=E8=A1=8CgetJson=E5=92=8CgetDefaultDownloadIn?= =?UTF-8?q?fo=E4=B9=8B=E5=90=8E=E5=86=8D=E6=89=A7=E8=A1=8Cdownload?= =?UTF-8?q?=EF=BC=8C=E9=87=8D=E5=AE=9A=E5=90=91=E8=BE=93=E5=87=BA=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E8=8E=B7=E5=8F=96=E5=88=B0=E7=9A=84=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=B0=86=E6=97=A0=E6=95=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/you_get/test.py | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/you_get/test.py diff --git a/src/you_get/test.py b/src/you_get/test.py new file mode 100644 index 00000000..84ac2e3e --- /dev/null +++ b/src/you_get/test.py @@ -0,0 +1,59 @@ +import traceback +import sys +from you_get import common as you_get +import io +import os + +url = "https://www.bilibili.com/video/BV1GV411p7P9" +path = os.path.dirname(os.path.realpath(__file__)) + +def getJson(url): + from you_get import common as you + try: + __console__ = sys.stdout + f = io.StringIO() + sys.stdout = f + sys.argv = ['you-get', url, '--json'] + you.main() + text = f.getvalue() + sys.stdout = __console__ + print(text) + except: + traceback.print_exc() + + +def getDefaultDownloadInfo(url): + try: + __console__ = sys.stdout + f = io.StringIO() + sys.stdout = f + sys.argv = ['you-get', url, '-u'] + you_get.main() + text = f.getvalue() + sys.stdout = __console__ + print(text) + except: + traceback.print_exc() + + +def download(url, path): + try: + sys.argv = ['you-get', url, '-o', path, '--no-caption', '--debug'] + you_get.main() + except: + traceback.print_exc() + + +if __name__ == '__main__': + # only use one sentence, they all ok (使用如下的单条语句,都是可以正常打印的, 并且可以下载视频) + # both are cant download video with combine (但是将语句组合使用,打印出的结果就有问题了, 并且无法下载视频) + + # use these lines, print double json text (使用如下语句,将会打印出两次 json 解析数据) + getDefaultDownloadInfo(url) + getJson(url) + download(url, path) + + # or use these lines, print triple json text (使用如下语句,仅仅改变排序,将会打印出三次 json 解析数据) + # getJson(url) + # getDefaultDownloadInfo(url) + # download(url, "save path")