[vlive] Add support for channels
authorping <liping.ong@gmail.com>
Tue, 24 Jan 2017 05:52:17 +0000 (13:52 +0800)
committerSergey M <dstftw@gmail.com>
Sat, 28 Jan 2017 11:50:38 +0000 (18:50 +0700)
youtube_dl/extractor/extractors.py
youtube_dl/extractor/vlive.py

index 81366f933dae069b98d33cca2a059ccec7f5fcad..c781c9b8726c24fa5b0a97e526d55e7898da2413 100644 (file)
@@ -1129,7 +1129,10 @@ from .vk import (
     VKUserVideosIE,
     VKWallPostIE,
 )
-from .vlive import VLiveIE
+from .vlive import (
+    VLiveIE,
+    VLiveChannelIE
+)
 from .vodlocker import VodlockerIE
 from .vodplatform import VODPlatformIE
 from .voicerepublic import VoiceRepublicIE
index 540246c79d8900feaada9921eb600a2f6695828d..70bab1f046e12ab100cdf9dd2b12ef3cebef7952 100644 (file)
@@ -2,6 +2,8 @@
 from __future__ import unicode_literals
 
 import re
+import time
+import itertools
 
 from .common import InfoExtractor
 from ..utils import (
@@ -169,3 +171,69 @@ class VLiveIE(InfoExtractor):
             'subtitles': subtitles,
         })
         return info
+
+
+class VLiveChannelIE(InfoExtractor):
+    IE_NAME = 'vlive:channel'
+    _VALID_URL = r'https?://channels\.vlive\.tv/(?P<id>[0-9A-Z]+)/video'
+    _TEST = {
+        'url': 'http://channels.vlive.tv/FCD4B/video',
+        'info_dict': {
+            'id': 'FCD4B',
+            'title': 'MAMAMOO',
+        },
+        'playlist_mincount': 110
+    }
+    _APP_ID = '8c6cc7b45d2568fb668be6e05b6e5a3b'
+
+    def _real_extract(self, url):
+        channel_code = self._match_id(url)
+
+        webpage = self._download_webpage(
+            'http://channels.vlive.tv/%s/video' % channel_code, channel_code)
+        app_js_url = self._search_regex(
+            r'(http[^\'\"\s]+app\.js)', webpage, 'app js', default='')
+
+        if app_js_url:
+            app_js = self._download_webpage(app_js_url, channel_code, 'app js')
+            app_id = self._search_regex(
+                r'Global\.VFAN_APP_ID\s*=\s*[\'"]([^\'"]+)[\'"]',
+                app_js, 'app id', default=self._APP_ID)
+        else:
+            app_id = self._APP_ID
+
+        channel_info = self._download_json(
+            'http://api.vfan.vlive.tv/vproxy/channelplus/decodeChannelCode',
+            channel_code, note='decode channel code',
+            query={'app_id': app_id, 'channelCode': channel_code, '_': int(time.time())})
+
+        channel_seq = channel_info['result']['channelSeq']
+        channel_name = None
+        entries = []
+
+        for page_num in itertools.count(1):
+            video_list = self._download_json(
+                'http://api.vfan.vlive.tv/vproxy/channelplus/getChannelVideoList',
+                channel_code, note='channel list %d' % page_num,
+                query={
+                    'app_id': app_id,
+                    'channelSeq': channel_seq,
+                    'maxNumOfRows': 1000,
+                    '_': int(time.time()),
+                    'pageNo': page_num
+                }
+            )
+            if not channel_name:
+                channel_name = video_list['result']['channelInfo']['channelName']
+
+            if not video_list['result'].get('videoList'):
+                break
+
+            for video in video_list['result']['videoList']:
+                video_id = str(video['videoSeq'])
+                entries.append(
+                    self.url_result(
+                        'http://www.vlive.tv/video/%s' % video_id, 'Vlive', video_id))
+
+        return self.playlist_result(
+            entries, channel_code, channel_name)