download API에 cookiefile, headers 키 추가

download API에 cookiefile, headers 키 추가 (Thanks to soju6jan)
This commit is contained in:
joyfuI
2020-12-07 23:59:36 +09:00
parent 33bfe6f4ee
commit 04937f7c64
5 changed files with 25 additions and 27 deletions

View File

@@ -74,8 +74,11 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로
`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 패키지를 선택할 수 있습니다. 설정 변경 후 재시작해야 적용됩니다.

View File

@@ -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"}

View File

@@ -110,10 +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')
# 2020-12-06 by soju6jan. api로 headers, cookiefile 전달 headers = kwagrs.get('headers')
youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts, dateafter, headers=kwagrs['headers'], cookiefile=kwagrs['cookiefile']) youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts, dateafter, headers)
# by soju6jan
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

View File

@@ -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, headers=None, cookiefile=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
@@ -92,9 +93,6 @@ class MyYoutubeDL(object):
'eta': None, # 예상 시간(s) 'eta': None, # 예상 시간(s)
'speed': None # 다운로드 속도(bytes/s) 'speed': None # 다운로드 속도(bytes/s)
} }
# 2020-12-06 by soju6jan. api로 headers, cookiefile 전달
self.headers = headers
self.cookiefile = cookiefile
def start(self): def start(self):
if self.status != Status.READY: if self.status != Status.READY:
@@ -112,12 +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
# 2020-12-06 by soju6jan. api로 headers, cookiefile 전달 # headers는 전역으로 계속 사용하기 때문에 매번 세팅
# headers는 전역으로 계속 사용하기 때문에 매번 세팅. youtube_dl.utils.std_headers = self.headers
youtube_dl_utils = __import__('%s.utils' % YOUTUBE_DL_PACKAGE)
youtube_dl_utils.std_headers = {} if self.headers is None else self.headers
# 동영상 정보 가져오기 # 동영상 정보 가져오기
info_dict = MyYoutubeDL.get_info_dict(self.url, self.opts.get('proxy'), cookiefile=self.cookiefile) 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
@@ -133,8 +129,6 @@ class MyYoutubeDL(object):
'ignoreerrors': True, 'ignoreerrors': True,
'cachedir': False 'cachedir': False
} }
if self.cookiefile:
ydl_opts['cookiefile'] = self.cookiefile
ydl_opts.update(self.opts) ydl_opts.update(self.opts)
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([self.url]) ydl.download([self.url])

View File

@@ -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,14 +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)
# 2020-12-06 by soju6jan. api로 headers, cookiefile 전달
headers = None
tmp_headers = request.values.get('headers', None)
if tmp_headers is not None:
import json
headers = json.loads(tmp_headers) # header는 json.dumps로 넘어오는 것으로 함. unqoute 등을 해야하는지 고려해야함.
cookiefile = request.values.get('cookiefile', None) cookiefile = request.values.get('cookiefile', None)
# by soju6jan headers = request.values.get('headers', '{}')
ret = { ret = {
'errorCode': 0, 'errorCode': 0,
'index': None 'index': None
@@ -243,9 +238,9 @@ def api(sub):
proxy=ModelSetting.get('proxy'), proxy=ModelSetting.get('proxy'),
ffmpeg_path=ModelSetting.get('ffmpeg_path'), ffmpeg_path=ModelSetting.get('ffmpeg_path'),
key=key, key=key,
# 2020-12-06 by soju6jan. cookiefile=cookiefile,
headers=headers, # header는 json.dumps로 넘어오는 것으로 함. unqoute 등을 해야하는지 고려해야 함
cookiefile=cookiefile) 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