Add a "id_regexp" parameter to filter results on video id
Signed-off-by: Fabien Grumelard <fabix-symlink@grumi.net>
This commit is contained in:
parent
3296d57132
commit
a43a01a5cf
3 changed files with 21 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ For each entry in the configuration file, the script :
|
||||||
In each section of the configuration file :
|
In each section of the configuration file :
|
||||||
- backend : the backend to use
|
- backend : the backend to use
|
||||||
- pattern : specify the search pattern
|
- pattern : specify the search pattern
|
||||||
- title_exclude : a coma seperated list. If an item in this list is substring of the title, then the video is ignored.
|
- title_exclude : a pipe seperated list. If an item in this list is substring of the title, then the video is ignored.
|
||||||
|
- id_regexp : an optional regular expression that the video id must match
|
||||||
- max_results : maximum number of result to parse
|
- max_results : maximum number of result to parse
|
||||||
- directory : the <user specify name> above.
|
- directory : the <user specify name> above.
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,10 @@ max_results=10
|
||||||
pattern=les guignols de l'info
|
pattern=les guignols de l'info
|
||||||
title_exclude=la semaine
|
title_exclude=la semaine
|
||||||
directory=Les guignols de l'info
|
directory=Les guignols de l'info
|
||||||
|
|
||||||
|
[ondar]
|
||||||
|
backend=francetelevisions
|
||||||
|
max_results=20
|
||||||
|
pattern=demande
|
||||||
|
id_regexp=on_n.*rire
|
||||||
|
directory=ONDAR
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class Downloadboob:
|
||||||
else:
|
else:
|
||||||
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=[], id_regexp=None):
|
||||||
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
|
||||||
|
|
@ -96,7 +96,7 @@ class Downloadboob:
|
||||||
|
|
||||||
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.lower(), title_exclude)):
|
if not(self.is_excluded(video.title.lower(), title_exclude)) and self.id_regexp_matched(video.id, id_regexp):
|
||||||
print " %s\n Id:%s\n Duration:%s" % (video.title, video.id, video.duration)
|
print " %s\n Id:%s\n Duration:%s" % (video.title, video.id, video.duration)
|
||||||
videos.append(video)
|
videos.append(video)
|
||||||
else:
|
else:
|
||||||
|
|
@ -117,6 +117,11 @@ class Downloadboob:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def id_regexp_matched(self, video_id, id_regexp):
|
||||||
|
if id_regexp:
|
||||||
|
return re.search(id_regexp, video_id) != None
|
||||||
|
return True
|
||||||
|
|
||||||
def get_filename(self, video, relative=False):
|
def get_filename(self, video, relative=False):
|
||||||
if relative:
|
if relative:
|
||||||
directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
|
directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
|
||||||
|
|
@ -228,6 +233,10 @@ for section in config.sections():
|
||||||
title_exclude=config.get(section, "title_exclude").split('|')
|
title_exclude=config.get(section, "title_exclude").split('|')
|
||||||
else:
|
else:
|
||||||
title_exclude=[]
|
title_exclude=[]
|
||||||
|
if config.has_option(section, "id_regexp"):
|
||||||
|
id_regexp=config.get(section, "id_regexp")
|
||||||
|
else:
|
||||||
|
id_regexp=None
|
||||||
max_result=config.getint(section, "max_results")
|
max_result=config.getint(section, "max_results")
|
||||||
section_sublinks_directory=config.get(section,"directory")
|
section_sublinks_directory=config.get(section,"directory")
|
||||||
section_links_directory=os.path.join(links_directory, section_sublinks_directory)
|
section_links_directory=os.path.join(links_directory, section_sublinks_directory)
|
||||||
|
|
@ -235,4 +244,4 @@ for section in config.sections():
|
||||||
downloadboob = Downloadboob(backend_name, download_directory, section_links_directory)
|
downloadboob = Downloadboob(backend_name, download_directory, section_links_directory)
|
||||||
downloadboob.purge()
|
downloadboob.purge()
|
||||||
# FIXME sortBy, title.match
|
# FIXME sortBy, title.match
|
||||||
downloadboob.download(pattern, ICapVideo.SEARCH_DATE, False, max_result, title_exclude)
|
downloadboob.download(pattern, ICapVideo.SEARCH_DATE, False, max_result, title_exclude, id_regexp)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue