v2.1.0 download API에 cookiefile, headers 키 추가
download API에 cookiefile, headers 키 추가 (Thanks to soju6jan)
This commit is contained in:
22
README.md
22
README.md
@@ -14,7 +14,7 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
과연 이걸로 뭔가를 만드실 분이 계실지...
|
과연 이걸로 뭔가를 만드실 분이 계실지...
|
||||||
|
|
||||||
[youtube-dl](https://github.com/ytdl-org/youtube-dl)의 DMCA 테이크다운 이후, 업데이트 속도가 느려진 것 같아서 youtube-dl의 포크 프로젝트인 [youtube-dlc](https://github.com/blackjack4494/yt-dlc)를 추가했습니다.
|
[youtube-dl](https://github.com/ytdl-org/youtube-dl)의 DMCA 테이크다운 이후, 업데이트 속도가 느려진 것 같아서 youtube-dl의 포크 프로젝트인 [youtube-dlc](https://github.com/blackjack4494/yt-dlc)를 추가했습니다.
|
||||||
설정에서 취향껏 설정해서 사용하시면 됩니다.
|
설정에서 취향껏 골라서 사용하시면 됩니다.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
### 공통사항
|
### 공통사항
|
||||||
@@ -53,7 +53,7 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
`errorCode` | 에러 코드 | Integer
|
`errorCode` | 에러 코드 | Integer
|
||||||
`info_dict` | 동영상 정보 | Object
|
`info_dict` | 동영상 정보 | Object
|
||||||
|
|
||||||
동영상 정보(`info_dict` 키)에는 youtube-dl에서 생성한 info_dict 정보가 그대로 들어있습니다. 따라서 이 부분은 직접 주소를 넣어가며 반환되는 정보를 확인해보는게 좋습니다.
|
동영상 정보(`info_dict` 키)에는 youtube-dl에서 생성한 info_dict 정보가 그대로 들어있습니다. 따라서 이 부분은 직접 주소를 넣어가며 반환되는 정보를 확인해보는 게 좋습니다.
|
||||||
간단한 예로 `thumbnail` 키엔 썸네일 주소, `uploader` 키엔 업로더 이름, `title` 키엔 동영상 제목, `duration` 키엔 동영상 길이 등이 들어 있습니다.
|
간단한 예로 `thumbnail` 키엔 썸네일 주소, `uploader` 키엔 업로더 이름, `title` 키엔 동영상 제목, `duration` 키엔 동영상 길이 등이 들어 있습니다.
|
||||||
그리고 만약 주소가 플레이리스트라면 `_type` 키에 `"playlist"`라는 값이 들어 있습니다. 이때는 `entries` 키에 리스트가 들어있어 동영상들의 제목과 ID를 확인할 수 있습니다.
|
그리고 만약 주소가 플레이리스트라면 `_type` 키에 `"playlist"`라는 값이 들어 있습니다. 이때는 `entries` 키에 리스트가 들어있어 동영상들의 제목과 ID를 확인할 수 있습니다.
|
||||||
|
|
||||||
@@ -65,17 +65,20 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
`plugin` | 플러그인 이름 | O | String
|
`plugin` | 플러그인 이름 | O | String
|
||||||
`key` | 임의의 키. 이후 다운로드를 제어할 때 이 키가 필요함 | O | String
|
`key` | 임의의 키. 이후 다운로드를 제어할 때 이 키가 필요함 | O | String
|
||||||
`url` | 동영상 주소 | O | String
|
`url` | 동영상 주소 | O | String
|
||||||
`filename` | 파일명. 템플릿 규칙은 https://github.com/ytdl-org/youtube-dl/blob/master/README.md#output-template 참고. 미지정 시 사용자 설정 | X | String
|
`filename` | 파일명. 템플릿 규칙은 https://github.com/ytdl-org/youtube-dl/#output-template 참고. 미지정 시 사용자 설정 | X | String
|
||||||
`save_path` | 저장 폴더 경로. 미지정 시 사용자 설정 | X | String
|
`save_path` | 저장 폴더 경로. 미지정 시 사용자 설정 | X | String
|
||||||
`format` | 동영상 포맷. 포맷 지정은 https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection 참고. 미지정 시 최고 화질 | X | String
|
`format` | 동영상 포맷. 포맷 지정은 https://github.com/ytdl-org/youtube-dl/#format-selection 참고. 미지정 시 최고 화질 | X | String
|
||||||
`preferedformat` | 변환할 비디오 포맷. 가능한 포맷은 https://ffmpeg.org/general.html#File-Formats 참고. 미지정 시 변환하지 않음 | X | String
|
`preferedformat` | 변환할 비디오 포맷. 가능한 포맷은 https://ffmpeg.org/general.html#File-Formats 참고. 미지정 시 변환하지 않음 | X | String
|
||||||
`preferredcodec` | 추출할 오디오 코덱. 가능한 값은 `"best"`, `"mp3"`, `"aac"`, `"flac"`, `"m4a"`, `"opus"`, `"vorbis"`, `"wav"`. 미지정 시 추출하지 않음 | X | String
|
`preferredcodec` | 추출할 오디오 코덱. 가능한 값은 `"best"`, `"mp3"`, `"aac"`, `"flac"`, `"m4a"`, `"opus"`, `"vorbis"`, `"wav"`. 미지정 시 추출하지 않음 | X | String
|
||||||
`preferredquality` | 추출한 오디오의 비트레이트. 0 ~ 9 사이의 VBR 퀄리티 값(0에 가까울수록 좋음) 혹은 특정 비트레이트 값. `preferredcodec` 키가 있을 때만 유효. 기본값: `192` | X | Integer
|
`preferredquality` | 추출한 오디오의 비트레이트. 0 ~ 9 사이의 VBR 퀄리티 값(0에 가까울수록 좋음) 혹은 특정 비트레이트 값. `preferredcodec` 키가 있을 때만 유효. 기본값: `192` | X | Integer
|
||||||
`dateafter` | 지정한 날짜 이후에 업로드된 동영상만 다운로드. 미지정 시 모든 동영상 다운로드 | X | String
|
`dateafter` | 지정한 날짜 이후에 업로드된 동영상만 다운로드. 미지정 시 모든 동영상 다운로드 | X | String
|
||||||
`archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있을 경우 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String
|
`archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String
|
||||||
`start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean
|
`start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean
|
||||||
|
`cookiefile` | 다운로드 시 필요한 쿠키 파일 경로 | X | String
|
||||||
|
`headers` | 다운로드 시 사용할 헤더. 기본값: `{}` | 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` 형식의 문자열입니다.
|
||||||
#### Response
|
#### Response
|
||||||
키 | 설명 | 타입
|
키 | 설명 | 타입
|
||||||
--- | --- | ---
|
--- | --- | ---
|
||||||
@@ -132,6 +135,11 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
|
|||||||
물론 해당 정보가 없으면 null입니다.
|
물론 해당 정보가 없으면 null입니다.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
v2.1.0
|
||||||
|
* download API에 cookiefile, headers 키 추가
|
||||||
|
카카오TV 동영상 다운로드에 활용할 수 있습니다. 잘하면 로봇 체크 패스에도 사용이 가능한 듯 싶습니다.
|
||||||
|
Thanks to [soju6jan](https://github.com/soju6jan)
|
||||||
|
|
||||||
v2.0.0
|
v2.0.0
|
||||||
* youtube-dlc 추가
|
* youtube-dlc 추가
|
||||||
사용할 youtube-dl 패키지를 선택할 수 있습니다. 설정 변경 후 재시작해야 적용됩니다.
|
사용할 youtube-dl 패키지를 선택할 수 있습니다. 설정 변경 후 재시작해야 적용됩니다.
|
||||||
@@ -218,7 +226,7 @@ v1.3.1
|
|||||||
v1.3.0
|
v1.3.0
|
||||||
* 후처리 기능 추가
|
* 후처리 기능 추가
|
||||||
이제 비디오 변환이나 오디오 추출이 가능합니다.
|
이제 비디오 변환이나 오디오 추출이 가능합니다.
|
||||||
오디오 추출의 경우 비트레이트는 192kbps로 설정되어 있습니다.
|
오디오 추출의 비트레이트는 192kbps로 설정되어 있습니다.
|
||||||
|
|
||||||
v1.2.5
|
v1.2.5
|
||||||
* 기본 파일명 설정 추가
|
* 기본 파일명 설정 추가
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"description": "\uc720\ud29c\ube0c, \ub124\uc774\ubc84TV \ub4f1 \ub3d9\uc601\uc0c1 \uc0ac\uc774\ud2b8\uc5d0\uc11c \ub3d9\uc601\uc0c1 \ub2e4\uc6b4\ub85c\ub4dc", "name": "youtube-dl", "more": "", "version": "2.0.0", "home": "https://github.com/joyfuI/youtube-dl", "category_name": "vod", "developer": "joyfuI"}
|
{"description": "\uc720\ud29c\ube0c, \ub124\uc774\ubc84TV \ub4f1 \ub3d9\uc601\uc0c1 \uc0ac\uc774\ud2b8\uc5d0\uc11c \ub3d9\uc601\uc0c1 \ub2e4\uc6b4\ub85c\ub4dc", "name": "youtube-dl", "more": "", "version": "2.1.0", "home": "https://github.com/joyfuI/youtube-dl", "category_name": "vod", "developer": "joyfuI"}
|
||||||
@@ -110,8 +110,11 @@ class LogicNormal(object):
|
|||||||
opts['proxy'] = kwagrs['proxy']
|
opts['proxy'] = kwagrs['proxy']
|
||||||
if 'ffmpeg_path' in kwagrs and kwagrs['ffmpeg_path']:
|
if 'ffmpeg_path' in kwagrs and kwagrs['ffmpeg_path']:
|
||||||
opts['ffmpeg_location'] = kwagrs['ffmpeg_path']
|
opts['ffmpeg_location'] = kwagrs['ffmpeg_path']
|
||||||
|
if 'cookiefile' in kwagrs and kwagrs['cookiefile']:
|
||||||
|
opts['cookiefile'] = kwagrs['cookiefile']
|
||||||
dateafter = kwagrs.get('dateafter')
|
dateafter = kwagrs.get('dateafter')
|
||||||
youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts, dateafter)
|
headers = kwagrs.get('headers')
|
||||||
|
youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts, dateafter, headers)
|
||||||
youtube_dl.key = kwagrs.get('key')
|
youtube_dl.key = kwagrs.get('key')
|
||||||
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
|
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
|
||||||
return youtube_dl
|
return youtube_dl
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class MyYoutubeDL(object):
|
|||||||
__index = 0
|
__index = 0
|
||||||
_last_msg = ''
|
_last_msg = ''
|
||||||
|
|
||||||
def __init__(self, plugin, url, filename, temp_path, save_path=None, opts=None, dateafter=None, datebefore=None):
|
def __init__(self, plugin, url, filename, temp_path, save_path=None, opts=None, dateafter=None, datebefore=None, headers={}):
|
||||||
# from youtube_dl.utils import DateRange
|
# from youtube_dl.utils import DateRange
|
||||||
from .plugin import YOUTUBE_DL_PACKAGE
|
from .plugin import YOUTUBE_DL_PACKAGE
|
||||||
DateRange = __import__('%s.utils' % YOUTUBE_DL_PACKAGE, fromlist=['DateRange']).DateRange
|
DateRange = __import__('%s.utils' % YOUTUBE_DL_PACKAGE, fromlist=['DateRange']).DateRange
|
||||||
@@ -66,6 +66,7 @@ class MyYoutubeDL(object):
|
|||||||
self.opts = opts
|
self.opts = opts
|
||||||
if dateafter or datebefore:
|
if dateafter or datebefore:
|
||||||
self.opts['daterange'] = DateRange(start=dateafter, end=datebefore)
|
self.opts['daterange'] = DateRange(start=dateafter, end=datebefore)
|
||||||
|
self.headers = headers
|
||||||
self.index = MyYoutubeDL.__index
|
self.index = MyYoutubeDL.__index
|
||||||
MyYoutubeDL.__index += 1
|
MyYoutubeDL.__index += 1
|
||||||
self.__status = Status.READY
|
self.__status = Status.READY
|
||||||
@@ -109,8 +110,10 @@ class MyYoutubeDL(object):
|
|||||||
try:
|
try:
|
||||||
self.start_time = datetime.now()
|
self.start_time = datetime.now()
|
||||||
self.status = Status.START
|
self.status = Status.START
|
||||||
|
# headers는 전역으로 계속 사용하기 때문에 매번 세팅
|
||||||
|
youtube_dl.utils.std_headers = self.headers
|
||||||
# 동영상 정보 가져오기
|
# 동영상 정보 가져오기
|
||||||
info_dict = MyYoutubeDL.get_info_dict(self.url, self.opts.get('proxy'))
|
info_dict = MyYoutubeDL.get_info_dict(self.url, self.opts.get('proxy'), self.opts.get('cookiefile'))
|
||||||
if info_dict is None:
|
if info_dict is None:
|
||||||
self.status = Status.ERROR
|
self.status = Status.ERROR
|
||||||
return
|
return
|
||||||
@@ -164,11 +167,10 @@ class MyYoutubeDL(object):
|
|||||||
return __version__
|
return __version__
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_info_dict(url, proxy=None):
|
def get_info_dict(url, proxy=None, cookiefile=None):
|
||||||
# import youtube_dl
|
# import youtube_dl
|
||||||
from .plugin import YOUTUBE_DL_PACKAGE
|
from .plugin import YOUTUBE_DL_PACKAGE
|
||||||
youtube_dl = __import__('%s' % YOUTUBE_DL_PACKAGE)
|
youtube_dl = __import__('%s' % YOUTUBE_DL_PACKAGE)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'simulate': True,
|
'simulate': True,
|
||||||
@@ -178,6 +180,8 @@ class MyYoutubeDL(object):
|
|||||||
}
|
}
|
||||||
if proxy:
|
if proxy:
|
||||||
ydl_opts['proxy'] = proxy
|
ydl_opts['proxy'] = proxy
|
||||||
|
if cookiefile:
|
||||||
|
ydl_opts['cookiefile'] = cookiefile
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download([url])
|
ydl.download([url])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
10
plugin.py
10
plugin.py
@@ -5,6 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import json
|
||||||
|
|
||||||
# third-party
|
# third-party
|
||||||
from flask import Blueprint, request, render_template, redirect, jsonify, abort
|
from flask import Blueprint, request, render_template, redirect, jsonify, abort
|
||||||
@@ -44,7 +45,7 @@ menu = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin_info = {
|
plugin_info = {
|
||||||
'version': '2.0.0',
|
'version': '2.1.0',
|
||||||
'name': 'youtube-dl',
|
'name': 'youtube-dl',
|
||||||
'category_name': 'vod',
|
'category_name': 'vod',
|
||||||
'developer': 'joyfuI',
|
'developer': 'joyfuI',
|
||||||
@@ -209,6 +210,8 @@ def api(sub):
|
|||||||
dateafter = request.values.get('dateafter', None)
|
dateafter = request.values.get('dateafter', None)
|
||||||
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)
|
||||||
|
headers = request.values.get('headers', '{}')
|
||||||
ret = {
|
ret = {
|
||||||
'errorCode': 0,
|
'errorCode': 0,
|
||||||
'index': None
|
'index': None
|
||||||
@@ -234,7 +237,10 @@ def api(sub):
|
|||||||
archive=archive,
|
archive=archive,
|
||||||
proxy=ModelSetting.get('proxy'),
|
proxy=ModelSetting.get('proxy'),
|
||||||
ffmpeg_path=ModelSetting.get('ffmpeg_path'),
|
ffmpeg_path=ModelSetting.get('ffmpeg_path'),
|
||||||
key=key)
|
key=key,
|
||||||
|
cookiefile=cookiefile,
|
||||||
|
# header는 json.dumps로 넘어오는 것으로 함. unqoute 등을 해야하는지 고려해야 함
|
||||||
|
headers=json.loads(headers))
|
||||||
if youtube_dl is None:
|
if youtube_dl is None:
|
||||||
return LogicNormal.abort(ret, 10) # 실패
|
return LogicNormal.abort(ret, 10) # 실패
|
||||||
ret['index'] = youtube_dl.index
|
ret['index'] = youtube_dl.index
|
||||||
|
|||||||
@@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
{{ macros.setting_input_text('url', 'URL', placeholder='http:// 주소', desc='유튜브, 네이버TV 등 동영상 주소') }}
|
{{ macros.setting_input_text('url', 'URL', placeholder='http:// 주소', desc='유튜브, 네이버TV 등 동영상 주소') }}
|
||||||
{{ macros.setting_input_text('filename', '파일명', value=arg['filename'], desc='템플릿 규칙은 https://github.com/blackjack4494/yt-dlc#output-template 참고') }}
|
{{ macros.setting_input_text('filename', '파일명', value=arg['filename'], desc='템플릿 규칙은 https://github.com/ytdl-org/youtube-dl/#output-template 참고') }}
|
||||||
{{ macros.setting_select('preset', '동영상 포맷 프리셋', arg['preset_list'], col='3') }}
|
{{ macros.setting_select('preset', '동영상 포맷 프리셋', arg['preset_list'], col='3') }}
|
||||||
{{ macros.setting_input_text('format', '동영상 포맷', desc=['포맷 지정은 https://github.com/blackjack4494/yt-dlc#format-selection 참고', '빈칸으로 두면 최고 화질로 다운로드합니다.']) }}
|
{{ macros.setting_input_text('format', '동영상 포맷', desc=['포맷 지정은 https://github.com/ytdl-org/youtube-dl/#format-selection 참고', '빈칸으로 두면 최고 화질로 다운로드합니다.']) }}
|
||||||
{{ setting_select2('postprocessor', '후처리', arg['postprocessor_list'], col='3', desc='다운로드 후 FFmpeg로 후처리합니다.') }}
|
{{ setting_select2('postprocessor', '후처리', arg['postprocessor_list'], col='3', desc='다운로드 후 FFmpeg로 후처리합니다.') }}
|
||||||
{{ macros.setting_button([['download_btn', '다운로드']]) }}
|
{{ macros.setting_button([['download_btn', '다운로드']]) }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
{{ macros.setting_input_text_and_buttons('ffmpeg_path', 'FFmpeg 경로', [['ffmpeg_version', '버전확인']], value=arg['ffmpeg_path'], placeholder='ffmpeg', desc='SJVA에 내장된 버전 말고 원하는 버전을 사용할 수 있습니다.') }}
|
{{ macros.setting_input_text_and_buttons('ffmpeg_path', 'FFmpeg 경로', [['ffmpeg_version', '버전확인']], value=arg['ffmpeg_path'], placeholder='ffmpeg', desc='SJVA에 내장된 버전 말고 원하는 버전을 사용할 수 있습니다.') }}
|
||||||
{{ macros.setting_input_text('temp_path', '임시 폴더', value=arg['temp_path'], desc='다운로드 파일이 임시로 저장될 폴더입니다.') }}
|
{{ macros.setting_input_text('temp_path', '임시 폴더', value=arg['temp_path'], desc='다운로드 파일이 임시로 저장될 폴더입니다.') }}
|
||||||
{{ macros.setting_input_text('save_path', '저장 폴더', value=arg['save_path'], desc='정상적으로 완료된 파일이 이동할 폴더입니다.') }}
|
{{ macros.setting_input_text('save_path', '저장 폴더', value=arg['save_path'], desc='정상적으로 완료된 파일이 이동할 폴더입니다.') }}
|
||||||
{{ macros.setting_input_text('default_filename', '기본 파일명', value=arg['default_filename'], placeholder=arg['DEFAULT_FILENAME'], desc='템플릿 규칙은 https://github.com/blackjack4494/yt-dlc#output-template 참고') }}
|
{{ macros.setting_input_text('default_filename', '기본 파일명', value=arg['default_filename'], placeholder=arg['DEFAULT_FILENAME'], desc='템플릿 규칙은 https://github.com/ytdl-org/youtube-dl/#output-template 참고') }}
|
||||||
{{ macros.setting_input_text('proxy', '프록시', value=arg['proxy'], desc=['HTTP/HTTPS/SOCKS를 지원합니다. 예) socks5://127.0.0.1:1080/', '빈칸으로 두면 프록시를 사용하지 않습니다.']) }}
|
{{ macros.setting_input_text('proxy', '프록시', value=arg['proxy'], desc=['HTTP/HTTPS/SOCKS를 지원합니다. 예) socks5://127.0.0.1:1080/', '빈칸으로 두면 프록시를 사용하지 않습니다.']) }}
|
||||||
{{ macros.setting_checkbox('activate_cors', 'CORS 허용', value=arg['activate_cors'], desc='API로의 크로스 도메인 요청을 허용합니다. 설정 저장 후 재시작이 필요합니다.') }}
|
{{ macros.setting_checkbox('activate_cors', 'CORS 허용', value=arg['activate_cors'], desc='API로의 크로스 도메인 요청을 허용합니다. 설정 저장 후 재시작이 필요합니다.') }}
|
||||||
{{ macros.setting_button([['global_setting_save_btn', '저장']]) }}
|
{{ macros.setting_button([['global_setting_save_btn', '저장']]) }}
|
||||||
|
|||||||
Reference in New Issue
Block a user