diff --git a/README.md b/README.md index 39d2dc5..89c89e1 100644 --- a/README.md +++ b/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)를 추가했습니다. -설정에서 취향껏 설정해서 사용하시면 됩니다. +설정에서 취향껏 골라서 사용하시면 됩니다. ## API ### 공통사항 @@ -53,7 +53,7 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 `errorCode` | 에러 코드 | Integer `info_dict` | 동영상 정보 | Object -동영상 정보(`info_dict` 키)에는 youtube-dl에서 생성한 info_dict 정보가 그대로 들어있습니다. 따라서 이 부분은 직접 주소를 넣어가며 반환되는 정보를 확인해보는게 좋습니다. +동영상 정보(`info_dict` 키)에는 youtube-dl에서 생성한 info_dict 정보가 그대로 들어있습니다. 따라서 이 부분은 직접 주소를 넣어가며 반환되는 정보를 확인해보는 게 좋습니다. 간단한 예로 `thumbnail` 키엔 썸네일 주소, `uploader` 키엔 업로더 이름, `title` 키엔 동영상 제목, `duration` 키엔 동영상 길이 등이 들어 있습니다. 그리고 만약 주소가 플레이리스트라면 `_type` 키에 `"playlist"`라는 값이 들어 있습니다. 이때는 `entries` 키에 리스트가 들어있어 동영상들의 제목과 ID를 확인할 수 있습니다. @@ -65,17 +65,20 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 `plugin` | 플러그인 이름 | O | String `key` | 임의의 키. 이후 다운로드를 제어할 때 이 키가 필요함 | 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 -`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 `preferredcodec` | 추출할 오디오 코덱. 가능한 값은 `"best"`, `"mp3"`, `"aac"`, `"flac"`, `"m4a"`, `"opus"`, `"vorbis"`, `"wav"`. 미지정 시 추출하지 않음 | X | String `preferredquality` | 추출한 오디오의 비트레이트. 0 ~ 9 사이의 VBR 퀄리티 값(0에 가까울수록 좋음) 혹은 특정 비트레이트 값. `preferredcodec` 키가 있을 때만 유효. 기본값: `192` | X | Integer `dateafter` | 지정한 날짜 이후에 업로드된 동영상만 다운로드. 미지정 시 모든 동영상 다운로드 | X | String -`archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있을 경우 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String +`archive` | 다운로드한 동영상의 ID를 기록할 파일 경로. 파일이 이미 있으면 이미 다운로드한 동영상은 다운로드 하지 않음. 미지정 시 기록하지 않음 | X | String `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 키 | 설명 | 타입 --- | --- | --- @@ -132,6 +135,11 @@ API를 제공합니다. 다른 플러그인에서 동영상 정보나 다운로 물론 해당 정보가 없으면 null입니다. ## Changelog +v2.1.0 +* download API에 cookiefile, headers 키 추가 + 카카오TV 동영상 다운로드에 활용할 수 있습니다. 잘하면 로봇 체크 패스에도 사용이 가능한 듯 싶습니다. + Thanks to [soju6jan](https://github.com/soju6jan) + v2.0.0 * youtube-dlc 추가 사용할 youtube-dl 패키지를 선택할 수 있습니다. 설정 변경 후 재시작해야 적용됩니다. @@ -218,7 +226,7 @@ v1.3.1 v1.3.0 * 후처리 기능 추가 이제 비디오 변환이나 오디오 추출이 가능합니다. - 오디오 추출의 경우 비트레이트는 192kbps로 설정되어 있습니다. + 오디오 추출의 비트레이트는 192kbps로 설정되어 있습니다. v1.2.5 * 기본 파일명 설정 추가 diff --git a/info.json b/info.json index 21833e4..fa542f4 100644 --- a/info.json +++ b/info.json @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/logic_normal.py b/logic_normal.py index cd20bb5..6483768 100644 --- a/logic_normal.py +++ b/logic_normal.py @@ -110,8 +110,11 @@ class LogicNormal(object): opts['proxy'] = kwagrs['proxy'] if 'ffmpeg_path' in kwagrs and kwagrs['ffmpeg_path']: opts['ffmpeg_location'] = kwagrs['ffmpeg_path'] + if 'cookiefile' in kwagrs and kwagrs['cookiefile']: + opts['cookiefile'] = kwagrs['cookiefile'] 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') LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가 return youtube_dl diff --git a/my_youtube_dl.py b/my_youtube_dl.py index fc56cfb..4f230e4 100644 --- a/my_youtube_dl.py +++ b/my_youtube_dl.py @@ -45,7 +45,7 @@ class MyYoutubeDL(object): __index = 0 _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 .plugin import YOUTUBE_DL_PACKAGE DateRange = __import__('%s.utils' % YOUTUBE_DL_PACKAGE, fromlist=['DateRange']).DateRange @@ -66,6 +66,7 @@ class MyYoutubeDL(object): self.opts = opts if dateafter or datebefore: self.opts['daterange'] = DateRange(start=dateafter, end=datebefore) + self.headers = headers self.index = MyYoutubeDL.__index MyYoutubeDL.__index += 1 self.__status = Status.READY @@ -109,8 +110,10 @@ class MyYoutubeDL(object): try: self.start_time = datetime.now() 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: self.status = Status.ERROR return @@ -164,11 +167,10 @@ class MyYoutubeDL(object): return __version__ @staticmethod - def get_info_dict(url, proxy=None): + def get_info_dict(url, proxy=None, cookiefile=None): # import youtube_dl from .plugin import YOUTUBE_DL_PACKAGE youtube_dl = __import__('%s' % YOUTUBE_DL_PACKAGE) - try: ydl_opts = { 'simulate': True, @@ -178,6 +180,8 @@ class MyYoutubeDL(object): } if proxy: ydl_opts['proxy'] = proxy + if cookiefile: + ydl_opts['cookiefile'] = cookiefile with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) except Exception as e: diff --git a/plugin.py b/plugin.py index 41392c2..8124958 100644 --- a/plugin.py +++ b/plugin.py @@ -5,6 +5,7 @@ import os import sys import traceback import subprocess +import json # third-party from flask import Blueprint, request, render_template, redirect, jsonify, abort @@ -44,7 +45,7 @@ menu = { } plugin_info = { - 'version': '2.0.0', + 'version': '2.1.0', 'name': 'youtube-dl', 'category_name': 'vod', 'developer': 'joyfuI', @@ -209,6 +210,8 @@ def api(sub): dateafter = request.values.get('dateafter', None) archive = request.values.get('archive', None) start = request.values.get('start', False) + cookiefile = request.values.get('cookiefile', None) + headers = request.values.get('headers', '{}') ret = { 'errorCode': 0, 'index': None @@ -234,7 +237,10 @@ def api(sub): archive=archive, proxy=ModelSetting.get('proxy'), 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: return LogicNormal.abort(ret, 10) # 실패 ret['index'] = youtube_dl.index diff --git a/templates/youtube-dl_download.html b/templates/youtube-dl_download.html index 2c6542d..c192cfd 100644 --- a/templates/youtube-dl_download.html +++ b/templates/youtube-dl_download.html @@ -33,9 +33,9 @@