1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-24 17:23:23 +03:00

refactor: simplify skills outputs

This commit is contained in:
louistiti 2022-06-12 17:58:57 +08:00
parent 10d10a1690
commit e1485c2ed3
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
25 changed files with 280 additions and 173 deletions

View File

@ -31,14 +31,23 @@ def translate(key, dict = { }):
"""Pickup the language file according to the cmd arg
and return the value according to the params"""
# "Temporize" for the data buffer ouput on the core
sleep(0.1)
output = ''
variables = { }
file = open(path.join(dirname, '../../skills', intent_obj['domain'], intent_obj['skill'], 'nlu', intent_obj['lang'] + '.json'), 'r', encoding = 'utf8')
obj = loads(file.read())
file.close()
# In case the key is a raw answer
if key not in obj['answers']:
return key
prop = obj['answers'][key]
variables = obj['variables']
if 'variables' in obj:
variables = obj['variables']
if isinstance(prop, list):
output = choice(prop)
else:
@ -52,15 +61,18 @@ def translate(key, dict = { }):
for key in variables:
output = output.replace('%' + key + '%', str(variables[key]))
# "Temporize" for the data buffer ouput on the core
sleep(0.1)
return output
def output(type, code, speech = '', core = { }):
def output(type, content = '', core = { }):
"""Communicate with the core"""
codes.append(code)
if isinstance(content, dict):
speech = translate(content['key'], content['data'])
codes.append(content['key'])
else:
content = str(content)
speech = translate(content)
codes.append(content)
print(dumps({
'domain': intent_obj['domain'],
@ -69,6 +81,7 @@ def output(type, code, speech = '', core = { }):
'lang': intent_obj['lang'],
'utterance': intent_obj['utterance'],
'entities': intent_obj['entities'],
'slots': intent_obj['slots'],
'output': {
'type': type,
'codes': codes,

View File

@ -416,6 +416,12 @@ class Nlu {
log.title('NLU')
log.success(`Intent found: ${this.nluResultObj.classification.skill}.${this.nluResultObj.classification.action} (domain: ${this.nluResultObj.classification.domain})`)
if (this.nluResultObj.classification.domain === 'system') {
this.brain.talk(`${this.brain.wernicke('random_unknown_intents')}.`, true)
this.brain.socket.emit('is-typing', false)
return resolve({ })
}
const nluDataFilePath = join(process.cwd(), 'skills', this.nluResultObj.classification.domain, this.nluResultObj.classification.skill, `nlu/${this.brain.lang}.json`)
this.nluResultObj.nluDataFilePath = nluDataFilePath

View File

@ -17,11 +17,11 @@ def guess(params):
# Return no speech if no number has been found
if given_nb == -1:
return utils.output('end', None, None, { 'isInActionLoop': False })
return utils.output('end', None, { 'isInActionLoop': False })
if given_nb == nb_to_guess:
return utils.output('end', 'guessed', '....CONGRATS.... Do you want to play another round?', { 'isInActionLoop': False })
return utils.output('end', '....CONGRATS.... Do you want to play another round?', { 'isInActionLoop': False })
if nb_to_guess < given_nb:
return utils.output('end', 'smaller', utils.translate('smaller'))
return utils.output('end', 'smaller')
if nb_to_guess > given_nb:
return utils.output('end', 'bigger', utils.translate('bigger'))
return utils.output('end', 'bigger')

View File

@ -16,10 +16,9 @@ def replay(params):
decision = resolver['value']
if decision == True:
return utils.output('end', 'replay', 'Let\'s goooo ' + str(decision), {
return utils.output('end', 'Let\'s goooo ' + str(decision), {
'isInActionLoop': False,
'restart': True
})
return utils.output('end', 'quit', 'As you wish ' + str(decision), { 'isInActionLoop': False })
return utils.output('end', 'As you wish ' + str(decision), { 'isInActionLoop': False })

View File

@ -14,4 +14,4 @@ def setup(params):
# TODO: save these values in DB
# TODO: add output_context
return utils.output('end', 'ready', utils.translate('ready'))
return utils.output('end', 'ready')

View File

@ -23,9 +23,9 @@ def play(params):
}
entities, slots = params['entities'], params['slots']
# TODO: make resolution more simple. E.g. slots['rounds_nb']['strValue']. Same for entities
rounds_nb = str(slots['rounds_nb']['value']['resolution']['value'])
testo_email = str(slots['testo_email']['value']['resolution']['value'])
testo_nb = str(slots['testo_nb']['value']['resolution']['value'])
rounds_nb = str(slots['rounds_nb']['resolution']['value'])
testo_email = str(slots['testo_email']['resolution']['value'])
testo_nb = str(slots['testo_nb']['resolution']['value'])
player = {
'handsign': None,
'points': 0
@ -40,26 +40,29 @@ def play(params):
if entity['entity'] == 'handsign':
player['handsign'] = entity['option']
utils.output('inter', 'testo', 'Just a test: ' + rounds_nb + ' + ' + testo_email + ' + ' + testo_nb)
utils.output('inter', 'Just a test: ' + rounds_nb + ' + ' + testo_email + ' + ' + testo_nb)
# Return no speech if no number has been found
# Exit the loop if no handsign has been found
if player['handsign'] == None:
return utils.output('end', None, None, { 'isInActionLoop': False })
if leon['handsign'] == player['handsign']:
return utils.output('end', 'equal', utils.translate('equal'))
return utils.output('end', 'equal')
# Point for Leon
if handsigns[leon['handsign']]['superior_to'] == player['handsign']:
# TODO: increment +1 for Leon
return utils.output('end', 'point_for_leon', utils.translate('point_for_leon', {
'handsign_1': leon['handsign'].lower(),
'handsign_2': player['handsign'].lower()
}))
return utils.output('end', { 'key': 'point_for_leon',
'data': {
'handsign_1': leon['handsign'].lower(),
'handsign_2': player['handsign'].lower()
}
})
# TODO: increment +1 for player
return utils.output('end', 'point_for_player', utils.translate('point_for_player', {
'handsign_1': player['handsign'].lower(),
'handsign_2': leon['handsign'].lower()
}))
return utils.output('end', { 'key': 'point_for_player',
'data': {
'handsign_1': player['handsign'].lower(),
'handsign_2': leon['handsign'].lower()
}
})

View File

@ -16,9 +16,9 @@ def rematch(params):
decision = item['resolution']['value']
if decision == 1:
return utils.output('end', 'replay', 'Let\'s goooo', {
return utils.output('end', 'Let\'s goooo', {
'isInActionLoop': False,
'restart': True
})
return utils.output('end', 'quit', 'As you wish', { 'isInActionLoop': False })
return utils.output('end', 'As you wish', { 'isInActionLoop': False })

View File

@ -10,4 +10,4 @@ def setup(params):
# TODO: use rounds_nb slot and save it in DB
return utils.output('end', 'ready', utils.translate('ready'))
return utils.output('end', 'ready')

View File

@ -13,16 +13,16 @@ def run(params):
# 1/2 chance to get deeper greetings
if randint(0, 1) != 0:
if time.hour >= 5 and time.hour <= 10:
return utils.output('end', 'morning_good_day', utils.translate('morning_good_day'))
return utils.output('end', 'morning_good_day')
if time.hour == 11:
return utils.output('end', 'morning', utils.translate('morning'))
return utils.output('end', 'morning')
if time.hour >= 12 and time.hour <= 17:
return utils.output('end', 'afternoon', utils.translate('afternoon'))
return utils.output('end', 'afternoon')
if time.hour >= 18 and time.hour <= 21:
return utils.output('end', 'evening', utils.translate('evening'))
return utils.output('end', 'evening')
if time.hour >= 22 and time.hour <= 23:
return utils.output('end', 'night', utils.translate('night'))
return utils.output('end', 'night')
return utils.output('end', 'too_late', utils.translate('too_late'))
return utils.output('end', 'too_late')
return utils.output('end', 'default', utils.translate('default'))
return utils.output('end', 'default')

View File

@ -9,6 +9,8 @@ def introduce_leon(params):
has_info = True
if has_info == False:
return utils.output('end', 'remembered', utils.translate('remembered', { 'owner_name': owner_name }))
# return utils.output('end', 'remembered', utils.translate('remembered', { 'owner_name': owner_name }))
return utils.output('end', 'leon_introduction_with', utils.translate('remembered', { 'owner_name': owner_name }))
return utils.output('end', 'leon_introduction', utils.translate('leon_introduction'))
return utils.output('end', 'leon_introduction')
# return utils.output('end', 'leon_introduction', utils.translate('leon_introduction'))

View File

@ -7,4 +7,4 @@ from random import randint
def run(params):
"""Leon gives a random number"""
return utils.output('end', 'success', randint(0, 100))
return utils.output('end', randint(0, 100))

View File

@ -45,14 +45,12 @@ def run(params):
tech_slug = language.lower()
if limit > 25:
utils.output('inter', 'limit_max', utils.translate('limit_max', {
'limit': limit
}))
utils.output('inter', { 'key': 'limit_max', 'data': { 'limit': limit } })
limit = 25
elif limit == 0:
limit = 5
utils.output('inter', 'reaching', utils.translate('reaching'))
utils.output('inter', 'reaching')
try:
r = utils.http('GET', 'https://github.com/trending/' + tech_slug + '?since=' + since)
@ -88,12 +86,12 @@ def run(params):
}
)
return utils.output('end', answer_key, utils.translate(answer_key, {
'limit': limit,
'tech': tech,
'result': result
}
)
)
return utils.output('end', { 'key': answer_key,
'data': {
'limit': limit,
'tech': tech,
'result': result
}
})
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))
return utils.output('end', 'unreachable')

View File

@ -30,7 +30,7 @@ def run(params):
else:
day_date = item['resolution']['strValue']
utils.output('inter', 'reaching', utils.translate('reaching'))
utils.output('inter', 'reaching')
try:
url = 'https://api.producthunt.com/v1/posts'
@ -41,19 +41,21 @@ def run(params):
response = r.json()
if 'error' in response and response['error'] == 'unauthorized_oauth':
return utils.output('end', 'invalid_developer_token', utils.translate('invalid_developer_token'))
return utils.output('end', 'invalid_developer_token')
posts = list(enumerate(response['posts']))
result = ''
if len(posts) == 0:
return utils.output('end', 'not_found', utils.translate('not_found'))
return utils.output('end', 'not_found')
if limit > len(posts):
utils.output('inter', 'limit_max', utils.translate('limit_max', {
'limit': limit,
'new_limit': len(posts)
}))
utils.output('inter', { 'key': 'limit_max',
'data': {
'limit': limit,
'new_limit': len(posts)
}
})
limit = len(posts)
elif limit == 0:
limit = 5
@ -83,12 +85,12 @@ def run(params):
if (i + 1) == limit:
break
return utils.output('end', answer_key, utils.translate(answer_key, {
'limit': limit,
'result': result,
'date': day_date
}
)
)
return utils.output('end', { 'key': answer_key,
'data': {
'limit': limit,
'result': result,
'date': day_date
}
})
except requests.exceptions.RequestException as e:
return utils.output('end', 'unreachable', utils.translate('unreachable'))
return utils.output('end', 'unreachable')

View File

@ -25,11 +25,11 @@ def add_todos(params):
# Verify if a list name has been provided
if not list_name:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))
return utils.output('end', 'list_not_provided')
# Verify todos have been provided
if len(todos) == 0:
return utils.output('end', 'todos_not_provided', utils.translate('todos_not_provided'))
return utils.output('end', 'todos_not_provided')
# Verify the list exists
if db.has_list(list_name) == False:
@ -42,7 +42,9 @@ def add_todos(params):
db.create_todo(list_name, todo)
result += utils.translate('list_todo_element', { 'todo': todo })
return utils.output('end', 'todos_added', utils.translate('todos_added', {
'list': list_name,
'result': result
}))
return utils.output('end', { 'key': 'todos_added',
'data': {
'list': list_name,
'result': result
}
})

View File

@ -25,11 +25,11 @@ def complete_todos(params):
# Verify if a list name has been provided
if not list_name:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))
return utils.output('end', 'list_not_provided')
# Verify todos have been provided
if len(todos) == 0:
return utils.output('end', 'todos_not_provided', utils.translate('todos_not_provided'))
return utils.output('end', 'todos_not_provided')
# Verify the list exists
if db.has_list(list_name) == False:
@ -45,7 +45,9 @@ def complete_todos(params):
result += utils.translate('list_completed_todo_element', { 'todo': db_todo['name'] })
return utils.output('end', 'todos_completed', utils.translate('todos_completed', {
'list': list_name,
'result': result
}))
return utils.output('end', { 'key': 'todos_completed',
'data': {
'list': list_name,
'result': result
}
})

View File

@ -19,12 +19,20 @@ def create_list(params):
# Verify if a list name has been provided
if not list_name:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))
return utils.output('end', 'list_not_provided')
# Verify if list already exists or not
if db.has_list(list_name):
return utils.output('end', 'list_already_exists', utils.translate('list_already_exists', { 'list': list_name }))
return utils.output('end', { 'key': 'list_already_exists',
'data': {
'list': list_name
}
})
db.create_list(list_name)
return utils.output('end', 'list_created', utils.translate('list_created', { 'list': list_name }))
return utils.output('end', { 'key': 'list_created',
'data': {
'list': list_name
}
})

