Skip to content

Commit

Permalink
Merge pull request #27 from lrusak/custom-channels
Browse files Browse the repository at this point in the history
allow using custom update channels
  • Loading branch information
chewitt authored Jun 24, 2016
2 parents eeec324 + 8089008 commit 9a56a7c
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 24 deletions.
28 changes: 28 additions & 0 deletions language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ msgid "Select an update channel"
msgstr ""

msgctxt "#761"
msgid "Enable to allow entering a custom update url"
msgstr ""

msgctxt "#762"
msgid "Enter a custom update url (url should be the root of the update files)"
msgstr ""

msgctxt "#770"
msgid "Select an available version"
msgstr ""

Expand Down Expand Up @@ -276,6 +284,22 @@ msgctxt "#32015"
msgid "Update Channel"
msgstr ""

msgctxt "#32016"
msgid "Show Custom Channels"
msgstr ""

msgctxt "#32017"
msgid " - Custom Channel 1"
msgstr ""

msgctxt "#32018"
msgid " - Custom Channel 2"
msgstr ""

msgctxt "#32019"
msgid " - Custom Channel 3"
msgstr ""

msgctxt "#32020"
msgid "Available Versions"
msgstr ""
Expand Down Expand Up @@ -484,6 +508,10 @@ msgctxt "#32190"
msgid "System Name"
msgstr ""

msgctxt "#32191"
msgid "Invalid URL"
msgstr ""

msgctxt "#32196"
msgid "About"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion src/oe.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def download_file(source, destination, silent=False):
if silent == False:
download_dlg = xbmcgui.DialogProgress()
download_dlg.create('LibreELEC', _(32181).encode('utf-8'), ' ', ' ')
response = urllib2.urlopen(source)
response = urllib2.urlopen(urllib2.quote(source, safe=':/'))
total_size = int(response.info().getheader('Content-Length').strip())
minutes = 0
seconds = 0
Expand Down
156 changes: 134 additions & 22 deletions src/resources/lib/modules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,54 @@ def __init__(self, oeMain):
'InfoText': 715,
'order': 2,
},
'ShowCustomChannels': {
'name': 32016,
'value': '0',
'action': 'set_custom_channel',
'type': 'bool',
'parent': {
'entry': 'AutoUpdate',
'value': ['manual'],
},
'InfoText': 761,
'order': 3,
},
'CustomChannel1': {
'name': 32017,
'value': '',
'action': 'set_custom_channel',
'type': 'text',
'parent': {
'entry': 'ShowCustomChannels',
'value': ['1'],
},
'InfoText': 762,
'order': 4,
},
'CustomChannel2': {
'name': 32018,
'value': '',
'action': 'set_custom_channel',
'type': 'text',
'parent': {
'entry': 'ShowCustomChannels',
'value': ['1'],
},
'InfoText': 762,
'order': 5,
},
'CustomChannel3': {
'name': 32019,
'value': '',
'action': 'set_custom_channel',
'type': 'text',
'parent': {
'entry': 'ShowCustomChannels',
'value': ['1'],
},
'InfoText': 762,
'order': 6,
},
'Channel': {
'name': 32015,
'value': '',
Expand All @@ -164,7 +212,7 @@ def __init__(self, oeMain):
},
'values': [],
'InfoText': 760,
'order': 3,
'order': 7,
},
'Build': {
'name': 32020,
Expand All @@ -176,8 +224,8 @@ def __init__(self, oeMain):
'value': ['manual'],
},
'values': [],
'InfoText': 761,
'order': 4,
'InfoText': 770,
'order': 8,
},
},
},
Expand Down Expand Up @@ -339,8 +387,22 @@ def load_values(self):
value = self.oe.read_setting('system', 'Channel')
if not value is None:
self.struct['update']['settings']['Channel']['value'] = value
value = self.oe.read_setting('system', 'ShowCustomChannels')
if not value is None:
self.struct['update']['settings']['ShowCustomChannels']['value'] = value

