From 579db854e835f8077c3b60b1835d21d4d45e34f9 Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Tue, 2 Sep 2014 17:05:43 +0200 Subject: [PATCH] [contrib] fix pyflakes in xbmc plugin --- contrib/plugin.video.videoobmc/default.py | 62 ++-- .../resources/language/english/strings.xml | 38 +-- .../resources/language/french/strings.xml | 38 +-- .../resources/lib/__init__.py | 2 +- .../resources/lib/base/__init__.py | 2 +- .../resources/lib/base/common_xbmc.py | 314 +++++++++--------- .../resources/lib/base/menu.py | 80 ++--- .../resources/lib/base/weboobmc.py | 2 +- .../resources/lib/menu.py | 144 ++++---- .../resources/lib/test/__init__.py | 2 +- .../resources/lib/test/common_test.py | 220 ++++++------ 11 files changed, 452 insertions(+), 452 deletions(-) diff --git a/contrib/plugin.video.videoobmc/default.py b/contrib/plugin.video.videoobmc/default.py index de04e623..7d608f50 100644 --- a/contrib/plugin.video.videoobmc/default.py +++ b/contrib/plugin.video.videoobmc/default.py @@ -1,31 +1,31 @@ -# -*- coding: utf-8 -*- -import sys -import resources.lib.base.common_xbmc as common_xbmc -import resources.lib.constants as constants -from resources.lib.actions import actions - -# Plugin constants -version = "0.1.0" -plugin = "videoobmc" + version -addon_id = "plugin.video.videoobmc" -author = "Bezleputh" -mail = "carton_ben@yahoo.fr" - -#import lxml.html import Element -#print Element.__file__ - -#TODO gestion du logger, gestion des modules via XBMC (activation/desactivation) - -#Bug encodge des categories -#corriger version 1 pour que v2 et v1 donctionnent - -if (__name__ == "__main__"): - if not (sys.argv[2]): - actions[constants.DISPLAY_MENU]()._do() - else: - params = common_xbmc.parse_params(sys.argv[2]) - action = params.get("action") - if (action): - actions[action]()._do(params) - else: - common_xbmc.display_error(" ARGV Nothing done.. verify params " + repr(params)) +# -*- coding: utf-8 -*- +import sys +import resources.lib.base.common_xbmc as common_xbmc +import resources.lib.constants as constants +from resources.lib.actions import actions + +# Plugin constants +version = "0.1.0" +plugin = "videoobmc" + version +addon_id = "plugin.video.videoobmc" +author = "Bezleputh" +mail = "carton_ben@yahoo.fr" + +#import lxml.html import Element +#print Element.__file__ + +#TODO gestion du logger, gestion des modules via XBMC (activation/desactivation) + +#Bug encodge des categories +#corriger version 1 pour que v2 et v1 donctionnent + +if (__name__ == "__main__"): + if not (sys.argv[2]): + actions[constants.DISPLAY_MENU]()._do() + else: + params = common_xbmc.parse_params(sys.argv[2]) + action = params.get("action") + if (action): + actions[action]()._do(params) + else: + common_xbmc.display_error(" ARGV Nothing done.. verify params " + repr(params)) diff --git a/contrib/plugin.video.videoobmc/resources/language/english/strings.xml b/contrib/plugin.video.videoobmc/resources/language/english/strings.xml index f5f6e83a..b25c1ae2 100644 --- a/contrib/plugin.video.videoobmc/resources/language/english/strings.xml +++ b/contrib/plugin.video.videoobmc/resources/language/english/strings.xml @@ -1,23 +1,23 @@ - - - - Search - Search: + + + + Seach + Seach: - Download - Information + Download + Infomation - Error! + Eo! - Information - Download started - Download succeed + Infomation + Download stated + Download succeed - Download folder: - Number of videos per backends: - Display Non Safe For Work videos: - Enable debug mode: - Update weboob backends - Start updating weboob backends - Weboob backends successfully updated - + Download folde: + Numbe of videos pe backends: + Display Non Safe Fo Wok videos: + Enable debug mode: + Update weboob backends + Stat updating weboob backends + Weboob backends successfully updated + diff --git a/contrib/plugin.video.videoobmc/resources/language/french/strings.xml b/contrib/plugin.video.videoobmc/resources/language/french/strings.xml index 09c8d746..7284633a 100644 --- a/contrib/plugin.video.videoobmc/resources/language/french/strings.xml +++ b/contrib/plugin.video.videoobmc/resources/language/french/strings.xml @@ -1,23 +1,23 @@ - - - - Recherche - Recherche: + + + + Recheche + Recheche: - Télécharger - Information + Téléchage + Infomation - Erreur! + Eeu! - Information - Lancement du téléchargement - Fichier téléchargé avec succès + Infomation + Lancement du téléchagement + Fichie téléchagé avec succès - Répertoire de Téléchargement: - Nombre de vidéos par backends: - Afficher les vidéos interdites aux moins de 18 ans : - Enable debug mode : - Mise à jour des modules weboob - Debut de la mise à jour - Weboob est maintenant à jour - + Répetoie de Téléchagement: + Nombe de vidéos pa backends: + Affiche les vidéos intedites aux moins de 18 ans : + Enable debug mode : + Mise à jou des modules weboob + Debut de la mise à jou + Weboob est maintenant à jou + diff --git a/contrib/plugin.video.videoobmc/resources/lib/__init__.py b/contrib/plugin.video.videoobmc/resources/lib/__init__.py index ee074ac5..b93054b3 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/__init__.py +++ b/contrib/plugin.video.videoobmc/resources/lib/__init__.py @@ -1 +1 @@ -# Dummy file to make this directory a package. +# Dummy file to make this directory a package. diff --git a/contrib/plugin.video.videoobmc/resources/lib/base/__init__.py b/contrib/plugin.video.videoobmc/resources/lib/base/__init__.py index ee074ac5..b93054b3 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/base/__init__.py +++ b/contrib/plugin.video.videoobmc/resources/lib/base/__init__.py @@ -1 +1 @@ -# Dummy file to make this directory a package. +# Dummy file to make this directory a package. diff --git a/contrib/plugin.video.videoobmc/resources/lib/base/common_xbmc.py b/contrib/plugin.video.videoobmc/resources/lib/base/common_xbmc.py index 1835ca75..5dce9c54 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/base/common_xbmc.py +++ b/contrib/plugin.video.videoobmc/resources/lib/base/common_xbmc.py @@ -1,157 +1,157 @@ -# -*- coding: utf-8 -*- - -import xbmc -import xbmcgui -import xbmcplugin -import xbmcaddon - -import urllib -import sys - -from traceback import print_exc - - -def get_addon(): - if hasattr(sys.modules["__main__"], "addon_id"): - _id = sys.modules["__main__"].addon_id - return xbmcaddon.Addon(id=_id) - - -def get_translation(key): - addon = get_addon() - if addon: - return addon.getLocalizedString(int(key)) - - -def get_settings(key): - addon = get_addon() - if addon: - return addon.getSetting(key) - - -def get_addon_dir(): - addon = get_addon() - if addon: - addonDir = addon.getAddonInfo("path") - else: - addonDir = xbmc.translatePath("special://profile/addon_data/") - - return addonDir - - -def display_error(msg): - xbmc.executebuiltin("XBMC.Notification(%s, %s)" % (get_translation('30200').decode('utf-8'), msg)) - print msg - print_exc(msg) - - -def display_info(msg): - xbmc.executebuiltin("XBMC.Notification(%s, %s, 3000, DefaultFolder.png)" % (get_translation('30300').encode('utf-8'), - msg.encode('utf-8'))) - #print msg - print_exc() - - -def parse_params(param_str): - param_dic = {} - # Parameters are on the 3rd arg passed to the script - param_str = sys.argv[2] - if len(param_str) > 1: - param_str = param_str.replace('?', '') - - # Ignore last char if it is a '/' - if param_str[len(param_str) - 1] == '/': - param_str = param_str[0:len(param_str) - 2] - - # Processing each parameter splited on '&' - for param in param_str.split('&'): - try: - # Spliting couple key/value - key, value = param.split('=') - except: - key = param - value = '' - - key = urllib.unquote_plus(key) - value = urllib.unquote_plus(value) - - # Filling dictionnary - param_dic[key] = value - - return param_dic - - -def ask_user(content, title): - keyboard = xbmc.Keyboard(content, title) - keyboard.doModal() - if keyboard.isConfirmed() and keyboard.getText(): - return keyboard.getText() - return "" - - -def create_param_url(param_dic, quote_plus=False): - """ - Create an plugin URL based on the key/value passed in a dictionary - """ - url = sys.argv[0] - sep = '?' - - try: - for param in param_dic: - if quote_plus: - url = url + sep + urllib.quote_plus(param) + '=' + urllib.quote_plus(param_dic[param]) - else: - url = "%s%s%s=%s" % (url, sep, param, param_dic[param]) - - sep = '&' - except Exception, msg: - display_error("create_param_url %s" % msg) - url = None - return url - - -def create_list_item(name, itemInfoType="Video", itemInfoLabels=None, iconimage="DefaultFolder.png", - c_items=None, isPlayable=False): - lstItem = xbmcgui.ListItem(label=name, iconImage=iconimage, thumbnailImage=iconimage) - - if c_items: - lstItem.addContextMenuItems(c_items, replaceItems=True) - - if itemInfoLabels: - iLabels = itemInfoLabels - else: - iLabels = {"Title": name, } - - lstItem.setInfo(type=itemInfoType, infoLabels=iLabels) - if isPlayable: - lstItem.setProperty('IsPlayable', "true") - - return lstItem - - -def add_menu_item(params={}): - url = create_param_url(params) - if params.get('name'): - if params.get('iconimage'): - lstItem = create_list_item(params.get('name'), iconimage=params.get('iconimage')) - else: - lstItem = create_list_item(params.get('name')) - xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=lstItem, isFolder=True) - else: - display_error('add_menu_item : Fail to add item to menu') - - -def add_menu_link(params={}): - if params.get('name') and params.get('iconimage') and params.get('url') and \ - params.get('itemInfoLabels') and params.get('c_items'): - url = params.get('url') - lstItem = create_list_item(params.get('name'), iconimage=params.get('iconimage'), - itemInfoLabels=params.get('itemInfoLabels'), c_items=params.get('c_items'), - isPlayable=True) - xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=lstItem) - else: - display_error('add_menu_link : Fail to add item to menu') - - -def end_of_directory(update=False): - xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True, updateListing=update) # , cacheToDisc=True) +# -*- coding: utf-8 -*- + +import xbmc +import xbmcgui +import xbmcplugin +import xbmcaddon + +import urllib +import sys + +from traceback import print_exc + + +def get_addon(): + if hasattr(sys.modules["__main__"], "addon_id"): + _id = sys.modules["__main__"].addon_id + return xbmcaddon.Addon(id=_id) + + +def get_translation(key): + addon = get_addon() + if addon: + return addon.getLocalizedString(int(key)) + + +def get_settings(key): + addon = get_addon() + if addon: + return addon.getSetting(key) + + +def get_addon_dir(): + addon = get_addon() + if addon: + addonDir = addon.getAddonInfo("path") + else: + addonDir = xbmc.translatePath("special://profile/addon_data/") + + return addonDir + + +def display_error(msg): + xbmc.executebuiltin("XBMC.Notification(%s, %s)" % (get_translation('30200').decode('utf-8'), msg)) + print msg + print_exc(msg) + + +def display_info(msg): + xbmc.executebuiltin("XBMC.Notification(%s, %s, 3000, DefaultFolder.png)" % (get_translation('30300').encode('utf-8'), + msg.encode('utf-8'))) + #print msg + print_exc() + + +def parse_params(param_str): + param_dic = {} + # Parameters are on the 3rd arg passed to the script + param_str = sys.argv[2] + if len(param_str) > 1: + param_str = param_str.replace('?', '') + + # Ignore last char if it is a '/' + if param_str[len(param_str) - 1] == '/': + param_str = param_str[0:len(param_str) - 2] + + # Processing each parameter splited on '&' + for param in param_str.split('&'): + try: + # Spliting couple key/value + key, value = param.split('=') + except: + key = param + value = '' + + key = urllib.unquote_plus(key) + value = urllib.unquote_plus(value) + + # Filling dictionnary + param_dic[key] = value + + return param_dic + + +def ask_user(content, title): + keyboard = xbmc.Keyboard(content, title) + keyboard.doModal() + if keyboard.isConfirmed() and keyboard.getText(): + return keyboard.getText() + return "" + + +def create_param_url(param_dic, quote_plus=False): + """ + Create an plugin URL based on the key/value passed in a dictionary + """ + url = sys.argv[0] + sep = '?' + + try: + for param in param_dic: + if quote_plus: + url = url + sep + urllib.quote_plus(param) + '=' + urllib.quote_plus(param_dic[param]) + else: + url = "%s%s%s=%s" % (url, sep, param, param_dic[param]) + + sep = '&' + except Exception as msg: + display_error("create_param_url %s" % msg) + url = None + return url + + +def create_list_item(name, itemInfoType="Video", itemInfoLabels=None, iconimage="DefaultFolder.png", + c_items=None, isPlayable=False): + lstItem = xbmcgui.ListItem(label=name, iconImage=iconimage, thumbnailImage=iconimage) + + if c_items: + lstItem.addContextMenuItems(c_items, replaceItems=True) + + if itemInfoLabels: + iLabels = itemInfoLabels + else: + iLabels = {"Title": name, } + + lstItem.setInfo(type=itemInfoType, infoLabels=iLabels) + if isPlayable: + lstItem.setProperty('IsPlayable', "true") + + return lstItem + + +def add_menu_item(params={}): + url = create_param_url(params) + if params.get('name'): + if params.get('iconimage'): + lstItem = create_list_item(params.get('name'), iconimage=params.get('iconimage')) + else: + lstItem = create_list_item(params.get('name')) + xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=lstItem, isFolder=True) + else: + display_error('add_menu_item : Fail to add item to menu') + + +def add_menu_link(params={}): + if params.get('name') and params.get('iconimage') and params.get('url') and \ + params.get('itemInfoLabels') and params.get('c_items'): + url = params.get('url') + lstItem = create_list_item(params.get('name'), iconimage=params.get('iconimage'), + itemInfoLabels=params.get('itemInfoLabels'), c_items=params.get('c_items'), + isPlayable=True) + xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=lstItem) + else: + display_error('add_menu_link : Fail to add item to menu') + + +def end_of_directory(update=False): + xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True, updateListing=update) # , cacheToDisc=True) diff --git a/contrib/plugin.video.videoobmc/resources/lib/base/menu.py b/contrib/plugin.video.videoobmc/resources/lib/base/menu.py index 4add6315..33d07acc 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/base/menu.py +++ b/contrib/plugin.video.videoobmc/resources/lib/base/menu.py @@ -1,40 +1,40 @@ -# -*- coding: utf-8 -*- -import sys - -if hasattr(sys.modules["__main__"], "common_xbmc"): - common_xbmc = sys.modules["__main__"].common_xbmc -else: - import common_xbmc - - -class BaseMenuItem(): - - def __init__(self, name, action, iconimage="DefaultFolder.png"): - self.params = {} - self.params['name'] = name - self.params['action'] = action - self.params['iconimage'] = iconimage - - def get(self, element): - return self.params[element] - - def add_to_menu(self): - common_xbmc.add_menu_item(self.params) - - -class BaseMenuLink(BaseMenuItem): - - def __init__(self, name, url, action, iconimage="DefaultFolder.png"): - BaseMenuItem.__init__(self, name, action, iconimage) - self.params["url"] = url - - def createVideoContextMenu(self): - return "" - - def create_info_labels(self): - return "" - - def add_to_menu(self): - self.params["itemInfoLabels"] = self.create_info_labels() - self.params["c_items"] = self.createVideoContextMenu() - common_xbmc.add_menu_link(self.params) +# -*- coding: utf-8 -*- +import sys + +if hasattr(sys.modules["__main__"], "common_xbmc"): + common_xbmc = sys.modules["__main__"].common_xbmc +else: + import common_xbmc + + +class BaseMenuItem(): + + def __init__(self, name, action, iconimage="DefaultFolder.png"): + self.params = {} + self.params['name'] = name + self.params['action'] = action + self.params['iconimage'] = iconimage + + def get(self, element): + return self.params[element] + + def add_to_menu(self): + common_xbmc.add_menu_item(self.params) + + +class BaseMenuLink(BaseMenuItem): + + def __init__(self, name, url, action, iconimage="DefaultFolder.png"): + BaseMenuItem.__init__(self, name, action, iconimage) + self.params["url"] = url + + def createVideoContextMenu(self): + return "" + + def create_info_labels(self): + return "" + + def add_to_menu(self): + self.params["itemInfoLabels"] = self.create_info_labels() + self.params["c_items"] = self.createVideoContextMenu() + common_xbmc.add_menu_link(self.params) diff --git a/contrib/plugin.video.videoobmc/resources/lib/base/weboobmc.py b/contrib/plugin.video.videoobmc/resources/lib/base/weboobmc.py index d1247594..32466b9f 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/base/weboobmc.py +++ b/contrib/plugin.video.videoobmc/resources/lib/base/weboobmc.py @@ -55,7 +55,7 @@ class Weboobmc(): os.path.join(os.path.expanduser('~'), '.local', 'share') ), 'weboob') icons_dir = os.path.join(datadir, 'icons') - + return os.path.join(icons_dir, '%s.png' % module) def is_category(self, obj): diff --git a/contrib/plugin.video.videoobmc/resources/lib/menu.py b/contrib/plugin.video.videoobmc/resources/lib/menu.py index 8f3d3e5c..f4a2490f 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/menu.py +++ b/contrib/plugin.video.videoobmc/resources/lib/menu.py @@ -1,72 +1,72 @@ -# -*- coding: utf-8 -*- -import sys -import constants - -from datetime import datetime, timedelta -from base.menu import BaseMenuItem, BaseMenuLink - -if hasattr(sys.modules["__main__"], "common_xbmc"): - common_xbmc = sys.modules["__main__"].common_xbmc -else: - import common_xbmc - - -class MenuItem(BaseMenuItem): - params = {} - - def __init__(self, name, action, iconimage="DefaultFolder.png", backend=''): - BaseMenuItem.__init__(self, name, action, iconimage) - self.params['backend'] = backend - - -class MenuItemPath(MenuItem): - - def __init__(self, collection, action=constants.DISPLAY_COLLECTION_MENU, iconimage="DefaultFolder.png"): - MenuItem.__init__(self, collection.title, action, iconimage, collection.fullid.split('@')[-1]) - self.params["path"] = '/'.join(collection.split_path) - - -class MenuItemVideo(BaseMenuLink): - def __init__(self, video, iconimage="DefaultFolder.png"): - name = '[%s] %s' % (video.backend, video.title) - BaseMenuLink.__init__(self, name, video.url, constants.VIDEO, - video.thumbnail.url if video.thumbnail.url else iconimage) - self.video = video - self.params["id"] = self.video.id - - def createVideoContextMenu(self): - cm = [] - - #Information - cm.append((common_xbmc.get_translation('30110'), "XBMC.Action(Info)")) - - #Téléchargement - url = "%s?action=%s&id=%s&backend=%s" % (sys.argv[0], constants.DOWNLOAD, self.video.id, self.video.backend) - cm.append((common_xbmc.get_translation('30100'), "XBMC.PlayMedia(%s)" % (url))) - - return cm - - def create_info_labels(self): - date, year = self.format_date(self.video.date) - - duration = 0 - if self.video.duration: - duration = u'%s' % str(self.video.duration.total_seconds()/60) if isinstance(self.video.duration, timedelta) else self.video.duration - - description = u'%s' % self.video.description - - return {"Title": self.video.title, - "Year": year, - "Plot": description, - "PlotOutline": description[0:30] if len(description) > 30 else description, - "Director": self.video.author if self.video.author else 'Unknown', - "Duration": duration, - "Date": date} - - def format_date(self, video_date): - date = datetime.now().strftime("%d/%m/%Y") - if video_date: - date = video_date.strftime("%d/%m/%Y") - - year = date.split('/')[-1] - return date, year +# -*- coding: utf-8 -*- +import sys +import constants + +from datetime import datetime, timedelta +from base.menu import BaseMenuItem, BaseMenuLink + +if hasattr(sys.modules["__main__"], "common_xbmc"): + common_xbmc = sys.modules["__main__"].common_xbmc +else: + import common_xbmc + + +class MenuItem(BaseMenuItem): + params = {} + + def __init__(self, name, action, iconimage="DefaultFolder.png", backend=''): + BaseMenuItem.__init__(self, name, action, iconimage) + self.params['backend'] = backend + + +class MenuItemPath(MenuItem): + + def __init__(self, collection, action=constants.DISPLAY_COLLECTION_MENU, iconimage="DefaultFolder.png"): + MenuItem.__init__(self, collection.title, action, iconimage, collection.fullid.split('@')[-1]) + self.params["path"] = '/'.join(collection.split_path) + + +class MenuItemVideo(BaseMenuLink): + def __init__(self, video, iconimage="DefaultFolder.png"): + name = '[%s] %s' % (video.backend, video.title) + BaseMenuLink.__init__(self, name, video.url, constants.VIDEO, + video.thumbnail.url if video.thumbnail.url else iconimage) + self.video = video + self.params["id"] = self.video.id + + def createVideoContextMenu(self): + cm = [] + + #Information + cm.append((common_xbmc.get_translation('30110'), "XBMC.Action(Info)")) + + #Téléchargement + url = "%s?action=%s&id=%s&backend=%s" % (sys.argv[0], constants.DOWNLOAD, self.video.id, self.video.backend) + cm.append((common_xbmc.get_translation('30100'), "XBMC.PlayMedia(%s)" % (url))) + + return cm + + def create_info_labels(self): + date, year = self.format_date(self.video.date) + + duration = 0 + if self.video.duration: + duration = u'%s' % str(self.video.duration.total_seconds()/60) if isinstance(self.video.duration, timedelta) else self.video.duration + + description = u'%s' % self.video.description + + return {"Title": self.video.title, + "Year": year, + "Plot": description, + "PlotOutline": description[0:30] if len(description) > 30 else description, + "Director": self.video.author if self.video.author else 'Unknown', + "Duration": duration, + "Date": date} + + def format_date(self, video_date): + date = datetime.now().strftime("%d/%m/%Y") + if video_date: + date = video_date.strftime("%d/%m/%Y") + + year = date.split('/')[-1] + return date, year diff --git a/contrib/plugin.video.videoobmc/resources/lib/test/__init__.py b/contrib/plugin.video.videoobmc/resources/lib/test/__init__.py index ee074ac5..b93054b3 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/test/__init__.py +++ b/contrib/plugin.video.videoobmc/resources/lib/test/__init__.py @@ -1 +1 @@ -# Dummy file to make this directory a package. +# Dummy file to make this directory a package. diff --git a/contrib/plugin.video.videoobmc/resources/lib/test/common_test.py b/contrib/plugin.video.videoobmc/resources/lib/test/common_test.py index 112cc496..0da8c54c 100644 --- a/contrib/plugin.video.videoobmc/resources/lib/test/common_test.py +++ b/contrib/plugin.video.videoobmc/resources/lib/test/common_test.py @@ -1,110 +1,110 @@ -# -*- coding: utf-8 -*- - -import urllib - - -def get_addon(): - pass - - -def get_translation(key): - translation = {'30000': 'Recherche', - '30001': 'Recherche :', - '30100': 'Télécharger', - '30110': 'Information', - '30200': 'Erreur!', - '30300': 'Information', - '30301': 'Lancement du téléchargement', - '30302': 'Fichier téléchargé avec succès', - '30551': 'Debut de la mise à jour', - '30552': 'Weboob est maintenant à jour'} - return translation.get(key) - - -def get_addon_dir(): - return '/home/benjamin' - - -def get_settings(key): - settings = {'downloadPath': get_addon_dir(), - 'nbVideoPerBackend': '0', - 'nsfw': 'False'} - return settings.get(key) - - -def display_error(error): - print "%s: %s" % ("ERROR", error) - - -def display_info(msg): - print "%s: %s" % ("INFO", msg) - - -def parse_params(paramStr): - - paramDic = {} - # Parameters are on the 3rd arg passed to the script - if len(paramStr) > 1: - paramStr = paramStr.replace('?', '') - - # Ignore last char if it is a '/' - if paramStr[len(paramStr) - 1] == '/': - paramStr = paramStr[0:len(paramStr) - 2] - - # Processing each parameter splited on '&' - for param in paramStr.split('&'): - try: - # Spliting couple key/value - key, value = param.split('=') - except: - key = param - value = '' - - key = urllib.unquote_plus(key) - value = urllib.unquote_plus(value) - - # Filling dictionnary - paramDic[key] = value - return paramDic - - -def ask_user(content, title): - return raw_input(title) - - -def create_param_url(paramsDic, quote_plus=False): - - #url = sys.argv[0] - url = '' - sep = '?' - - try: - for param in paramsDic: - if quote_plus: - url = url + sep + urllib.quote_plus(param) + '=' + urllib.quote_plus(paramsDic[param]) - else: - url = "%s%s%s=%s" % (url, sep, param, paramsDic[param]) - - sep = '&' - except Exception, msg: - display_error("create_param_url %s" % msg) - url = None - return url - - -def add_menu_item(params={}): - print '%s => "%s"' % (params.get('name'), create_param_url(params)) - - -def add_menu_link(params={}): - print '[%s] %s (%s)' % (params.get('id'), params.get('name'), params.get('url')) - #print params.get('itemInfoLabels') - #print params.get('c_items') - - -def end_of_directory(update=False): - print '******************************************************' - - -def download_video(url, name, dir='./'): - print 'Downlaod a video %s from %s' % (name, url) +# -*- coding: utf-8 -*- + +import urllib + + +def get_addon(): + pass + + +def get_translation(key): + translation = {'30000': 'Recherche', + '30001': 'Recherche :', + '30100': 'Télécharger', + '30110': 'Information', + '30200': 'Erreur!', + '30300': 'Information', + '30301': 'Lancement du téléchargement', + '30302': 'Fichier téléchargé avec succès', + '30551': 'Debut de la mise à jour', + '30552': 'Weboob est maintenant à jour'} + return translation.get(key) + + +def get_addon_dir(): + return '/home/benjamin' + + +def get_settings(key): + settings = {'downloadPath': get_addon_dir(), + 'nbVideoPerBackend': '0', + 'nsfw': 'False'} + return settings.get(key) + + +def display_error(error): + print "%s: %s" % ("ERROR", error) + + +def display_info(msg): + print "%s: %s" % ("INFO", msg) + + +def parse_params(paramStr): + + paramDic = {} + # Parameters are on the 3rd arg passed to the script + if len(paramStr) > 1: + paramStr = paramStr.replace('?', '') + + # Ignore last char if it is a '/' + if paramStr[len(paramStr) - 1] == '/': + paramStr = paramStr[0:len(paramStr) - 2] + + # Processing each parameter splited on '&' + for param in paramStr.split('&'): + try: + # Spliting couple key/value + key, value = param.split('=') + except: + key = param + value = '' + + key = urllib.unquote_plus(key) + value = urllib.unquote_plus(value) + + # Filling dictionnary + paramDic[key] = value + return paramDic + + +def ask_user(content, title): + return raw_input(title) + + +def create_param_url(paramsDic, quote_plus=False): + + #url = sys.argv[0] + url = '' + sep = '?' + + try: + for param in paramsDic: + if quote_plus: + url = url + sep + urllib.quote_plus(param) + '=' + urllib.quote_plus(paramsDic[param]) + else: + url = "%s%s%s=%s" % (url, sep, param, paramsDic[param]) + + sep = '&' + except Exception as msg: + display_error("create_param_url %s" % msg) + url = None + return url + + +def add_menu_item(params={}): + print '%s => "%s"' % (params.get('name'), create_param_url(params)) + + +def add_menu_link(params={}): + print '[%s] %s (%s)' % (params.get('id'), params.get('name'), params.get('url')) + #print params.get('itemInfoLabels') + #print params.get('c_items') + + +def end_of_directory(update=False): + print '******************************************************' + + +def download_video(url, name, dir='./'): + print 'Downlaod a video %s from %s' % (name, url)