ytdl cache

This commit is contained in:
thezero 2021-06-20 11:07:37 +02:00
parent 5061236b58
commit ce01266238
2 changed files with 10 additions and 5 deletions

View File

@ -8,4 +8,5 @@ services:
- ./conf:/bot/conf - ./conf:/bot/conf
environment: environment:
- CONF_FOLDER=/bot/conf/ - CONF_FOLDER=/bot/conf/
- XDG_CACHE_HOME=/bot/out/.cache
user: 1000:1000 user: 1000:1000

View File

@ -75,7 +75,7 @@ class Video:
def download(self): def download(self):
logger.info("Downloading {}".format(self.link)) logger.info("Downloading {}".format(self.link))
p = Popen(["youtube-dl", "-f", self.code, self.link], stdout=PIPE, stderr=PIPE).communicate() p = Popen(["youtube-dl", "-o", "/bot/out/%(title)s-%(id)s.%(ext)s", "-f", self.code, self.link], stdout=PIPE, stderr=PIPE).communicate()
for line in str(p[0], 'utf-8').split('\n'): for line in str(p[0], 'utf-8').split('\n'):
logger.info(line) logger.info(line)
@ -83,10 +83,14 @@ class Video:
self.file_name = line[24:] # name of the file self.file_name = line[24:] # name of the file
def check_dimension(self): def check_dimension(self):
if os.path.getsize(self.file_name) > 50 * 1024 * 1023: try:
Popen(["split", "-b", "49M", self.file_name, self.file_name]) if os.path.getsize(self.file_name) > 50 * 1024 * 1023:
os.remove(self.file_name) Popen(["split", "-b", "49M", self.file_name, self.file_name])
return glob(escape(self.file_name) + '*') os.remove(self.file_name)
return glob(escape(self.file_name) + '*')
except AttributeError as e:
logger.error(e)
return None
@contextmanager @contextmanager
def send(self): def send(self):