Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hls-native] a grain of sand #6407

Closed
irtusb opened this issue Jul 29, 2015 · 3 comments
Closed

[hls-native] a grain of sand #6407

irtusb opened this issue Jul 29, 2015 · 3 comments

Comments

@irtusb
Copy link
Contributor

@irtusb irtusb commented Jul 29, 2015

The Following patch is meant to provide a bit more of user feedback while using the experimental hls-native downloader. It changes the current [hlsnative] downloading segment x/x for the usual [download] 1.1% of 185.00B at 170.38KiB/s ETA 06:46 where the amount of bytes is actually the number of video segments and the percentage is based on downloaded segments/total segments. ETA and speed are real values regardless segment number.

Lastly, the progress is still being updated at the end of each segment.

diff --git a/youtube_dl/downloader/hls.py b/youtube_dl/downloader/hls.py
index 8be4f42..1b4fb37 100644
--- a/youtube_dl/downloader/hls.py
+++ b/youtube_dl/downloader/hls.py
@@ -76,11 +76,15 @@ class NativeHlsFD(FileDownloader):
         is_test = self.params.get('test', False)
         remaining_bytes = self._TEST_FILE_SIZE if is_test else None
         byte_counter = 0
+        import time
+        start = time.time()
+        chunk_counter = 0
+        data_len = len(segment_urls)
         with open(tmpfilename, 'wb') as outf:
             for i, segurl in enumerate(segment_urls):
-                self.to_screen(
-                    '[hlsnative] %s: Downloading segment %d / %d' %
-                    (info_dict['id'], i + 1, len(segment_urls)))
+                #self.to_screen(
+                #    '[hlsnative] %s: Downloading segment %d / %d' %
+                #    (info_dict['id'], i + 1, len(segment_urls)))
                 seg_req = compat_urllib_request.Request(segurl)
                 if remaining_bytes is not None:
                     seg_req.add_header('Range', 'bytes=0-%d' % (remaining_bytes - 1))
@@ -91,6 +95,16 @@ class NativeHlsFD(FileDownloader):
                     remaining_bytes -= len(segment)
                 outf.write(segment)
                 byte_counter += len(segment)
+                chunk_counter += 1
+                self._hook_progress({
+                    'downloaded_bytes': chunk_counter,
+                    'total_bytes': len(segment_urls),
+                    'eta': self.calc_eta(start, time.time(), data_len, chunk_counter),
+                    'speed': self.calc_speed(start, time.time(), byte_counter),
+                    'tmpfilename': tmpfilename,
+                    'status': 'downloading',
+                    'elapsed': time.time() - start,
+                })
                 if remaining_bytes is not None and remaining_bytes <= 0:
                     break
@remitamine
Copy link
Collaborator

@remitamine remitamine commented Jul 29, 2015

this pull request #6392 created by dstftw already contains the change you want and more(it supports resuming the download in hls native...).

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Jul 30, 2015

Closing this because it's addressed in #6392, but thanks for the patch!

@jaimeMF jaimeMF closed this Jul 30, 2015
@irtusb
Copy link
Contributor Author

@irtusb irtusb commented Jul 30, 2015

ouch!, didn't notice it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.