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
|
return True
|
||||||
|
|
||||||
def download(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None, title_exclude=[]):
|
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)
|
print "For backend %s, search for '%s'" % (backend_name, pattern)
|
||||||
|
|
||||||
# create directory for links
|
# create directory for links
|
||||||
|
|
@ -90,10 +89,11 @@ class Downloadboob:
|
||||||
os.makedirs(self.links_directory)
|
os.makedirs(self.links_directory)
|
||||||
|
|
||||||
# search for videos
|
# search for videos
|
||||||
count = 0
|
|
||||||
videos = []
|
videos = []
|
||||||
l = list(self.backend.search_videos(pattern, sortby, nsfw, max_results))
|
for i, video in enumerate(self.backend.search_videos(pattern, sortby, nsfw, max_results)):
|
||||||
for video in l:
|
if i == max_results:
|
||||||
|
break
|
||||||
|
|
||||||
if not self.is_downloaded(video):
|
if not self.is_downloaded(video):
|
||||||
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
||||||
if not(self.is_excluded(video.title, title_exclude)):
|
if not(self.is_excluded(video.title, title_exclude)):
|
||||||
|
|
@ -102,11 +102,9 @@ class Downloadboob:
|
||||||
else:
|
else:
|
||||||
print "Already downloaded, check %s" % video.id
|
print "Already downloaded, check %s" % video.id
|
||||||
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
|
||||||
self.set_linkname(video)
|
linkname = self.get_linkname(video)
|
||||||
|
if not os.path.exists(linkname):
|
||||||
count=count+1
|
self.remove_download(video)
|
||||||
if count == max_results:
|
|
||||||
break
|
|
||||||
|
|
||||||
# download videos
|
# download videos
|
||||||
print "Downloading..."
|
print "Downloading..."
|
||||||
|
|
@ -124,9 +122,8 @@ class Downloadboob:
|
||||||
directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
|
directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
|
||||||
else:
|
else:
|
||||||
directory = os.path.join(self.download_directory, self.backend_name)
|
directory = os.path.join(self.download_directory, self.backend_name)
|
||||||
|
if not os.path.exists(directory):
|
||||||
if not os.path.exists(directory):
|
os.makedirs(directory)
|
||||||
os.makedirs(directory)
|
|
||||||
|
|
||||||
ext = video.ext
|
ext = video.ext
|
||||||
if not ext:
|
if not ext:
|
||||||
|
|
@ -155,6 +152,19 @@ class Downloadboob:
|
||||||
return os.path.isfile(self.get_filename(video))
|
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):
|
def set_linkname(self, video):
|
||||||
linkname = self.get_linkname(video)
|
linkname = self.get_linkname(video)
|
||||||
idname = self.get_filename(video, relative=True)
|
idname = self.get_filename(video, relative=True)
|
||||||
|
|
@ -197,6 +207,7 @@ class Downloadboob:
|
||||||
args = ('wget', video.url, '-O', dest)
|
args = ('wget', video.url, '-O', dest)
|
||||||
|
|
||||||
os.spawnlp(os.P_WAIT, args[0], *args)
|
os.spawnlp(os.P_WAIT, args[0], *args)
|
||||||
|
self.set_linkname(video)
|
||||||
|
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue