download, thumbnail, sub API에 headers 키 추가
This commit is contained in:
16
README.md
16
README.md
@@ -15,7 +15,7 @@ SJVA에서 "시스템 → 플러그인 → 플러그인 수동 설치" 칸에
|
|||||||
API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로드를 요청할 수 있습니다.
|
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가 우선 지원됩니다.
|
설정에서 취향껏 골라서 사용하시면 되며 youtube-dl가 우선 지원됩니다.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@@ -93,8 +93,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
||||||
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
||||||
| `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String |
|
| `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"`입니다.
|
`playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다.
|
||||||
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
||||||
@@ -127,8 +129,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
||||||
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
||||||
| `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String |
|
| `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"`입니다.
|
`playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다.
|
||||||
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
||||||
@@ -163,8 +167,10 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
| `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String |
|
||||||
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
| `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean |
|
||||||
| `cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String |
|
| `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"`입니다.
|
`playlist` 키에 넣을 수 있는 값은 `"1-3,7,10-13"` 형식의 범위 또는 `"reverse"`, `"random"`입니다.
|
||||||
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
범위를 넣으면 플레이리스트에서 선택한 것만 다운로드합니다.
|
||||||
@@ -248,6 +254,8 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
v4.0.0
|
v4.0.0
|
||||||
|
|
||||||
- 최신 플러그인 구조로 변경
|
- 최신 플러그인 구조로 변경
|
||||||
|
- download, thumbnail, sub API에 headers 키 추가
|
||||||
|
http 헤더 수정이 필요한 경우 활용할 수 있습니다.
|
||||||
|
|
||||||
v3.1.1
|
v3.1.1
|
||||||
|
|
||||||
|
|||||||
6
main.py
6
main.py
@@ -333,6 +333,8 @@ class LogicMain(LogicModuleBase):
|
|||||||
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
||||||
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
||||||
opts["cookiefile"] = kwagrs["cookiefile"]
|
opts["cookiefile"] = kwagrs["cookiefile"]
|
||||||
|
if "headers" in kwagrs and kwagrs["headers"]:
|
||||||
|
opts["http_headers"] = kwagrs["headers"]
|
||||||
dateafter = kwagrs.get("dateafter")
|
dateafter = kwagrs.get("dateafter")
|
||||||
youtube_dl = MyYoutubeDL(
|
youtube_dl = MyYoutubeDL(
|
||||||
plugin, "video", url, filename, temp_path, save_path, opts, dateafter
|
plugin, "video", url, filename, temp_path, save_path, opts, dateafter
|
||||||
@@ -377,6 +379,8 @@ class LogicMain(LogicModuleBase):
|
|||||||
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
||||||
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
||||||
opts["cookiefile"] = kwagrs["cookiefile"]
|
opts["cookiefile"] = kwagrs["cookiefile"]
|
||||||
|
if "headers" in kwagrs and kwagrs["headers"]:
|
||||||
|
opts["http_headers"] = kwagrs["headers"]
|
||||||
dateafter = kwagrs.get("dateafter")
|
dateafter = kwagrs.get("dateafter")
|
||||||
youtube_dl = MyYoutubeDL(
|
youtube_dl = MyYoutubeDL(
|
||||||
plugin,
|
plugin,
|
||||||
@@ -432,6 +436,8 @@ class LogicMain(LogicModuleBase):
|
|||||||
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
opts["ffmpeg_location"] = kwagrs["ffmpeg_path"]
|
||||||
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
if "cookiefile" in kwagrs and kwagrs["cookiefile"]:
|
||||||
opts["cookiefile"] = kwagrs["cookiefile"]
|
opts["cookiefile"] = kwagrs["cookiefile"]
|
||||||
|
if "headers" in kwagrs and kwagrs["headers"]:
|
||||||
|
opts["http_headers"] = kwagrs["headers"]
|
||||||
dateafter = kwagrs.get("dateafter")
|
dateafter = kwagrs.get("dateafter")
|
||||||
youtube_dl = MyYoutubeDL(
|
youtube_dl = MyYoutubeDL(
|
||||||
plugin, "subtitle", url, filename, temp_path, save_path, opts, dateafter
|
plugin, "subtitle", url, filename, temp_path, save_path, opts, dateafter
|
||||||
|
|||||||
@@ -118,7 +118,10 @@ class MyYoutubeDL:
|
|||||||
self.status = Status.START
|
self.status = Status.START
|
||||||
# 동영상 정보 가져오기
|
# 동영상 정보 가져오기
|
||||||
info_dict = MyYoutubeDL.get_info_dict(
|
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:
|
if info_dict is None:
|
||||||
self.status = Status.ERROR
|
self.status = Status.ERROR
|
||||||
@@ -174,7 +177,7 @@ class MyYoutubeDL:
|
|||||||
return __version__
|
return __version__
|
||||||
|
|
||||||
@staticmethod
|
@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
|
# import youtube_dl
|
||||||
youtube_dl = __import__(youtube_dl_package)
|
youtube_dl = __import__(youtube_dl_package)
|
||||||
|
|
||||||
@@ -184,6 +187,8 @@ class MyYoutubeDL:
|
|||||||
ydl_opts["proxy"] = proxy
|
ydl_opts["proxy"] = proxy
|
||||||
if cookiefile:
|
if cookiefile:
|
||||||
ydl_opts["cookiefile"] = cookiefile
|
ydl_opts["cookiefile"] = cookiefile
|
||||||
|
if http_headers:
|
||||||
|
ydl_opts["http_headers"] = http_headers
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
info = ydl.extract_info(url, download=False)
|
info = ydl.extract_info(url, download=False)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import Blueprint, request, jsonify, abort
|
from flask import Blueprint, request, jsonify, abort
|
||||||
|
|
||||||
@@ -121,6 +122,7 @@ def api(sub):
|
|||||||
archive = request.values.get("archive", None)
|
archive = request.values.get("archive", None)
|
||||||
start = request.values.get("start", False)
|
start = request.values.get("start", False)
|
||||||
cookiefile = request.values.get("cookiefile", None)
|
cookiefile = request.values.get("cookiefile", None)
|
||||||
|
headers = request.values.get("headers", None)
|
||||||
ret = {"errorCode": 0, "index": None}
|
ret = {"errorCode": 0, "index": None}
|
||||||
if None in (key, url):
|
if None in (key, url):
|
||||||
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
||||||
@@ -157,6 +159,7 @@ def api(sub):
|
|||||||
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
||||||
key=key,
|
key=key,
|
||||||
cookiefile=cookiefile,
|
cookiefile=cookiefile,
|
||||||
|
headers=json.loads(headers),
|
||||||
)
|
)
|
||||||
if youtube_dl is None:
|
if youtube_dl is None:
|
||||||
return LogicAbort.abort(ret, 10) # 실패
|
return LogicAbort.abort(ret, 10) # 실패
|
||||||
@@ -181,6 +184,7 @@ def api(sub):
|
|||||||
archive = request.values.get("archive", None)
|
archive = request.values.get("archive", None)
|
||||||
start = request.values.get("start", False)
|
start = request.values.get("start", False)
|
||||||
cookiefile = request.values.get("cookiefile", None)
|
cookiefile = request.values.get("cookiefile", None)
|
||||||
|
headers = request.values.get("headers", None)
|
||||||
ret = {"errorCode": 0, "index": None}
|
ret = {"errorCode": 0, "index": None}
|
||||||
if None in (key, url):
|
if None in (key, url):
|
||||||
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
||||||
@@ -202,6 +206,7 @@ def api(sub):
|
|||||||
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
||||||
key=key,
|
key=key,
|
||||||
cookiefile=cookiefile,
|
cookiefile=cookiefile,
|
||||||
|
headers=json.loads(headers),
|
||||||
)
|
)
|
||||||
if youtube_dl is None:
|
if youtube_dl is None:
|
||||||
return LogicAbort.abort(ret, 10) # 실패
|
return LogicAbort.abort(ret, 10) # 실패
|
||||||
@@ -228,6 +233,7 @@ def api(sub):
|
|||||||
archive = request.values.get("archive", None)
|
archive = request.values.get("archive", None)
|
||||||
start = request.values.get("start", False)
|
start = request.values.get("start", False)
|
||||||
cookiefile = request.values.get("cookiefile", None)
|
cookiefile = request.values.get("cookiefile", None)
|
||||||
|
headers = request.values.get("headers", None)
|
||||||
ret = {"errorCode": 0, "index": None}
|
ret = {"errorCode": 0, "index": None}
|
||||||
if None in (key, url):
|
if None in (key, url):
|
||||||
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
return LogicAbort.abort(ret, 1) # 필수 요청 변수가 없음
|
||||||
@@ -251,6 +257,7 @@ def api(sub):
|
|||||||
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
ffmpeg_path=Plugin.ModelSetting.get("ffmpeg_path"),
|
||||||
key=key,
|
key=key,
|
||||||
cookiefile=cookiefile,
|
cookiefile=cookiefile,
|
||||||
|
headers=json.loads(headers),
|
||||||
)
|
)
|
||||||
if youtube_dl is None:
|
if youtube_dl is None:
|
||||||
return LogicAbort.abort(ret, 10) # 실패
|
return LogicAbort.abort(ret, 10) # 실패
|
||||||
|
|||||||
Reference in New Issue
Block a user