View File

@ -19,13 +19,21 @@ def delete_list(params):
# Verify if a list name has been provided
if not list_name:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))
return utils.output('end', 'list_not_provided')
# Verify if the list exists
if db.has_list(list_name) == False:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': list_name }))
return utils.output('end', { 'key': 'list_does_not_exist',
'data': {
'list': list_name
}
})
# Delete the to-do list
db.delete_list(list_name)
return utils.output('end', 'list_deleted', utils.translate('list_deleted', { 'list': list_name }))
return utils.output('end', { 'key': 'list_deleted',
'data': {
'list': list_name
}
})

View File

@ -24,22 +24,32 @@ def rename_list(params):
# Verify if an old and new list name have been provided
if not old_list_name or not new_list_name:
return utils.output('end', 'new_or_old_list_not_provided', utils.translate('new_or_old_list_not_provided'))
return utils.output('end', 'new_or_old_list_not_provided')
# Verify if the old list exists
if db.has_list(old_list_name) == False:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': old_list_name }))
return utils.output('end', { 'key': 'list_does_not_exist',
'data': {
'list': old_list_name
}
})
# Verify if the new list name already exists
if db.has_list(new_list_name):
return utils.output('end', 'list_already_exists', utils.translate('list_already_exists', { 'list': new_list_name }))
return utils.output('end', { 'key': 'list_already_exists',
'data': {
'list': new_list_name
}
})
# Rename the to-do list
db.update_list_name(old_list_name, new_list_name)
# Rename the list name of the todos
db.update_todo_list_name(old_list_name, new_list_name)
return utils.output('end', 'list_renamed', utils.translate('list_renamed', {
'old_list': old_list_name,
'new_list': new_list_name
}))
return utils.output('end', { 'key': 'list_renamed',
'data': {
'old_list': old_list_name,
'new_list': new_list_name
}
})

