Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 47 additions & 6 deletions plugins/youtube.py
Original file line number Diff line number Diff line change
@@ -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 :
Expand Down Expand Up @@ -41,7 +49,7 @@ def link_downloader(*a):
args = [str(i) for i in a]
y = {
'outtmpl':plgn.location_video,
'logger':logger,
'logger':ydl_logger,
'nooverwrites':'True'
}
if len(args)>1 and (args[1] == 'a' or args[1]=='A'):
Expand All @@ -52,6 +60,9 @@ 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)>3 and ('i' in args[3].lower()): y.update({ 'ignoreerrors':True })
logger.debug(y)
link = str(args[0])
ydl= youtube_dl.YoutubeDL(y)
try:
Expand Down Expand Up @@ -86,6 +97,33 @@ def queue(data,what,param):
f.write(',')
return '{0} added to download queue'.format(str(what))


@plgn.command('save <(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?.*?(?:list)=(?P<playid>.*?)>')
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))
return 'Saved playid {0}'.format(playid)

@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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested that youtube-dl works for downloading a playlist on the basis of playlist id itself ? I could see that you are just grouping out the playlist_id with the help of regex matching in line 101. If the playlist_id is sufficient enough then go going so far .

try:
logger.info('starting for id->' + i)
link_downloader(i, *'aki')
except:
pass
finally:
logger.info('done Downloading id->' +i)




@plgn.command('begin')
def begin(data,what = None):
if not os.access(plgn.queued_links,os.F_OK):
Expand Down Expand Up @@ -176,11 +214,14 @@ 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.playlists o= open(config['playlists']).read().split('/n')
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 = []

Expand Down
2 changes: 1 addition & 1 deletion threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down