v1.7.0 download API에 dateafter 추가

Python 3 지원
download API에 dateafter 추가
This commit is contained in:
joyfuI
2020-11-08 22:59:26 +09:00
8 changed files with 74 additions and 43 deletions

6
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.idea/ .idea/
venv/ .venv/
*.pyo *.pyo
__pycache__/
test/

View File

@@ -73,8 +73,12 @@ API에선 직접 비트레이트를 설정할 수 있습니다.
`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
`archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있을 경우 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String `archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있을 경우 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String
`start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean `start` | 다운로드 준비 후 바로 다운로드를 시작할지 여부. 기본값: `false` | X | Boolean
`dateafter` 키에 넣을 수 있는 날짜는 `YYYYMMDD` 또는 `(now|today)[+-][0-9](day|week|month|year)(s)?` 형식의 문자열입니다.
#### Response #### Response
키 | 설명 | 타입 키 | 설명 | 타입
--- | --- | --- --- | --- | ---
@@ -131,6 +135,12 @@ API에선 직접 비트레이트를 설정할 수 있습니다.
물론 해당 정보가 없으면 null입니다. 물론 해당 정보가 없으면 null입니다.
## Changelog ## Changelog
v1.7.0
* Python 3 지원
Python 2를 유지한 채로 Python 3 지원을 추가했습니다.
* download API에 dateafter 추가
지정한 날짜 이후에 업로드된 동영상만 다운로드하는 옵션입니다. 플레이리스트 다운로드 시에 유용하게 사용할 수 있습니다.
v1.6.11 v1.6.11
* 목록 메뉴에 전체 중지 버튼 추가 * 목록 메뉴에 전체 중지 버튼 추가

View File

@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from plugin import blueprint, menu, plugin_load, plugin_unload, plugin_info from .plugin import blueprint, menu, plugin_load, plugin_unload, plugin_info

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": "1.6.11", "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": "1.7.0", "home": "https://github.com/joyfuI/youtube-dl", "category_name": "vod", "developer": "joyfuI"}

View File

@@ -59,7 +59,7 @@ class Logic(object):
logger.debug(subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--upgrade', 'youtube-dl'], universal_newlines=True)) logger.debug(subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--upgrade', 'youtube-dl'], universal_newlines=True))
# 편의를 위해 json 파일 생성 # 편의를 위해 json 파일 생성
from plugin import plugin_info from .plugin import plugin_info
Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json'))
except Exception as e: except Exception as e:
logger.error('Exception:%s', e) logger.error('Exception:%s', e)

View File

@@ -72,39 +72,45 @@ class LogicNormal(object):
@staticmethod @staticmethod
def download(**kwagrs): def download(**kwagrs):
logger.debug(kwagrs) try:
plugin = kwagrs['plugin'] logger.debug(kwagrs)
url = kwagrs['url'] plugin = kwagrs['plugin']
filename = kwagrs['filename'] url = kwagrs['url']
temp_path = kwagrs['temp_path'] filename = kwagrs['filename']
save_path = kwagrs['save_path'] temp_path = kwagrs['temp_path']
opts = {} save_path = kwagrs['save_path']
if 'format' in kwagrs and kwagrs['format']: opts = {}
opts['format'] = kwagrs['format'] if 'format' in kwagrs and kwagrs['format']:
postprocessor = [] opts['format'] = kwagrs['format']
if 'preferedformat' in kwagrs and kwagrs['preferedformat']: postprocessor = []
postprocessor.append({ if 'preferedformat' in kwagrs and kwagrs['preferedformat']:
'key': 'FFmpegVideoConvertor', postprocessor.append({
'preferedformat': kwagrs['preferedformat'] 'key': 'FFmpegVideoConvertor',
}) 'preferedformat': kwagrs['preferedformat']
if 'preferredcodec' in kwagrs and kwagrs['preferredcodec']: })
postprocessor.append({ if 'preferredcodec' in kwagrs and kwagrs['preferredcodec']:
'key': 'FFmpegExtractAudio', postprocessor.append({
'preferredcodec': kwagrs['preferredcodec'], 'key': 'FFmpegExtractAudio',
'preferredquality': str(kwagrs['preferredquality']) 'preferredcodec': kwagrs['preferredcodec'],
}) 'preferredquality': str(kwagrs['preferredquality'])
if postprocessor: })
opts['postprocessors'] = postprocessor if postprocessor:
if 'archive' in kwagrs and kwagrs['archive']: opts['postprocessors'] = postprocessor
opts['download_archive'] = kwagrs['archive'] if 'archive' in kwagrs and kwagrs['archive']:
if 'proxy' in kwagrs and kwagrs['proxy']: opts['download_archive'] = kwagrs['archive']
opts['proxy'] = kwagrs['proxy'] if 'proxy' in kwagrs and kwagrs['proxy']:
if 'ffmpeg_path' in kwagrs and kwagrs['ffmpeg_path']: opts['proxy'] = kwagrs['proxy']
opts['ffmpeg_location'] = kwagrs['ffmpeg_path'] if 'ffmpeg_path' in kwagrs and kwagrs['ffmpeg_path']:
youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts) opts['ffmpeg_location'] = kwagrs['ffmpeg_path']
youtube_dl.key = kwagrs.get('key') dateafter = kwagrs.get('dateafter')
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가 youtube_dl = MyYoutubeDL(plugin, url, filename, temp_path, save_path, opts, dateafter)
return youtube_dl youtube_dl.key = kwagrs.get('key')
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
return youtube_dl
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
return None
@staticmethod @staticmethod
def get_data(youtube_dl): def get_data(youtube_dl):