value = self.oe.read_setting('system', 'CustomChannel1')
if not value is None:
self.struct['update']['settings']['CustomChannel1']['value'] = value
value = self.oe.read_setting('system', 'CustomChannel2')
if not value is None:
self.struct['update']['settings']['CustomChannel2']['value'] = value
value = self.oe.read_setting('system', 'CustomChannel3')
if not value is None:
self.struct['update']['settings']['CustomChannel3']['value'] = value

self.update_json = self.build_json()

self.update_json = self.get_json()
self.struct['update']['settings']['Channel']['values'] = self.get_channels()
self.struct['update']['settings']['Build']['values'] = self.get_available_builds()

Expand Down Expand Up @@ -546,14 +608,37 @@ def set_channel(self, listItem=None):
except Exception, e:
self.oe.dbg_log('system::set_channel', 'ERROR: (' + repr(e) + ')')

def set_custom_channel(self, listItem=None):
try:
self.oe.dbg_log('system::set_custom_channel', 'enter_function', 0)
if not listItem == None:
self.set_value(listItem)
if listItem.getProperty('entry') != 'ShowCustomChannels':
if self.get_json(listItem.getProperty('value')) is None:
xbmcDialog = xbmcgui.Dialog()
xbmcDialog.ok('LibreELEC Update', self.oe._(32191).encode('utf-8'))
xbmcDialog = None
del xbmcDialog
self.update_json = self.build_json()
self.struct['update']['settings']['Channel']['values'] = self.get_channels()
if not self.struct['update']['settings']['Channel']['values'] is None:
if not self.struct['update']['settings']['Channel']['value'] in self.struct['update']['settings']['Channel']['values']:
self.struct['update']['settings']['Channel']['value'] = None
self.struct['update']['settings']['Build']['values'] = self.get_available_builds()
self.oe.dbg_log('system::set_custom_channel', 'exit_function', 0)
except Exception, e:
self.oe.dbg_log('system::set_custom_channel', 'ERROR: (' + repr(e) + ')')

def get_channels(self):
try:
self.oe.dbg_log('system::get_channels', 'enter_function', 0)
channels = []
for channel in self.update_json:
channels.append(channel)
return channels
self.oe.dbg_log('system::get_channels', unicode(self.update_json), 0)
if not self.update_json is None:
for channel in self.update_json:
channels.append(channel)
self.oe.dbg_log('system::get_channels', 'exit_function', 0)
return channels
except Exception, e:
self.oe.dbg_log('system::get_channels', 'ERROR: (' + repr(e) + ')')

Expand All @@ -563,11 +648,11 @@ def do_manual_update(self, listItem=None):
if not listItem == None:
self.struct['update']['settings']['Build']['value'] = listItem.getProperty('value')
if self.struct['update']['settings']['Build']['value'] != '':
self.update_file = self.UPDATE_DOWNLOAD_URL % ('releases', self.struct['update']['settings']['Build']['value'])
self.update_file = self.update_json[self.struct['update']['settings']['Channel']['value']]['url'] + self.struct['update']['settings']['Build']['value']
xbmcDialog = xbmcgui.Dialog()
answer = xbmcDialog.yesno('LibreELEC Update', self.oe._(32188).encode('utf-8') + ': ' + self.oe.VERSION,
self.oe._(32187).encode('utf-8') + ': ' + self.struct['update']['settings']['Build']['value'].split('-'
)[-1].replace('.tar', '').encode('utf-8'), self.oe._(32180).encode('utf-8'))
self.oe._(32187).encode('utf-8') + ': ' + re.findall(r'([0-9]+.[0-9].*)', self.struct['update']['settings']['Build']['value'].replace('.tar', '').encode('utf-8'))[0],
self.oe._(32180).encode('utf-8'))
xbmcDialog = None
del xbmcDialog
if answer:
Expand All @@ -578,28 +663,55 @@ def do_manual_update(self, listItem=None):
except Exception, e:
self.oe.dbg_log('system::do_manual_update', 'ERROR: (' + repr(e) + ')')

