Fixed bug causing filename to truncate word.
Browse filesfilename sanitizing function was causing the last word in the filename
to get truncated.
- youtube/youtube.py +4 -4
youtube/youtube.py
CHANGED
@@ -71,7 +71,7 @@ class Video(object):
|
|
71 |
"""
|
72 |
response = urlopen(self.url)
|
73 |
#TODO: Allow a destination path to be specified.
|
74 |
-
dst_file = open(self.filename, 'wb')
|
75 |
meta_data = response.info()
|
76 |
file_size = int(meta_data.getheaders("Content-Length")[0])
|
77 |
print "Downloading: %s Bytes: %s" % (self.filename, file_size)
|
@@ -282,15 +282,15 @@ class YouTube(object):
|
|
282 |
return url[0]
|
283 |
|
284 |
|
285 |
-
def sanitize_filename(text):
|
286 |
"""
|
287 |
Sanitizes filenames for many operating systems.
|
288 |
|
289 |
Keyword arguments:
|
290 |
text -- The unsanitized pending filename.
|
291 |
"""
|
292 |
-
#
|
293 |
-
truncate = lambda text: text[:
|
294 |
|
295 |
#NTFS forbids characters in range 0-31 (0x00-0x1F)
|
296 |
ntfs = [chr(i) for i in range(0, 31)]
|
|
|
71 |
"""
|
72 |
response = urlopen(self.url)
|
73 |
#TODO: Allow a destination path to be specified.
|
74 |
+
dst_file = open('/Users/nickficano/Downloads/PyCon/' + self.filename, 'wb')
|
75 |
meta_data = response.info()
|
76 |
file_size = int(meta_data.getheaders("Content-Length")[0])
|
77 |
print "Downloading: %s Bytes: %s" % (self.filename, file_size)
|
|
|
282 |
return url[0]
|
283 |
|
284 |
|
285 |
+
def sanitize_filename(text, max_length=200):
|
286 |
"""
|
287 |
Sanitizes filenames for many operating systems.
|
288 |
|
289 |
Keyword arguments:
|
290 |
text -- The unsanitized pending filename.
|
291 |
"""
|
292 |
+
#Quick way of truncating long filenames.
|
293 |
+
truncate = lambda text: text[:max_length].rsplit(' ', 0)[0]
|
294 |
|
295 |
#NTFS forbids characters in range 0-31 (0x00-0x1F)
|
296 |
ntfs = [chr(i) for i in range(0, 31)]
|