From d7f84df528228ed663c527b04552c971c695058b Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Fri, 17 Jun 2016 10:20:30 +0530 Subject: [PATCH 01/21] youtube plguin can now save playlists. --- plugins/youtube.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 5d7abf5..00a1736 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -86,6 +86,15 @@ def queue(data,what,param): f.write(',') return '{0} added to download queue'.format(str(what)) + +@plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') +def saveplaylist(data, playid): + open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + return 'Saved playid {0}'.format(playid) + +#def continueplaylist(): +# link_downloader + @plgn.command('begin') def begin(data,what = None): if not os.access(plgn.queued_links,os.F_OK): @@ -180,7 +189,7 @@ def init(config): plgn.location = unicode(config['location']) plgn.location_video = plgn.location + config['outtmpl'] plgn.queued_links = config['queue_file'] - #plgn.playlists o= open(config['playlists']).read().split('/n') + plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From a97619ae265b29bb932841946d9f20fd236b34fc Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:11:04 +0530 Subject: [PATCH 02/21] command first letter is only case-optioned if its an alpha --- lib.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib.py b/lib.py index e00baee..3925c0b 100644 --- a/lib.py +++ b/lib.py @@ -214,9 +214,17 @@ def wrapper(config=None): self.setup = wrapper return wrapper - def command(self, regex, help=''): + def command(self, regex, help=''): + #a.='qwertyuiopasdfghjklzxcvbnm' + #a+a.upper() + #print sorted(a+a.upper()) + #['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + # 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + #'m', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] def wrapper(func): - rx ='['+regex[0]+regex[0].upper()+']'+regex[1:] + rx = regex + if regex[0].lower() in 'qwertyuiopasdfghjklzxcvbnm': + rx ='['+regex[0]+regex[0].upper()+']'+regex[1:] self.funcs.setdefault(rx , (func, help or regex.split()[0] )) return func return wrapper From 54605dc6c8aa063d8e827c14f952f4f09a768a5a Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:12:56 +0530 Subject: [PATCH 03/21] bugfixes in youtube plugin. - by default location is assumed to be current location - using os.sep to join paths - queue_file param is optional and is assumed to be in current dir. --- plugins/youtube.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 00a1736..f708ce4 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,7 +89,7 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) return 'Saved playid {0}'.format(playid) #def continueplaylist(): @@ -186,9 +186,9 @@ def listings(data,what=None): @plgn.setupmethod def init(config): - plgn.location = unicode(config['location']) - plgn.location_video = plgn.location + config['outtmpl'] - plgn.queued_links = config['queue_file'] + plgn.location = unicode(config.get('location', '.')) + plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) + plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From c05ea4f68e9bddb4dbbba5659bbfcd8c6241b9cf Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 14:44:15 +0530 Subject: [PATCH 04/21] [youtube] download playlist. playlistids are saved in a local file and every hour the download is fired. --- plugins/youtube.py | 20 ++++++++++++++++---- threadpool.py | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index f708ce4..f86a63a 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,11 +89,21 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) - return 'Saved playid {0}'.format(playid) + if playid in [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i != None]: + return 'playid {0} exists'.format(playid) + open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) + return 'Saved playid {0}'.format(playid) + +@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) +def continueplaylist(): + playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] + for i in playids: + try: + link_downloader(i, 'a') + except: + pass + -#def continueplaylist(): -# link_downloader @plgn.command('begin') def begin(data,what = None): @@ -190,6 +200,8 @@ def init(config): plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') + if not os.path.exists(plgn.playlistsfile): + open(plgn.playlistsfile,'w') plgn.old = [] plgn.new = [] diff --git a/threadpool.py b/threadpool.py index 7ee0137..c80a4d5 100644 --- a/threadpool.py +++ b/threadpool.py @@ -55,7 +55,6 @@ def add_task(self, func, *args, **kargs): """Add a task to the queue""" # logger.info('added tasks') try: - logger.debug("added tasks name :%s"%func.__name__) self.tasks.put((func, args, kargs), block=False) except Full, e: if ALLOW_SCALLING: @@ -76,6 +75,7 @@ def waiter(): logger.info('thread for %s returning' % func.__name__) return self.add_task(func, *args, **kwargs) + logger.debug("added tasks name :%s"%func.__name__) self.add_task(waiter) def wait_completion(self): From 0e167fd858604f51fd2ddbeaaec260018b3f0988 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Fri, 17 Jun 2016 10:20:30 +0530 Subject: [PATCH 05/21] youtube plguin can now save playlists. --- plugins/youtube.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 24b1e22..6f5b148 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -86,6 +86,15 @@ def queue(data,what,param): f.write(',') return '{0} added to download queue'.format(str(what)) + +@plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') +def saveplaylist(data, playid): + open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + return 'Saved playid {0}'.format(playid) + +#def continueplaylist(): +# link_downloader + @plgn.command('begin') def begin(data,what = None): if not os.access(plgn.queued_links,os.F_OK): @@ -180,7 +189,7 @@ def init(config): plgn.location = unicode(config['location']) plgn.location_video = plgn.location + config['outtmpl'] plgn.queued_links = config['queue_file'] - #plgn.playlists o= open(config['playlists']).read().split('/n') + plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From cfdd64b3a156d522b33398d281eae88dfa32992e Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:11:04 +0530 Subject: [PATCH 06/21] command first letter is only case-optioned if its an alpha --- lib.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib.py b/lib.py index d8754ae..13aced0 100644 --- a/lib.py +++ b/lib.py @@ -240,10 +240,12 @@ def wrapper(config=None): self.setup = wrapper return wrapper - def command(self, regex, help='', private_only=False, restrict_to=None): + def command(self, regex, help=''): def wrapper(func): - rx ='^['+regex[0]+regex[0].upper()+']'+regex[1:] +'$' - self.funcs.setdefault(rx , (func, help or regex.split()[0], private_only, restrict_to)) + rx = regex + if regex[0].lower() in 'qwertyuiopasdfghjklzxcvbnm': + rx ='['+regex[0]+regex[0].upper()+']'+regex[1:] + self.funcs.setdefault(rx , (func, help or regex.split()[0] )) return func return wrapper From be864b0d6e8c8212f2fab960407fcd02f9f6692d Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:12:56 +0530 Subject: [PATCH 07/21] bugfixes in youtube plugin. - by default location is assumed to be current location - using os.sep to join paths - queue_file param is optional and is assumed to be in current dir. --- plugins/youtube.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 6f5b148..54b027f 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,7 +89,7 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) return 'Saved playid {0}'.format(playid) #def continueplaylist(): @@ -186,9 +186,9 @@ def listings(data,what=None): @plgn.setupmethod def init(config): - plgn.location = unicode(config['location']) - plgn.location_video = plgn.location + config['outtmpl'] - plgn.queued_links = config['queue_file'] + plgn.location = unicode(config.get('location', '.')) + plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) + plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From a2078ca65306d62dffc3760b6c81004a6724e165 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 14:44:15 +0530 Subject: [PATCH 08/21] [youtube] download playlist. playlistids are saved in a local file and every hour the download is fired. --- plugins/youtube.py | 20 ++++++++++++++++---- threadpool.py | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 54b027f..84b0981 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,11 +89,21 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) - return 'Saved playid {0}'.format(playid) + if playid in [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i != None]: + return 'playid {0} exists'.format(playid) + open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) + return 'Saved playid {0}'.format(playid) + +@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) +def continueplaylist(): + playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] + for i in playids: + try: + link_downloader(i, 'a') + except: + pass + -#def continueplaylist(): -# link_downloader @plgn.command('begin') def begin(data,what = None): @@ -190,6 +200,8 @@ def init(config): plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') + if not os.path.exists(plgn.playlistsfile): + open(plgn.playlistsfile,'w') plgn.old = [] plgn.new = [] diff --git a/threadpool.py b/threadpool.py index 7ee0137..c80a4d5 100644 --- a/threadpool.py +++ b/threadpool.py @@ -55,7 +55,6 @@ def add_task(self, func, *args, **kargs): """Add a task to the queue""" # logger.info('added tasks') try: - logger.debug("added tasks name :%s"%func.__name__) self.tasks.put((func, args, kargs), block=False) except Full, e: if ALLOW_SCALLING: @@ -76,6 +75,7 @@ def waiter(): logger.info('thread for %s returning' % func.__name__) return self.add_task(func, *args, **kwargs) + logger.debug("added tasks name :%s"%func.__name__) self.add_task(waiter) def wait_completion(self): From 384f7536aeba5e11a3750c41f7c66c86400f9519 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Fri, 17 Jun 2016 10:20:30 +0530 Subject: [PATCH 09/21] youtube plguin can now save playlists. --- plugins/youtube.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 24b1e22..6f5b148 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -86,6 +86,15 @@ def queue(data,what,param): f.write(',') return '{0} added to download queue'.format(str(what)) + +@plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') +def saveplaylist(data, playid): + open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + return 'Saved playid {0}'.format(playid) + +#def continueplaylist(): +# link_downloader + @plgn.command('begin') def begin(data,what = None): if not os.access(plgn.queued_links,os.F_OK): @@ -180,7 +189,7 @@ def init(config): plgn.location = unicode(config['location']) plgn.location_video = plgn.location + config['outtmpl'] plgn.queued_links = config['queue_file'] - #plgn.playlists o= open(config['playlists']).read().split('/n') + plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From 5421eb3c7e5f10f674ca83ce71984087d0528319 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:11:04 +0530 Subject: [PATCH 10/21] command first letter is only case-optioned if its an alpha --- lib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib.py b/lib.py index d8754ae..acd3b9b 100644 --- a/lib.py +++ b/lib.py @@ -242,7 +242,9 @@ def wrapper(config=None): def command(self, regex, help='', private_only=False, restrict_to=None): def wrapper(func): - rx ='^['+regex[0]+regex[0].upper()+']'+regex[1:] +'$' + rx = regex + if regex[0].lower() in 'qwertyuiopasdfghjklzxcvbnm': + rx ='['+regex[0]+regex[0].upper()+']'+regex[1:] self.funcs.setdefault(rx , (func, help or regex.split()[0], private_only, restrict_to)) return func return wrapper From 44a595329771676178e577500ae9f031e02c24f8 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:12:56 +0530 Subject: [PATCH 11/21] bugfixes in youtube plugin. - by default location is assumed to be current location - using os.sep to join paths - queue_file param is optional and is assumed to be in current dir. --- plugins/youtube.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 6f5b148..54b027f 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,7 +89,7 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plg.playlistsfile,'a').write('\n%s'.format(playid)) + open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) return 'Saved playid {0}'.format(playid) #def continueplaylist(): @@ -186,9 +186,9 @@ def listings(data,what=None): @plgn.setupmethod def init(config): - plgn.location = unicode(config['location']) - plgn.location_video = plgn.location + config['outtmpl'] - plgn.queued_links = config['queue_file'] + plgn.location = unicode(config.get('location', '.')) + plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) + plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') plgn.old = [] plgn.new = [] From 3cf81a6511c9a6ae20c7aa24be332d1ab9deef7e Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 14:44:15 +0530 Subject: [PATCH 12/21] [youtube] download playlist. playlistids are saved in a local file and every hour the download is fired. --- plugins/youtube.py | 20 ++++++++++++++++---- threadpool.py | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 54b027f..84b0981 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -89,11 +89,21 @@ def queue(data,what,param): @plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') def saveplaylist(data, playid): - open(plgn.playlistsfile,'a').write('\n%s'.format(playid)) - return 'Saved playid {0}'.format(playid) + if playid in [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i != None]: + return 'playid {0} exists'.format(playid) + open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) + return 'Saved playid {0}'.format(playid) + +@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) +def continueplaylist(): + playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] + for i in playids: + try: + link_downloader(i, 'a') + except: + pass + -#def continueplaylist(): -# link_downloader @plgn.command('begin') def begin(data,what = None): @@ -190,6 +200,8 @@ def init(config): plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) plgn.queued_links = config.get('queue_file', 'queue.txt') plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') + if not os.path.exists(plgn.playlistsfile): + open(plgn.playlistsfile,'w') plgn.old = [] plgn.new = [] diff --git a/threadpool.py b/threadpool.py index 7ee0137..c80a4d5 100644 --- a/threadpool.py +++ b/threadpool.py @@ -55,7 +55,6 @@ def add_task(self, func, *args, **kargs): """Add a task to the queue""" # logger.info('added tasks') try: - logger.debug("added tasks name :%s"%func.__name__) self.tasks.put((func, args, kargs), block=False) except Full, e: if ALLOW_SCALLING: @@ -76,6 +75,7 @@ def waiter(): logger.info('thread for %s returning' % func.__name__) return self.add_task(func, *args, **kwargs) + logger.debug("added tasks name :%s"%func.__name__) self.add_task(waiter) def wait_completion(self): From 1dac8ec072748e6acea9ee105bcf6fa6e8d355d4 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Fri, 17 Jun 2016 10:20:30 +0530 Subject: [PATCH 13/21] youtube plguin can now save playlists. --- plugins/youtube.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 84b0981..9176c14 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -1,12 +1,20 @@ import time,os,subprocess import sys import logging +from logging.handlers import RotatingFileHandler import re,youtube_dl,getpass,os from lib import Plugin, cron logger = logging.getLogger('bot.youtube') logger.setLevel(logging.DEBUG) plgn = Plugin('youtube') +ydl_handler = RotatingFileHandler('youtubedl.log', 'a', 1 * 1024 * 1024) +ydl_handler.propagate = False +ydl_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s')) +ydl_logger = logging.getLogger('youtubedl') +ydl_logger.addHandler(ydl_handler) +ydl_logger.setLevel(logging.DEBUG) + @plgn.command('tell') def tell(data,what=None): string = """Follow the following commands : @@ -41,9 +49,10 @@ def link_downloader(*a): args = [str(i) for i in a] y = { 'outtmpl':plgn.location_video, - 'logger':logger, + 'logger':ydl_logger, 'nooverwrites':'True' } + logger.debug(y['outtmpl']) if len(args)>1 and (args[1] == 'a' or args[1]=='A'): y.update({ 'format': 'bestaudio/best', @@ -52,6 +61,8 @@ def link_downloader(*a): 'preferredcodec': 'mp3', 'preferredquality': '192',}] }) + if len(args)>2 and ('k' in args[2].lower()): + y.update({ 'keepvideo':True }) link = str(args[0]) ydl= youtube_dl.YoutubeDL(y) try: @@ -87,21 +98,23 @@ def queue(data,what,param): return '{0} added to download queue'.format(str(what)) -@plgn.command('^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)(?:&|$)') +@plgn.command('<(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)>') def saveplaylist(data, playid): if playid in [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i != None]: return 'playid {0} exists'.format(playid) open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) return 'Saved playid {0}'.format(playid) -@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) -def continueplaylist(): +#@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) + +@plgn.command('startplaylist') +def continueplaylist(*args, **kwargs): playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] + logger.debug(playids) for i in playids: - try: - link_downloader(i, 'a') - except: - pass + logger.debug('starting for id->' + i) + link_downloader(i, *'ak') + @@ -195,13 +208,14 @@ def listings(data,what=None): @plgn.setupmethod -def init(config): - plgn.location = unicode(config.get('location', '.')) - plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) - plgn.queued_links = config.get('queue_file', 'queue.txt') - plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') - if not os.path.exists(plgn.playlistsfile): - open(plgn.playlistsfile,'w') +def init(config=None): + if config is not None: # Anything except None will let you in. + plgn.location = unicode(config['location']) + plgn.location_video = os.sep.join([plgn.location , config['outtmpl']]) + plgn.queued_links = config.get('queue_file', 'queue.txt') + plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') + if not os.path.exists(plgn.playlistsfile): + open(plgn.playlistsfile,'w') plgn.old = [] plgn.new = [] From 5621defddb1c336c66c048600031b15a65323bba Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:11:04 +0530 Subject: [PATCH 14/21] command first letter is only case-optioned if its an alpha --- lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.py b/lib.py index acd3b9b..1732915 100644 --- a/lib.py +++ b/lib.py @@ -240,7 +240,7 @@ def wrapper(config=None): self.setup = wrapper return wrapper - def command(self, regex, help='', private_only=False, restrict_to=None): + def command(self, regex, help=''): def wrapper(func): rx = regex if regex[0].lower() in 'qwertyuiopasdfghjklzxcvbnm': From c949f6e6a44760b168ea43bc10017d9ff5a8e5e3 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 12:12:56 +0530 Subject: [PATCH 15/21] bugfixes in youtube plugin. - by default location is assumed to be current location - using os.sep to join paths - queue_file param is optional and is assumed to be in current dir. --- plugins/youtube.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 9176c14..13049d9 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -105,10 +105,10 @@ def saveplaylist(data, playid): open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) return 'Saved playid {0}'.format(playid) -#@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) - +@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) @plgn.command('startplaylist') def continueplaylist(*args, **kwargs): + """ DONT USE THIS """ playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] logger.debug(playids) for i in playids: From 45398e305283dfda3326ff78f9626f645602c86f Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Thu, 14 Jul 2016 14:44:15 +0530 Subject: [PATCH 16/21] [youtube] download playlist. playlistids are saved in a local file and every hour the download is fired. --- plugins/youtube.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 13049d9..3d2b3f8 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -112,8 +112,11 @@ def continueplaylist(*args, **kwargs): playids = [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i ] logger.debug(playids) for i in playids: - logger.debug('starting for id->' + i) - link_downloader(i, *'ak') + try: + logger.debug('starting for id->' + i) + link_downloader(i, *'ak') + except: + pass @@ -208,6 +211,7 @@ def listings(data,what=None): @plgn.setupmethod +<<<<<<< HEAD def init(config=None): if config is not None: # Anything except None will let you in. plgn.location = unicode(config['location']) @@ -216,6 +220,15 @@ def init(config=None): plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') if not os.path.exists(plgn.playlistsfile): open(plgn.playlistsfile,'w') +======= +def init(config): + plgn.location = unicode(config.get('location', '.')) + plgn.location_video = os.sep.join(plgn.location + config['outtmpl']) + plgn.queued_links = config.get('queue_file', 'queue.txt') + plgn.playlistsfile = config.get('playlistsfile', 'playlists.txt') + if not os.path.exists(plgn.playlistsfile): + open(plgn.playlistsfile,'w') +>>>>>>> [youtube] download playlist. plgn.old = [] plgn.new = [] From 2d28bd76a9d0a9413cc226d41dbe1cdb55bcb4ea Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Sat, 15 Oct 2016 16:00:46 +0530 Subject: [PATCH 17/21] bugfix --- lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.py b/lib.py index 1732915..acd3b9b 100644 --- a/lib.py +++ b/lib.py @@ -240,7 +240,7 @@ def wrapper(config=None): self.setup = wrapper return wrapper - def command(self, regex, help=''): + def command(self, regex, help='', private_only=False, restrict_to=None): def wrapper(func): rx = regex if regex[0].lower() in 'qwertyuiopasdfghjklzxcvbnm': From 27447dc7f5722d77b341769b730fdfcea4835fc5 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Sat, 15 Oct 2016 16:09:03 +0530 Subject: [PATCH 18/21] Added name to saveplylist command --- plugins/youtube.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index a2dd85f..e102693 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -98,8 +98,9 @@ def queue(data,what,param): return '{0} added to download queue'.format(str(what)) -@plgn.command('<(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)>') +@plgn.command('save <(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P.*?)>') def saveplaylist(data, playid): + """ save playlist for recurring download""" if playid in [i for i in open(plgn.playlistsfile,'r').read().split('\n') if i != None]: return 'playid {0} exists'.format(playid) open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) From d70ae28956ea323bc756f797b21572962d1966c0 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Sat, 15 Oct 2016 17:12:04 +0530 Subject: [PATCH 19/21] [youtube] added support for 'ignoreerror' options of youtubedl --- plugins/youtube.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index e102693..2fb8538 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -61,8 +61,8 @@ def link_downloader(*a): 'preferredcodec': 'mp3', 'preferredquality': '192',}] }) - if len(args)>2 and ('k' in args[2].lower()): - y.update({ 'keepvideo':True }) + if len(args)>2 and ('k' in args[2].lower()): y.update({ 'keepvideo':True }) + if len(args)>3 and ('i' in args[3].lower()): y.update({ 'ignoreerrors':True }) link = str(args[0]) ydl= youtube_dl.YoutubeDL(y) try: @@ -114,10 +114,12 @@ def continueplaylist(*args, **kwargs): logger.debug(playids) for i in playids: try: - logger.debug('starting for id->' + i) + logger.info('starting for id->' + i) link_downloader(i, *'ak') except: pass + finally: + logger.info('done Downloading id->' +i) From 83b60790aa463e49b66f98947da64d56c375b68d Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Sat, 15 Oct 2016 17:52:20 +0530 Subject: [PATCH 20/21] [youtube] final deployable code tested for pi, added support to keepvideo and ignore errors --- plugins/youtube.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 2fb8538..4368bf9 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -52,7 +52,6 @@ def link_downloader(*a): 'logger':ydl_logger, 'nooverwrites':'True' } - logger.debug(y['outtmpl']) if len(args)>1 and (args[1] == 'a' or args[1]=='A'): y.update({ 'format': 'bestaudio/best', @@ -63,6 +62,7 @@ def link_downloader(*a): }) if len(args)>2 and ('k' in args[2].lower()): y.update({ 'keepvideo':True }) if len(args)>3 and ('i' in args[3].lower()): y.update({ 'ignoreerrors':True }) + logger.debug(y) link = str(args[0]) ydl= youtube_dl.YoutubeDL(y) try: @@ -115,7 +115,7 @@ def continueplaylist(*args, **kwargs): for i in playids: try: logger.info('starting for id->' + i) - link_downloader(i, *'ak') + link_downloader(i, *'aki') except: pass finally: From 50fb966fefaa47edfed60f2a9f7bde7a4a4d6777 Mon Sep 17 00:00:00 2001 From: Sumit Jamgade Date: Sat, 15 Oct 2016 17:57:14 +0530 Subject: [PATCH 21/21] [youtube] correcting the cron schedule syntax --- plugins/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/youtube.py b/plugins/youtube.py index 4368bf9..87babdc 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -106,7 +106,7 @@ def saveplaylist(data, playid): open(plgn.playlistsfile,'a').write('\n{0}'.format(playid)) return 'Saved playid {0}'.format(playid) -@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=0,second=0)) +@plgn.schedule(cron(hour=range(2,6)+range(10,18), minute=[0],second=[0])) @plgn.command('startplaylist') def continueplaylist(*args, **kwargs): """ DONT USE THIS """