def get_json(self):
def get_json(self, url=None):
try:
self.oe.dbg_log('system::get_json', 'enter_function', 0)
url = self.UPDATE_DOWNLOAD_URL % ('releases', 'releases.json')
update_json = json.loads(self.oe.load_url(url))
return update_json
if url is None:
url = self.UPDATE_DOWNLOAD_URL % ('releases', 'releases.json')
if url.split('/')[-1] != 'releases.json':
url = url + '/releases.json'
data = self.oe.load_url(url)
if not data is None:
update_json = json.loads(data)
else:
update_json = None
self.oe.dbg_log('system::get_json', 'exit_function', 0)
return update_json
except Exception, e:
self.oe.dbg_log('system::get_json', 'ERROR: (' + repr(e) + ')')

def build_json(self):
try:
self.oe.dbg_log('system::build_json', 'enter_function', 0)
update_json = self.get_json()
if self.struct['update']['settings']['ShowCustomChannels']['value'] == '1':
custom_urls = []
for i in 1,2,3:
custom_urls.append(self.struct['update']['settings']['CustomChannel' + str(i)]['value'])
for custom_url in custom_urls:
if custom_url != '':
custom_update_json = self.get_json(custom_url)
if not custom_update_json is None:
for channel in custom_update_json:
update_json[channel] = custom_update_json[channel]
self.oe.dbg_log('system::build_json', 'exit_function', 0)
return update_json
except Exception, e:
self.oe.dbg_log('system::build_json', 'ERROR: (' + repr(e) + ')')

def get_available_builds(self):
try:
self.oe.dbg_log('system::get_available_builds', 'enter_function', 0)
channel = self.struct['update']['settings']['Channel']['value']
update_files = []
if channel != '':
if channel in self.update_json:
for i in self.update_json[channel]['project'][self.oe.ARCHITECTURE]['releases']:
update_files.append(self.update_json[channel]['project'][self.oe.ARCHITECTURE]['releases'][i]['file']['name'])

return update_files
if not self.update_json is None:
if channel != '':
if channel in self.update_json:
if self.oe.ARCHITECTURE in self.update_json[channel]['project']:
for i in self.update_json[channel]['project'][self.oe.ARCHITECTURE]['releases']:
update_files.append(self.update_json[channel]['project'][self.oe.ARCHITECTURE]['releases'][i]['file']['name'])
self.oe.dbg_log('system::get_available_builds', 'exit_function', 0)
return update_files
except Exception, e:
self.oe.dbg_log('system::get_available_builds', 'ERROR: (' + repr(e) + ')')

Expand Down Expand Up @@ -640,12 +752,12 @@ def do_autoupdate(self, listItem=None, silent=False):
if hasattr(self, 'update_file'):
if not os.path.exists(self.LOCAL_UPDATE_DIR):
os.makedirs(self.LOCAL_UPDATE_DIR)
downloaded = self.oe.download_file(self.update_file, self.oe.TEMP + self.update_file.split('/')[-1], silent)
downloaded = self.oe.download_file(self.update_file, self.oe.TEMP + 'update_file', silent)
if not downloaded is None:
self.update_file = self.update_file.split('/')[-1]
if self.struct['update']['settings']['UpdateNotify']['value'] == '1':
self.oe.notify(self.oe._(32363), self.oe._(32366))
os.rename(self.oe.TEMP + self.update_file, self.LOCAL_UPDATE_DIR + self.update_file)
os.rename(self.oe.TEMP + 'update_file', self.LOCAL_UPDATE_DIR + self.update_file)
subprocess.call('sync', shell=True, stdin=None, stdout=None, stderr=None)
if silent == False:
self.oe.winOeMain.close()
Expand Down
2 changes: 1 addition & 1 deletion src/resources/lib/oeWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def onClick(self, controlID):
if strTyp == 'multivalue':
items1 = []
items2 = []
for item in selectedItem.getProperty('values').split('|'):
for item in sorted(selectedItem.getProperty('values').split('|'), reverse=True):
if item != ':':
boo = item.split(':')
if len(boo) > 1:
Expand Down

0 comments on commit 9a56a7c

Please sign in to comment.