View File

@ -25,15 +25,19 @@ def uncheck_todos(params):
# Verify if a list name has been provided
if not list_name:
return utils.output('end', 'list_not_provided', utils.translate('list_not_provided'))
return utils.output('end', 'list_not_provided')
# Verify todos have been provided
if len(todos) == 0:
return utils.output('end', 'todos_not_provided', utils.translate('todos_not_provided'))
return utils.output('end', 'todos_not_provided')
# Verify if the list exists
if db.has_list(list_name) == False:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': list_name }))
return utils.output('end', { 'key': 'list_does_not_exist',
'data': {
'list': list_name
}
})
result = ''
for todo in todos:
@ -44,7 +48,9 @@ def uncheck_todos(params):
result += utils.translate('list_todo_element', { 'todo': db_todo['name'] })
return utils.output('end', 'todo_unchecked', utils.translate('todos_unchecked', {
'list': list_name,
'result': result
}))
return utils.output('end', { 'key': 'todo_unchecked',
'data': {
'list': list_name,
'result': result
}
})

View File

@ -19,13 +19,21 @@ def view_list(params):
# Verify if the list exists
if db.has_list(list_name) == False:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': list_name }))
return utils.output('end', { 'key': 'list_does_not_exist',
'data': {
'list': list_name
}
})
# Grab todos of the list
todos = db.get_todos(list_name)
if len(todos) == 0:
return utils.output('end', 'empty_list', utils.translate('empty_list', { 'list': list_name }))
return utils.output('end', { 'key': 'empty_list',
'data': {
'list': list_name
}
})
unchecked_todos = db.get_uncomplete_todos(list_name)
completed_todos = db.get_done_todos(list_name)
@ -34,31 +42,39 @@ def view_list(params):
result_completed_todos = ''
if len(unchecked_todos) == 0:
utils.output('inter', 'no_unchecked_todo', utils.translate('no_unchecked_todo', { 'list': list_name }))
utils.output('inter', { 'key': 'no_unchecked_todo',
'data': {
'list': list_name
}
})
else:
for todo in unchecked_todos:
result_unchecked_todos += utils.translate('list_todo_element', {
'todo': todo['name']
})
utils.output('inter', 'unchecked_todos_listed', utils.translate('unchecked_todos_listed', {
'list': list_name,
'result': result_unchecked_todos
}
)
)
utils.output('inter', { 'key': 'unchecked_todos_listed',
'data': {
'list': list_name,
'result': result_unchecked_todos
}
})
if len(completed_todos) == 0:
return utils.output('end', 'no_completed_todo', utils.translate('no_completed_todo', { 'list': list_name }))
return utils.output('end', { 'key': 'no_completed_todo',
'data': {
'list': list_name
}
})
for todo in completed_todos:
result_completed_todos += utils.translate('list_completed_todo_element', {
'todo': todo['name']
})
return utils.output('end', 'completed_todos_listed', utils.translate('completed_todos_listed', {
'list': list_name,
'result': result_completed_todos
}
)
)
return utils.output('end', { 'key': 'completed_todos_listed',
'data': {
'list': list_name,
'result': result_completed_todos
}
})

