44import os
55import uuid
66import json
7+ import time
78
89from pytubefix import YouTube
910
@@ -58,8 +59,10 @@ def add(self, url: str):
5859 MetricsHandler .cache_size .set (len (self .video_id_to_path ))
5960 MetricsHandler .cache_size_bytes .set (self .current_size_bytes )
6061 video_file_name = video .default_filename
62+ start_time = time .time ()
6163 with MetricsHandler .download_time .time ():
6264 video .download (self .file_path )
65+ end_time = time .time ()
6366 MetricsHandler .data_downloaded .inc (video .filesize )
6467 MetricsHandler .video_download_count .inc ()
6568 video_id = self .get_video_id (url )
@@ -80,6 +83,9 @@ def add(self, url: str):
8083 self .current_size_bytes += video_info .size_bytes
8184 MetricsHandler .cache_size .set (len (self .video_id_to_path ))
8285 MetricsHandler .cache_size_bytes .set (self .current_size_bytes )
86+ #download rate are currently listed in bytes / second
87+ download_rate = (video .filesize / (end_time - start_time ))
88+ MetricsHandler .download_rate .set (download_rate )
8389
8490 def find (self , video_id : str ):
8591 if video_id in self .video_id_to_path :
@@ -158,4 +164,4 @@ def write_cache(self):
158164 def get_video_id (url ) -> str :
159165 parsed_url = urlparse (url )
160166 video_id = parse_qs (parsed_url .query )["v" ][0 ]
161- return video_id
167+ return video_id
0 commit comments