Skip to content

Commit

Permalink
Rename Custom Source -> External Source
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts committed Jan 30, 2021
1 parent 876677e commit e4ebdf0
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 97 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ More information and documentation for developers can be found on our [Wiki page

## Features
* Integrates Live TV Channels with EPG data in Kodi from supported IPTV Add-ons
* Supports external sources so you can specify your own `M3U` and `XMLTV` files to merge from a file or a http(s)://-url
* Allows playback of past and future programs directly from the EPG

## Screenshots
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.el_gr/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ msgid "Supported Add-ons"
msgstr ""

msgctxt "#30012"
msgid "Custom Sources"
msgid "External Sources"
msgstr ""

msgctxt "#30013"
msgid "Add Source…"
msgid "Add external source…"
msgstr ""

msgctxt "#30014"
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ msgid "Supported Add-ons"
msgstr ""

msgctxt "#30012"
msgid "Custom Sources"
msgid "External Sources"
msgstr ""

msgctxt "#30013"
msgid "Add Source…"
msgid "Add external source…"
msgstr ""

msgctxt "#30014"
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.hu_hu/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ msgid "Supported Add-ons"
msgstr ""

msgctxt "#30012"
msgid "Custom Sources"
msgid "External Sources"
msgstr ""

msgctxt "#30013"
msgid "Add Source…"
msgid "Add external source…"
msgstr ""

msgctxt "#30014"
Expand Down
8 changes: 4 additions & 4 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ msgid "Supported Add-ons"
msgstr "Ondersteunde Add-ons"

msgctxt "#30012"
msgid "Custom Sources"
msgstr "Extra bronnen"
msgid "External Sources"
msgstr "Externe bronnen"

msgctxt "#30013"
msgid "Add Source…"
msgstr "Bron toevoegen…"
msgid "Add external source…"
msgstr "Externe bron toevoegen…"

msgctxt "#30014"
msgid "Delete Source"
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.ro_ro/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ msgid "Supported Add-ons"
msgstr ""

msgctxt "#30012"
msgid "Custom Sources"
msgid "External Sources"
msgstr ""

msgctxt "#30013"
msgid "Add Source…"
msgid "Add external source…"
msgstr ""

msgctxt "#30014"
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.ru_ru/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ msgid "Supported Add-ons"
msgstr ""

msgctxt "#30012"
msgid "Custom Sources"
msgid "External Sources"
msgstr ""

msgctxt "#30013"
msgid "Add Source…"
msgid "Add external source…"
msgstr ""

msgctxt "#30014"
Expand Down
65 changes: 35 additions & 30 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from resources.lib.modules.iptvsimple import IptvSimple
from resources.lib.modules.sources import Sources
from resources.lib.modules.sources.addon import AddonSource
from resources.lib.modules.sources.custom import CustomSource
from resources.lib.modules.sources.external import ExternalSource

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,37 +94,42 @@ def refresh():
def show_sources():
""" Show the sources menu. """
listing = []
listing.append(TitleItem(
title='[B]%s[/B]' % kodiutils.localize(30011), # Supported Add-ons
path=None,
art_dict=dict(
icon='empty.png',
),
))
for addon in AddonSource.detect_sources():
if addon.enabled:
path = kodiutils.url_for('disable_source', addon_id=addon.addon_id)
else:
path = kodiutils.url_for('enable_source', addon_id=addon.addon_id)

addon_sources = AddonSource.detect_sources()
external_sources = ExternalSource.detect_sources()

if addon_sources:
listing.append(TitleItem(
title=kodiutils.addon_name(addon.addon_obj),
path=path,
title='[B]%s[/B]' % kodiutils.localize(30011), # Supported Add-ons
path=None,
art_dict=dict(
icon='icons/infodialogs/enabled.png' if addon.enabled else 'icons/infodialogs/disable.png',
poster=kodiutils.addon_icon(addon.addon_obj),
icon='empty.png',
),
))
for addon in addon_sources:
if addon.enabled:
path = kodiutils.url_for('disable_source', addon_id=addon.addon_id)
else:
path = kodiutils.url_for('enable_source', addon_id=addon.addon_id)

listing.append(TitleItem(
title=kodiutils.addon_name(addon.addon_obj),
path=path,
art_dict=dict(
icon='icons/infodialogs/enabled.png' if addon.enabled else 'icons/infodialogs/disable.png',
poster=kodiutils.addon_icon(addon.addon_obj),
),
))

listing.append(TitleItem(
title='[B]%s[/B]' % kodiutils.localize(30012), # Custom Sources
title='[B]%s[/B]' % kodiutils.localize(30012), # External Sources
path=None,
art_dict=dict(
icon='empty.png',
),
))

for source in CustomSource.detect_sources():
for source in external_sources:
context_menu = [(
kodiutils.localize(30014), # Delete this Source
'Container.Update(%s)' %
Expand All @@ -142,7 +147,7 @@ def show_sources():
))

listing.append(TitleItem(
title=kodiutils.localize(30013), # Add Source
title=kodiutils.localize(30013), # Add Source
path=kodiutils.url_for('add_source'),
art_dict=dict(
icon='DefaultAddSource.png',
Expand All @@ -168,9 +173,9 @@ def disable_addon_source(addon_id):
@staticmethod
def add_source():
""" Add a new source. """
source = CustomSource(uuid=str(uuid4()),
name='Custom Source', # Default name
enabled=False)
source = ExternalSource(uuid=str(uuid4()),
name='External Source', # Default name
enabled=False)
source.save()

# Go to edit page
Expand All @@ -179,7 +184,7 @@ def add_source():
@staticmethod
def delete_source(uuid):
""" Add a new source. """
sources = CustomSource.detect_sources()
sources = ExternalSource.detect_sources()
source = next(source for source in sources if source.uuid == uuid)
source.delete()

Expand All @@ -188,7 +193,7 @@ def delete_source(uuid):
@staticmethod
def edit_source(uuid, edit=None):
""" Edit a custom source. """
sources = CustomSource.detect_sources()
sources = ExternalSource.detect_sources()
source = next(source for source in sources if source.uuid == uuid)

if source is None:
Expand Down Expand Up @@ -282,22 +287,22 @@ def _select_source(current_type, current_source, mask):
if res == 0:
# None
new_source = None
new_type = CustomSource.TYPE_NONE
new_type = ExternalSource.TYPE_NONE

elif res == 1:
# Enter URL
url = kodiutils.input_dialog(heading=kodiutils.localize(30030), # Enter URL
message=current_source if current_type == CustomSource.TYPE_URL else '')
message=current_source if current_type == ExternalSource.TYPE_URL else '')
if url:
new_source = url
new_type = CustomSource.TYPE_URL
new_type = ExternalSource.TYPE_URL

elif res == 2:
# Browse for file...
filename = kodiutils.file_dialog(kodiutils.localize(30031), mask=mask, # Browse for file
default=current_source if current_type == CustomSource.TYPE_FILE else '')
default=current_source if current_type == ExternalSource.TYPE_FILE else '')
if filename:
new_source = filename
new_type = CustomSource.TYPE_FILE
new_type = ExternalSource.TYPE_FILE

return new_type, new_source
7 changes: 4 additions & 3 deletions resources/lib/modules/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def refresh(cls, show_progress=False):
from resources.lib.modules.sources.addon import AddonSource
addon_sources = AddonSource.detect_sources()

from resources.lib.modules.sources.custom import CustomSource
custom_sources = CustomSource.detect_sources()
from resources.lib.modules.sources.external import ExternalSource
external_sources = ExternalSource.detect_sources()

sources = [source for source in addon_sources + custom_sources if source.enabled]
sources = [source for source in addon_sources + external_sources if source.enabled]

for index, source in enumerate(sources):
# Skip Add-ons that have IPTV Manager support disabled
Expand Down Expand Up @@ -161,6 +161,7 @@ def _decompress_gz(data):
return decompress(data).decode()
except ImportError: # Python 2
from gzip import GzipFile

from StringIO import StringIO
with GzipFile(fileobj=StringIO(data)) as fdesc:
return fdesc.read().decode()
Expand Down
1 change: 1 addition & 0 deletions resources/lib/modules/sources/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def update_qs(url, **params):
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
except ImportError: # Python 2
from urllib import urlencode

from urlparse import parse_qsl, urlparse, urlunparse
url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
_LOGGER = logging.getLogger(__name__)


class CustomSource(Source):
""" Defines a Custom source """
class ExternalSource(Source):
""" Defines an External source """

SOURCES_FILE = 'sources.json'

Expand All @@ -24,7 +24,7 @@ class CustomSource(Source):

def __init__(self, uuid, name, enabled, playlist_uri=None, playlist_type=TYPE_NONE, epg_uri=None, epg_type=TYPE_NONE):
""" Initialise object """
super(CustomSource, self).__init__()
super(ExternalSource, self).__init__()
self.uuid = uuid
self.name = name
self.enabled = enabled
Expand All @@ -38,26 +38,26 @@ def __str__(self):

@staticmethod
def detect_sources():
""" Load our sources that provide custom channel data
""" Load our sources that provide external channel data.
:rtype: list[CustomSource]
:rtype: list[ExternalSource]
"""
try:
with open(os.path.join(kodiutils.addon_profile(), CustomSource.SOURCES_FILE), 'r') as fdesc:
with open(os.path.join(kodiutils.addon_profile(), ExternalSource.SOURCES_FILE), 'r') as fdesc:
result = json.loads(fdesc.read())
except (IOError, TypeError, ValueError):
result = {}

sources = []
for source in result.values():
sources.append(CustomSource(
sources.append(ExternalSource(
uuid=source.get('uuid'),
name=source.get('name'),
enabled=source.get('enabled'),
playlist_uri=source.get('playlist_uri'),
playlist_type=source.get('playlist_type', CustomSource.TYPE_NONE),
playlist_type=source.get('playlist_type', ExternalSource.TYPE_NONE),
epg_uri=source.get('epg_uri'),
epg_type=source.get('epg_type', CustomSource.TYPE_NONE),
epg_type=source.get('epg_type', ExternalSource.TYPE_NONE),
))

return sources
Expand Down Expand Up @@ -113,28 +113,28 @@ def save(self):
if not os.path.exists(output_path):
os.mkdir(output_path)

with open(os.path.join(output_path, CustomSource.SOURCES_FILE), 'r') as fdesc:
with open(os.path.join(output_path, ExternalSource.SOURCES_FILE), 'r') as fdesc:
sources = json.loads(fdesc.read())
except (IOError, TypeError, ValueError):
sources = {}

# Update the element with my uuid
sources[self.uuid] = self.__dict__

with open(os.path.join(output_path, CustomSource.SOURCES_FILE), 'w') as fdesc:
with open(os.path.join(output_path, ExternalSource.SOURCES_FILE), 'w') as fdesc:
json.dump(sources, fdesc)

def delete(self):
""" Delete this source. """
output_path = kodiutils.addon_profile()
try:
with open(os.path.join(output_path, CustomSource.SOURCES_FILE), 'r') as fdesc:
with open(os.path.join(output_path, ExternalSource.SOURCES_FILE), 'r') as fdesc:
sources = json.loads(fdesc.read())
except (IOError, TypeError, ValueError):
sources = {}

# Remove the element with my uuid
sources.pop(self.uuid)

with open(os.path.join(output_path, CustomSource.SOURCES_FILE), 'w') as fdesc:
with open(os.path.join(output_path, ExternalSource.SOURCES_FILE), 'w') as fdesc:
json.dump(sources, fdesc)
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from resources.lib import kodiutils
from resources.lib.modules.contextmenu import ContextMenu
from resources.lib.modules.sources import Sources
from resources.lib.modules.sources.custom import CustomSource
from resources.lib.modules.sources.external import ExternalSource


class IntegrationTest(unittest.TestCase):
Expand All @@ -37,14 +37,14 @@ def test_refresh(self):
if os.path.exists(path):
os.unlink(path)

# Add a custom source
source = CustomSource(uuid=str(uuid4()),
name='Custom Source',
enabled=True,
playlist_type=CustomSource.TYPE_FILE,
playlist_uri=os.path.realpath('tests/data/custom_playlist.m3u'),
epg_type=CustomSource.TYPE_FILE,
epg_uri=os.path.realpath('tests/data/custom_epg.xml'))
# Add an external source
source = ExternalSource(uuid=str(uuid4()),
name='External Source',
enabled=True,
playlist_type=ExternalSource.TYPE_FILE,
playlist_uri=os.path.realpath('tests/data/external_playlist.m3u'),
epg_type=ExternalSource.TYPE_FILE,
epg_uri=os.path.realpath('tests/data/external_epg.xml'))
source.save()

# Do the refresh
Expand Down
Loading

0 comments on commit e4ebdf0

Please sign in to comment.