From 3410ddd73ccedc8b56e424dc6b4d6d7a5d02ac48 Mon Sep 17 00:00:00 2001 From: joyfuI <1342862+joyfuI@users.noreply.github.com> Date: Sun, 24 Jul 2022 21:56:46 +0900 Subject: [PATCH] =?UTF-8?q?download,=20thumbnail,=20sub=20API=EC=97=90=20h?= =?UTF-8?q?eaders=20=ED=82=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 ++++++++++++---- main.py | 6 ++++++ my_youtube_dl.py | 9 +++++++-- plugin.py | 7 +++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 100f8c6..0ecd1b7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ SJVA에서 "시스템 → 플러그인 → 플러그인 수동 설치" 칸에 API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로드를 요청할 수 있습니다. 다른 플러그인이 멋대로 다운로드를 중지할 수 없도록 다운로드를 요청할 때 임의의 키를 넘겨받습니다. 중지 요청 시 키가 일치해야 요청이 실행됩니다. -[youtube-dl](https://github.com/ytdl-org/youtube-dl)의 DMCA 테이크다운 사태 이후, 비슷한 상황을 대비하기 위해 youtube-dl의 포크 프로젝트 [youtube-dlc](https://github.com/blackjack4494/yt-dlc)의 포크 프로젝트(...)인 [yt-dlp](https://github.com/pukkandan/yt-dlp)를 추가했습니다. +[youtube-dl](https://github.com/ytdl-org/youtube-dl)의 DMCA 테이크다운 사태 이후, 비슷한 상황을 대비하기 위해 youtube-dl의 포크 프로젝트 [youtube-dlc](https://github.com/blackjack4494/yt-dlc)의 포크 프로젝트(...)인 [yt-dlp](https://github.com/yt-dlp/yt-dlp)를 추가했습니다. 설정에서 취향껏 골라서 사용하시면 되며 youtube-dl가 우선 지원됩니다. ## API @@ -93,8 +93,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 | `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String | | `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean | | `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String | +| `headers` | 다운로드 시 사용할 HTTP 헤더 정보 | X | String | -`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`headers` 키에 넣는 값은 `json` 형식의 문자열입니다. `playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다. 범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다. @@ -127,8 +129,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 | `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String | | `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean | | `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String | +| `headers` | 다운로드 시 사용할 HTTP 헤더 정보 | X | String | -`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`headers` 키에 넣는 값은 `json` 형식의 문자열입니다. `playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다. 범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다. @@ -163,8 +167,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 | `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String | | `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean | | `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String | +| `headers` | 다운로드 시 사용할 HTTP 헤더 정보 | X | String | -`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`dateafter` 키에 넣을 수 있는 날짜는 `"YYYYMMDD"` 또는 `"(now|today)[+-][0-9](day|week|month|year)(s)?"` 형식의 문자열입니다. +`headers` 키에 넣는 값은 `json` 형식의 문자열입니다. `playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다. 범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다. @@ -248,6 +254,8 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 v4.0.0 - 최신 플러그인 구조로 변경 +- download, thumbnail, sub API에 headers 키 추가 + http 헤더 수정이 필요한 경우 활용할 수 있습니다. v3.1.1 diff --git a/main.py b/main.py index 527a63c..61aa1bd 100644 --- a/main.py +++ b/main.py @@ -333,6 +333,8 @@ class LogicMain(LogicModuleBase): opts["ffmpeg_location"] = kwagrs["ffmpeg_path"] if "cookiefile" in kwagrs and kwagrs["cookiefile"]: opts["cookiefile"] = kwagrs["cookiefile"] + if "headers" in kwagrs and kwagrs["headers"]: + opts["http_headers"] = kwagrs["headers"] dateafter = kwagrs.get("dateafter") youtube_dl = MyYoutubeDL( plugin, "video", url, filename, temp_path, save_path, opts, dateafter @@ -377,6 +379,8 @@ class LogicMain(LogicModuleBase): opts["ffmpeg_location"] = kwagrs["ffmpeg_path"] if "cookiefile" in kwagrs and kwagrs["cookiefile"]: opts["cookiefile"] = kwagrs["cookiefile"] + if "headers" in kwagrs and kwagrs["headers"]: + opts["http_headers"] = kwagrs["headers"] dateafter = kwagrs.get("dateafter") youtube_dl = MyYoutubeDL( plugin, @@ -432,6 +436,8 @@ class LogicMain(LogicModuleBase): opts["ffmpeg_location"] = kwagrs["ffmpeg_path"] if "cookiefile" in kwagrs and kwagrs["cookiefile"]: opts["cookiefile"] = kwagrs["cookiefile"] + if "headers" in kwagrs and kwagrs["headers"]: + opts["http_headers"] = kwagrs["headers"] dateafter = kwagrs.get("dateafter") youtube_dl = MyYoutubeDL( plugin, "subtitle", url, filename, temp_path, save_path, opts, dateafter diff --git a/my_youtube_dl.py b/my_youtube_dl.py index 94196b1..c30eb9b 100644 --- a/my_youtube_dl.py +++ b/my_youtube_dl.py @@ -118,7 +118,10 @@ class MyYoutubeDL: self.status = Status.START # 동영상 정보 가져오기 info_dict = MyYoutubeDL.get_info_dict( - self.url, self.opts.get("proxy"), self.opts.get("cookiefile") + self.url, + self.opts.get("proxy"), + self.opts.get("cookiefile"), + self.opts.get("http_headers"), ) if info_dict is None: self.status = Status.ERROR @@ -174,7 +177,7 @@ class MyYoutubeDL: return __version__ @staticmethod - def get_info_dict(url, proxy=None, cookiefile=None): + def get_info_dict(url, proxy=None, cookiefile=None, http_headers=None): # import youtube_dl youtube_dl = __import__(youtube_dl_package) @@ -184,6 +187,8 @@ class MyYoutubeDL: ydl_opts["proxy"] = proxy if cookiefile: ydl_opts["cookiefile"] = cookiefile + if http_headers: + ydl_opts["http_headers"] = http_headers with youtube_dl.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=False) except Exception as error: diff --git a/plugin.py b/plugin.py index bbf3d8a..65d4af6 100644 --- a/plugin.py +++ b/plugin.py @@ -1,5 +1,6 @@ import os import traceback +import json from flask import Blueprint, request, jsonify, abort @@ -121,6 +122,7 @@ def api(sub): archive = request.values.get("archive", None) start = request.values.get("start", False) cookiefile = request.values.get("cookiefile", None) + headers = request.values.get("headers", None) ret = {"errorCode": 0, "index": None} if None in (key, url): return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음 @@ -157,6 +159,7 @@ def api(sub): ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"), key=key, cookiefile=cookiefile, + headers=json.loads(headers), ) if youtube_dl is None: return LogicAbort.abort(ret, 10) # 실패 @@ -181,6 +184,7 @@ def api(sub): archive = request.values.get("archive", None) start = request.values.get("start", False) cookiefile = request.values.get("cookiefile", None) + headers = request.values.get("headers", None) ret = {"errorCode": 0, "index": None} if None in (key, url): return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음 @@ -202,6 +206,7 @@ def api(sub): ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"), key=key, cookiefile=cookiefile, + headers=json.loads(headers), ) if youtube_dl is None: return LogicAbort.abort(ret, 10) # 실패 @@ -228,6 +233,7 @@ def api(sub): archive = request.values.get("archive", None) start = request.values.get("start", False) cookiefile = request.values.get("cookiefile", None) + headers = request.values.get("headers", None) ret = {"errorCode": 0, "index": None} if None in (key, url): return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음 @@ -251,6 +257,7 @@ def api(sub): ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"), key=key, cookiefile=cookiefile, + headers=json.loads(headers), ) if youtube_dl is None: return LogicAbort.abort(ret, 10) # 실패