Browse Source

ytdl cache

thezero 2 years ago
parent
commit
ce01266238
2 changed files with 10 additions and 5 deletions
  1. 1 0
      docker-compose.yml
  2. 9 5
      src/vid_utils.py

+ 1 - 0
docker-compose.yml

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

+ 9 - 5
src/vid_utils.py

@@ -75,7 +75,7 @@ class Video:
 
     def download(self):
         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'):
             logger.info(line)
@@ -83,10 +83,14 @@ class Video:
                 self.file_name = line[24:]  # name of the file
 
     def check_dimension(self):
-        if os.path.getsize(self.file_name) > 50 * 1024 * 1023:
-            Popen(["split", "-b", "49M", self.file_name, self.file_name])
-            os.remove(self.file_name)
-        return glob(escape(self.file_name) + '*')
+        try:
+            if os.path.getsize(self.file_name) > 50 * 1024 * 1023:
+                Popen(["split", "-b", "49M", self.file_name, self.file_name])
+                os.remove(self.file_name)
+            return glob(escape(self.file_name) + '*')
+        except AttributeError as e:
+            logger.error(e)
+            return None
 
     @contextmanager
     def send(self):