Browse Source

Stop saving files without the name (as in .jpg).

Nikola Kotur 10 years ago
parent
commit
5a03afd4da
1 changed files with 10 additions and 1 deletions
  1. 10 1
      reddrip/ripper/__init__.py

+ 10 - 1
reddrip/ripper/__init__.py

@@ -3,6 +3,8 @@ import logging
 import time
 import re
 import urlparse
+import string
+import random
 
 from redis.exceptions import ResponseError
 import requests
@@ -24,8 +26,15 @@ class Ripper(object):
 
         self.reddit = praw.Reddit(user_agent=self.agent)
 
+    def _random_name(self, size=10, chars=string.ascii_lowercase +
+                                          string.digits):
+        return ''.join(random.choice(chars) for x in range(size))
+
     def _clean_title(self, title):
-        return re.sub(r'([^\s\w]|_)+', '', title)[:128].lower()
+        title = re.sub(r'([^\s\w]|_)+', '', title)[:128].lower()
+        if len(title) < 4:
+            title = self._random_name()
+        return title
 
     def _get_ext(self, url):
         url_info = urlparse.urlparse(url)