2013-03-02 21:26:28 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2019-01-09 21:34:21 +01:00
|
|
|
import os
|
2013-02-12 19:15:11 +01:00
|
|
|
|
2014-04-21 16:50:24 +02:00
|
|
|
from svtplay_dl.fetcher import VideoRetriever
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.utils.output import ETA
|
2021-05-03 01:43:37 +02:00
|
|
|
from svtplay_dl.utils.output import formatname
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.utils.output import progressbar
|
2013-02-12 19:15:11 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-04-21 16:50:24 +02:00
|
|
|
class HTTP(VideoRetriever):
|
2018-05-25 22:47:26 +02:00
|
|
|
@property
|
2014-05-01 17:13:46 +02:00
|
|
|
def name(self):
|
|
|
|
return "http"
|
|
|
|
|
2014-04-21 16:50:24 +02:00
|
|
|
def download(self):
|
2021-12-18 21:37:09 +01:00
|
|
|
"""Get the stream from HTTP"""
|
2019-01-09 21:34:21 +01:00
|
|
|
_, ext = os.path.splitext(self.url)
|
|
|
|
if ext == ".mp3":
|
2021-05-03 01:43:37 +02:00
|
|
|
self.output["ext"] = "mp3"
|
2019-01-09 21:34:21 +01:00
|
|
|
else:
|
2021-05-03 01:43:37 +02:00
|
|
|
self.output["ext"] = "mp4" # this might be wrong..
|
2015-08-31 19:45:15 +02:00
|
|
|
data = self.http.request("get", self.url, stream=True)
|
2014-04-21 16:50:24 +02:00
|
|
|
try:
|
2019-08-25 00:27:31 +02:00
|
|
|
total_size = data.headers["content-length"]
|
2014-04-21 16:50:24 +02:00
|
|
|
except KeyError:
|
|
|
|
total_size = 0
|
|
|
|
total_size = int(total_size)
|
|
|
|
bytes_so_far = 0
|
2014-08-20 20:27:45 +02:00
|
|
|
|
2021-05-03 01:43:37 +02:00
|
|
|
filename = formatname(self.output, self.config)
|
|
|
|
file_d = open(filename, "wb")
|
2013-02-12 19:15:11 +01:00
|
|
|
|
2016-03-20 00:30:43 +01:00
|
|
|
eta = ETA(total_size)
|
2015-08-30 14:41:59 +02:00
|
|
|
for i in data.iter_content(8192):
|
|
|
|
bytes_so_far += len(i)
|
|
|
|
file_d.write(i)
|
2018-10-28 22:36:09 +01:00
|
|
|
if not self.config.get("silent"):
|
2016-03-20 00:30:43 +01:00
|
|
|
eta.update(bytes_so_far)
|
2019-08-25 00:27:31 +02:00
|
|
|
progressbar(total_size, bytes_so_far, "".join(["ETA: ", str(eta)]))
|
2013-02-12 19:15:11 +01:00
|
|
|
|
2017-11-24 23:11:48 +01:00
|
|
|
file_d.close()
|
|
|
|
self.finished = True
|