From b683cae13f4af91fc14b4274833a91ee57a25661 Mon Sep 17 00:00:00 2001 From: kjy00302 Date: Mon, 1 Feb 2016 01:40:06 +0900 Subject: [PATCH] fix TODOs, remove 'unicode', more properties --- youtube_dl/extractor/__init__.py | 2 +- youtube_dl/extractor/tvple.py | 74 +++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 74283c743..edb051312 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -678,7 +678,7 @@ from .tvc import ( from .tvigle import TvigleIE from .tvp import TvpIE, TvpSeriesIE from .tvplay import TVPlayIE -from .tvple import tvpleIE +from .tvple import TvpleIE from .tweakers import TweakersIE from .twentyfourvideo import TwentyFourVideoIE from .twentytwotracks import ( diff --git a/youtube_dl/extractor/tvple.py b/youtube_dl/extractor/tvple.py index 47ab4f0b2..8f4dba638 100644 --- a/youtube_dl/extractor/tvple.py +++ b/youtube_dl/extractor/tvple.py @@ -3,11 +3,13 @@ from __future__ import unicode_literals from .common import InfoExtractor import re +import time +import datetime -class tvpleIE(InfoExtractor): +class TvpleIE(InfoExtractor): _VALID_URL = r'https?://(?P(?:www\.)?tvple\.com/(?P[0-9]+))' - _TEST = { + _TESTS = [{ 'url': 'http://tvple.com/311090', 'md5': '46329fca94a29b5517a30d7e88f48dbf', 'info_dict': { @@ -16,32 +18,42 @@ class tvpleIE(InfoExtractor): 'uploader': '[디지털 드럭] 나비붙이', 'uploader_id': 'jack1609', 'title': '팜플렛으로 yee를 연주하는 김병만', - 'description': '자작입니다. 첫 조교..인가..? 조교라긴 애매하지만, 어쨋든 노래로 만드는 건 이번이 처음입니다.\n원본 영상 출처: https://www.youtube.com/watch?v=E4BPHBL35dE\nyee는 유튜브에 치면 원본 영상이 나오는데 다들 아시죠??? 저작권 문제가 될 경우는 지우겠습니다...\n\n병만로이드라고 불러야 하나??' - # TODO more properties, either as: - # * A value - # * MD5 checksum; start the string with md5: - # * A regular expression; start the string with re: - # * Any Python type (for example int or float) + 'description': '자작입니다. 첫 조교..인가..? 조교라긴 애매하지만, 어쨋든 노래로 만드는 건 이번이 처음입니다.\n원본 영상 출처: https://www.youtube.com/watch?v=E4BPHBL35dE\nyee는 유튜브에 치면 원본 영상이 나오는데 다들 아시죠??? 저작권 문제가 될 경우는 지우겠습니다...\n\n병만로이드라고 불러야 하나??', + 'duration': 9 } - } + }, { + 'url': 'http://tvple.com/208230', + 'md5': '98e4f705fbb77b0ad9afe6e86751d89a', + 'info_dict': { + 'id': '208230', + 'ext': 'mp4', + 'uploader': 'mesenghe', + 'uploader_id': 'mesenghe', + 'title': '소환사 협곡의 개새끼', + 'description': 'http://youtu.be/LGABUervp48\n재밌게 봐라\n유튜브나 네이버 동영상으로 퍼가지 말고\n이젠 롤 관련된 건 안 만든다', + 'duration': 71 + } + }] def _convert_srt_subtitle(self, json, duration): + """convert tvple subtitle to srt subtitle""" sec = [] sub = "" timecode = [] text = [] for i in json: - sec.append(int(i)) + if(i != 'status'): + sec.append(int(i)) sec.sort() for second in sec: msec = [] - for i in json[unicode(second)]: + for i in json[str(second)]: msec.append(int(i)) msec.sort() for millisecond in msec: timecode.append("%02d:%02d:%02d,%03d" % (second // 60 // 60, second // 60 % 60, second % 60, millisecond)) - text.append(json[unicode(second)][unicode(millisecond)].replace('
', '\n').replace(' ', '')) + text.append(json[str(second)][str(millisecond)].replace('
', '\n').replace(' ', '')) timecode.append("%02d:%02d:%02d,%03d" % (duration // 60 // 60, duration // 60 % 60, duration % 60, int(("%0.3f" % duration)[-3:]))) @@ -50,6 +62,7 @@ class tvpleIE(InfoExtractor): return sub def _convert_ass_cloud(self, json, videoid, title, width, height): + """convert tvple cloud to ass subtitle""" sec = [] asstemp1 = "[Script Info]\nTitle: %s\nScriptType: v4.00+\nWrapStyle: 0\nPlayResX: %d\nPlayResY: %d\nScaledBorderAndShadow: yes\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\nStyle: Default,Arial,14,&H23FFFFFF,&H000000FF,&HC8000000,&HC8000000,-1,0,0,0,100,100,0,0,1,2,2,5,10,10,10,1\n\n" % (title + '-' + videoid, width, height) @@ -76,7 +89,7 @@ class tvpleIE(InfoExtractor): if json['cloud']['read_url'][0] != '': subs['tvple'].append({ 'ext': 'ass', - 'data': self._convert_ass_cloud(self._download_json(json['cloud']['read_url'][0], 'cloud_%d' % int(videoid)), videoid, title, width, height) + 'data': self._convert_ass_cloud(self._download_json(json['cloud']['read_url'], 'cloud_%d' % int(videoid)), videoid, title, width, height) }) if json['subtitle'] != '': @@ -96,22 +109,30 @@ class tvpleIE(InfoExtractor): uploader = re.search(r'personacon-sm".*/>\s*(.*)\s*', webpage).group(1) # username uploader_id = re.search(r'"/ch/(.*)/videos"', webpage).group(1) # userid description = re.search(r'collapse-content linkify mg-top-base break-word">\s*(.*)\s*