View File

@ -14,7 +14,7 @@ def view_lists(params):
# Verify if a list exists
if lists_nb == 0:
return utils.output('end', 'no_list', utils.translate('no_list'))
return utils.output('end', 'no_list')
result = ''
# Fill end-result
@ -24,9 +24,9 @@ def view_lists(params):
'todos_nb': db.count_todos( list_element['name'])
})
return utils.output('end', 'lists_listed', utils.translate('lists_listed', {
'lists_nb': lists_nb,
'result': result
}
)
)
return utils.output('end', { 'key': 'lists_listed',
'data': {
'lists_nb': lists_nb,
'result': result
}
})

View File

@ -22,9 +22,9 @@ def run(params):
emails = utils.config('options')['emails']
if not emails:
return utils.output('end', 'no_email', utils.translate('no_email'))
return utils.output('end', 'no_email')
utils.output('inter', 'checking', utils.translate('checking'))
utils.output('inter', 'checking')
for index, email in enumerate(emails):
is_last_email = index == len(emails) - 1
@ -33,14 +33,22 @@ def run(params):
# Have I Been Pwned API returns a 403 when accessed by unauthorized/banned clients
if breached == 403:
return utils.output('end', 'blocked', utils.translate('blocked', { 'website_name': 'Have I Been Pwned' }))
return utils.output('end', { 'key': 'blocked',
'data': {
'website_name': 'Have I Been Pwned'
}
})
elif breached == 503:
return utils.output('end', 'blocked', utils.translate('unavailable', { 'website_name': 'Have I Been Pwned' }))
return utils.output('end', { 'key': 'unavailable',
'data': {
'website_name': 'Have I Been Pwned'
}
})
elif not breached:
if is_last_email:
return utils.output('end', 'no_pwnage', utils.translate('no_pwnage', data))
return utils.output('end', { 'key': 'no_pwnage', 'data': data })
else:
utils.output('inter', 'no_pwnage', utils.translate('no_pwnage', data))
utils.output('inter', { 'key': 'no_pwnage', 'data': data })
else:
data['result'] = ''
@ -53,10 +61,9 @@ def run(params):
)
if is_last_email:
return utils.output('end', 'pwned', utils.translate('pwned', data))
return utils.output('end', { 'key': 'pwned', 'data': data })
else:
utils.output('inter', 'pwned', utils.translate('pwned', data))
utils.output('inter', { 'key': 'pwned', 'data': data })
def check_for_breach(email):
# Delay for 2 seconds before making request to accomodate API usage policy
sleep(2)
@ -73,4 +80,8 @@ def check_for_breach(email):
return response.status_code
except exceptions.RequestException as e:
return utils.output('end', 'down', utils.translate('errors', { 'website_name': 'Have I Been Pwned' }))
return utils.output('end', { 'key': 'errors',
'data': {
'website_name': 'Have I Been Pwned'
}
})

