]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/downloader/niconico.py
[downloader, cleanup] Refactor `report_progress`
[yt-dlp.git] / yt_dlp / downloader / niconico.py
index c5a3587a4b1a5b57ff3428fac889e5016d5a5345..77ed39e5b9c0992f6fa9045c3b1644358f2299b7 100644 (file)
@@ -1,26 +1,21 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import threading
 
+from . import get_suitable_downloader
 from .common import FileDownloader
-from ..downloader import _get_real_downloader
-from ..extractor.niconico import NiconicoIE
-from ..compat import compat_urllib_request
+from ..utils import sanitized_Request
 
 
 class NiconicoDmcFD(FileDownloader):
     """ Downloading niconico douga from DMC with heartbeat """
 
-    FD_NAME = 'niconico_dmc'
-
     def real_download(self, filename, info_dict):
-        self.to_screen('[%s] Downloading from DMC' % self.FD_NAME)
+        from ..extractor.niconico import NiconicoIE
 
+        self.to_screen('[%s] Downloading from DMC' % self.FD_NAME)
         ie = NiconicoIE(self.ydl)
         info_dict, heartbeat_info_dict = ie._get_heartbeat_info(info_dict)
 
-        fd = _get_real_downloader(info_dict, params=self.params)(self.ydl, self.params)
+        fd = get_suitable_downloader(info_dict, params=self.params)(self.ydl, self.params)
 
         success = download_complete = False
         timer = [None]
@@ -29,9 +24,11 @@ def real_download(self, filename, info_dict):
         heartbeat_data = heartbeat_info_dict['data'].encode()
         heartbeat_interval = heartbeat_info_dict.get('interval', 30)
 
+        request = sanitized_Request(heartbeat_url, heartbeat_data)
+
         def heartbeat():
             try:
-                compat_urllib_request.urlopen(url=heartbeat_url, data=heartbeat_data)
+                self.ydl.urlopen(request).read()
             except Exception:
                 self.to_screen('[%s] Heartbeat failed' % self.FD_NAME)
 
@@ -52,4 +49,4 @@ def heartbeat():
                 with heartbeat_lock:
                     timer[0].cancel()
                     download_complete = True
-            return success
+        return success