View File

@@ -45,7 +45,9 @@ class MyYoutubeDL(object):
__index = 0 __index = 0
_last_msg = '' _last_msg = ''
def __init__(self, plugin, url, filename, temp_path, save_path=None, opts=None): def __init__(self, plugin, url, filename, temp_path, save_path=None, opts=None, dateafter=None, datebefore=None):
from youtube_dl.utils import DateRange
if save_path is None: if save_path is None:
save_path = temp_path save_path = temp_path
if opts is None: if opts is None:
@@ -60,6 +62,8 @@ class MyYoutubeDL(object):
os.makedirs(save_path) os.makedirs(save_path)
self.save_path = save_path self.save_path = save_path
self.opts = opts self.opts = opts
if dateafter or datebefore:
self.opts['daterange'] = DateRange(start=dateafter, end=datebefore)
self.index = MyYoutubeDL.__index self.index = MyYoutubeDL.__index
MyYoutubeDL.__index += 1 MyYoutubeDL.__index += 1
self.__status = Status.READY self.__status = Status.READY
@@ -97,6 +101,7 @@ class MyYoutubeDL(object):
def run(self): def run(self):
import youtube_dl import youtube_dl
import glob2 import glob2
try: try:
self.start_time = datetime.now() self.start_time = datetime.now()
self.status = Status.START self.status = Status.START
@@ -148,12 +153,14 @@ class MyYoutubeDL(object):
@staticmethod @staticmethod
def get_version(): def get_version():
import youtube_dl from youtube_dl.version import __version__
return youtube_dl.version.__version__
return __version__
@staticmethod @staticmethod
def get_info_dict(url, proxy=None): def get_info_dict(url, proxy=None):
import youtube_dl import youtube_dl
try: try:
ydl_opts = { ydl_opts = {
'simulate': True, 'simulate': True,
@@ -199,6 +206,7 @@ class MyYoutubeDL(object):
@status.setter @status.setter
def status(self, value): def status(self, value):
from .plugin import socketio_emit from .plugin import socketio_emit
self.__status = value self.__status = value
socketio_emit('status', self) socketio_emit('status', self)

View File

@@ -43,7 +43,7 @@ menu = {
} }
plugin_info = { plugin_info = {
'version': '1.6.11', 'version': '1.7.0',
'name': 'youtube-dl', 'name': 'youtube-dl',
'category_name': 'vod', 'category_name': 'vod',
'developer': 'joyfuI', 'developer': 'joyfuI',
@@ -112,7 +112,8 @@ def ajax(sub):
# UI 요청 # UI 요청
elif sub == 'ffmpeg_version': elif sub == 'ffmpeg_version':
path = request.form['path'] path = request.form['path']
ret = subprocess.check_output([path, '-version']).replace('\n', '<br>') ret = subprocess.check_output([path, '-version'])
ret = ret.decode().replace('\n', '<br>')
return jsonify(ret) return jsonify(ret)
elif sub == 'download': elif sub == 'download':
@@ -201,6 +202,7 @@ def api(sub):
preferedformat = request.values.get('preferedformat', None) preferedformat = request.values.get('preferedformat', None)
preferredcodec = request.values.get('preferredcodec', None) preferredcodec = request.values.get('preferredcodec', None)
preferredquality = request.values.get('preferredquality', 192) preferredquality = request.values.get('preferredquality', 192)
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)
ret = { ret = {
@@ -224,10 +226,13 @@ def api(sub):
preferedformat=preferedformat, preferedformat=preferedformat,
preferredcodec=preferredcodec, preferredcodec=preferredcodec,
preferredquality=preferredquality, preferredquality=preferredquality,
dateafter=dateafter,
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)
if youtube_dl is None:
return LogicNormal.abort(ret, 10) # 실패
ret['index'] = youtube_dl.index ret['index'] = youtube_dl.index
if start: if start:
youtube_dl.start() youtube_dl.start()