View File

@ -25,7 +25,11 @@ def run(params):
state = 'up'
website_name = domain[:domain.find('.')].title()
utils.output('inter', 'checking', utils.translate('checking', { 'website_name': website_name }))
utils.output('inter', { 'key': 'checking',
'data': {
'website_name': website_name
}
})
try:
r = utils.http('GET', 'http://' + domain)
@ -33,14 +37,26 @@ def run(params):
if (r.status_code != requests.codes.ok):
state = 'down'
utils.output('inter', 'up', utils.translate(state, { 'website_name': website_name }))
utils.output('inter', { 'key': state,
'data': {
'website_name': website_name
}
})
except requests.exceptions.RequestException as e:
utils.output('inter', 'down', utils.translate('errors', { 'website_name': website_name }))
utils.output('inter', { 'key': 'errors',
'data': {
'website_name': website_name
}
})
if len(domains) > 1 and i >= 0 and i + 1 < len(domains):
output += ' '
if len(domains) == 0:
return utils.output('end', 'invalid_domain_name', utils.translate('invalid_domain_name'))
else:
return utils.output('end', 'done')
return utils.output('end', { 'key': 'invalid_domain_name',
'data': {
'website_name': website_name
}
})
return utils.output('end')

View File

@ -13,29 +13,29 @@ import subprocess
import re
def run(params):
"""Give you information about your network speed"""
"""Give you information about your network speed"""
utils.output('inter', 'testing', utils.translate('testing'))
utils.output('inter', 'testing')
realpath = os.path.dirname(os.path.realpath(__file__))
process = subprocess.Popen(
[sys.executable, realpath + '/../lib/speed_test.lib.py', '--simple'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
realpath = os.path.dirname(os.path.realpath(__file__))
process = subprocess.Popen(
[sys.executable, realpath + '/../lib/speed_test.lib.py', '--simple'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
(output, err) = process.communicate()
p_status = process.wait()
(output, err) = process.communicate()
p_status = process.wait()
if err:
return utils.output('end', 'error', utils.translate('error'))
if err:
return utils.output('end', 'error')
rawoutput = output.decode('utf-8')
rawoutput = output.decode('utf-8')
data = {
'ping': re.search('Ping:(.+?)\n', rawoutput).group(1).strip(),
'download': re.search('Download:(.+?)\n', rawoutput).group(1).strip(),
'upload': re.search('Upload:(.+?)\n', rawoutput).group(1).strip()
}
data = {
'ping': re.search('Ping:(.+?)\n', rawoutput).group(1).strip(),
'download': re.search('Download:(.+?)\n', rawoutput).group(1).strip(),
'upload': re.search('Upload:(.+?)\n', rawoutput).group(1).strip()
}
return utils.output('end', 'done', utils.translate('done', data))
return utils.output('end', { 'key': 'done', 'data': data })

View File

@ -18,7 +18,7 @@ def run(params):
# https://developers.google.com/youtube/v3/docs/playlistItems/list
url = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=' + playlist_id + '&key=' + api_key
utils.output('inter', 'reaching_playlist', utils.translate('reaching_playlist'))
utils.output('inter', 'reaching_playlist')
# Get videos from the playlist
try:
r = utils.http('GET', url)
@ -26,11 +26,12 @@ def run(params):
# In case there is a problem like wrong settings
if 'error' in r.json():
error = r.json()['error']['errors'][0]
return utils.output('settings_error', 'settings_error', utils.translate('settings_errors', {
'reason': error['reason'],
'message': error['message']
}))
return utils.output('end', { 'key': 'settings_error'
'data': {
'reason': error['reason'],
'message': error['message']
}
})
items = r.json()['items']
video_ids = []
@ -46,7 +47,7 @@ def run(params):
'title': item['snippet']['title']
})
except requests.exceptions.RequestException as e:
return utils.output('request_error', 'request_error', utils.translate('request_errors'))
return utils.output('end', 'request_error')
Entry = query()
@ -71,19 +72,23 @@ def run(params):
nbrto_download = len(to_download)
if nbrto_download == 0:
return utils.output('nothing_to_download', 'nothing_to_download', utils.translate('nothing_to_download'))
return utils.output('end', 'nothing_to_download')
utils.output('inter', 'nb_to_download', utils.translate('nb_to_download', {
'nb': nbrto_download
}))
utils.output('inter', { 'key': 'nb_to_download'
'data': {
'nb': nbrto_download
}
})
# Create the module downloads directory
skill_dl_dir = utils.create_dl_dir()
for i, video in enumerate(to_download):
utils.output('inter', 'downloading', utils.translate('downloading', {
'video_title': video['title']
}))
utils.output('inter', { 'key': 'downloading'
'data': {
'video_title': video['title']
}
})
# Download the video
yt = YouTube('https://youtube.com/watch?v=' + video['id'])
@ -94,4 +99,4 @@ def run(params):
db.update({ 'downloaded_videos': downloaded_videos }, Entry.platform == 'youtube')
# Will synchronize the content (because "end" type) if synchronization enabled
return utils.output('end', 'success', utils.translate('success'))
return utils.output('end', 'success')