correctly create symlink and support when one is removed
- when a video is downloaded, create immediately a symlink - if a symlink is removed, empty the downloaded file to free space on disk
This commit is contained in:
parent
572890b386
commit
df1652f25f
1 changed files with 23 additions and 12 deletions
35
contrib/downloadboob/downloadboob.py
Normal file → Executable file
35
contrib/downloadboob/downloadboob.py
Normal file → Executable file
|
|
@ -81,7 +81,6 @@ class Downloadboob:
|
|||
return True
|
||||
|
||||
def download(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None, title_exclude=[]):
|
||||
|
||||
print "For backend %s, search for '%s'" % (backend_name, pattern)
|
||||
|
||||
# create directory for links
|
||||
|
|
@ -90,10 +89,11 @@ class Downloadboob:
|
|||
os.makedirs(self.links_directory)
|
||||
|
||||
# search for videos
|
||||
count = 0
|
||||
videos = []
|
||||
l = list(self.backend.search_videos(pattern, sortby, nsfw, max_results))
|
||||
for video in l:
|
||||
for i, video in enumerate(self.backend.search_videos(pattern, sortby, nsfw, max_results)):
|
||||
if i == max_results:
|
||||
break
|
||||
|
||||
if not self.is_downloaded(video):
|
||||
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
||||
if not(self.is_excluded(video.title, title_exclude)):
|
||||
|
|
@ -102,11 +102,9 @@ class Downloadboob:
|
|||
else:
|
||||
print "Already downloaded, check %s" % video.id
|
||||
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
||||
self.set_linkname(video)
|
||||
|
||||
count=count+1
|
||||
if count == max_results:
|
||||
break
|
||||
linkname = self.get_linkname(video)
|
||||
if not os.path.exists(linkname):
|
||||
self.remove_download(video)
|
||||
|
||||
# download videos
|
||||
print "Downloading..."
|
||||
|
|
@ -124,9 +122,8 @@ class Downloadboob:
|
|||
directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
|
||||
else:
|
||||
directory = os.path.join(self.download_directory, self.backend_name)
|
||||
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
ext = video.ext
|
||||
if not ext:
|
||||
|
|
@ -155,6 +152,19 @@ class Downloadboob:
|
|||
return os.path.isfile(self.get_filename(video))
|
||||
|
||||
|
||||
def remove_download(self, video):
|
||||
path = self.get_filename(video)
|
||||
if os.stat(path).st_size == 0:
|
||||
# already empty
|
||||
return
|
||||
|
||||
print 'Remove video %s' % video.title
|
||||
|
||||
# Empty it to keep information we have already downloaded it.
|
||||
with open(path, 'w'):
|
||||
pass
|
||||
|
||||
|
||||
def set_linkname(self, video):
|
||||
linkname = self.get_linkname(video)
|
||||
idname = self.get_filename(video, relative=True)
|
||||
|
|
@ -197,6 +207,7 @@ class Downloadboob:
|
|||
args = ('wget', video.url, '-O', dest)
|
||||
|
||||
os.spawnlp(os.P_WAIT, args[0], *args)
|
||||
self.set_linkname(video)
|
||||
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue