From a43a01a5cf3a1353df143774d0668cf736f43df6 Mon Sep 17 00:00:00 2001 From: Fabien Grumelard Date: Thu, 7 Feb 2013 16:40:22 +0100 Subject: [PATCH] Add a "id_regexp" parameter to filter results on video id Signed-off-by: Fabien Grumelard --- contrib/downloadboob/README | 3 ++- contrib/downloadboob/downloadboob.conf | 7 +++++++ contrib/downloadboob/downloadboob.py | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/contrib/downloadboob/README b/contrib/downloadboob/README index 4d7980eb..56e7c356 100644 --- a/contrib/downloadboob/README +++ b/contrib/downloadboob/README @@ -10,6 +10,7 @@ For each entry in the configuration file, the script : In each section of the configuration file : - backend : the backend to use - 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 - directory : the above. diff --git a/contrib/downloadboob/downloadboob.conf b/contrib/downloadboob/downloadboob.conf index 4c4f5ced..cac31a51 100644 --- a/contrib/downloadboob/downloadboob.conf +++ b/contrib/downloadboob/downloadboob.conf @@ -14,3 +14,10 @@ max_results=10 pattern=les guignols de l'info title_exclude=la semaine directory=Les guignols de l'info + +[ondar] +backend=francetelevisions +max_results=20 +pattern=demande +id_regexp=on_n.*rire +directory=ONDAR diff --git a/contrib/downloadboob/downloadboob.py b/contrib/downloadboob/downloadboob.py index dc997354..b198ad7c 100755 --- a/contrib/downloadboob/downloadboob.py +++ b/contrib/downloadboob/downloadboob.py @@ -80,7 +80,7 @@ class Downloadboob: else: 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) # create directory for links @@ -96,7 +96,7 @@ class Downloadboob: if not self.is_downloaded(video): 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) videos.append(video) else: @@ -117,6 +117,11 @@ class Downloadboob: return True 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): if relative: 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('|') else: 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") section_sublinks_directory=config.get(section,"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.purge() # 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)