Skip to content

Commit

Permalink
Merge pull request #66 from nwithan8/develop
Browse files Browse the repository at this point in the history
Prepare v1.2.2
  • Loading branch information
nwithan8 authored Nov 24, 2020
2 parents ec06a2e + 09607a2 commit a9a5975
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Enable verbose logging by passing ``verbose=True`` into the ``API`` object decla
- ``lateness``: int
- ``maxDays``: int
- ``slots``: List of ``TimeSlot`` objects
- ``flexPreference``: str ("end" or "distribute")
- ``pad``: int
- ``timeZoneOffset``: int

Expand Down
3 changes: 2 additions & 1 deletion dizqueTV/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__version__ = '1.2.1.0'
__version__ = '1.2.2.0'
__author__ = 'Nate Harris'
__copyright__ = "2020, Nate Harris"
21 changes: 11 additions & 10 deletions dizqueTV/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,9 @@ def add_schedule(self, time_slots: List[TimeSlot], **kwargs) -> bool:
"""
for slot in time_slots:
kwargs['slots'].append(slot._data)
schedule_settings = helpers._combine_settings(new_settings_dict=kwargs,
template_dict=SCHEDULE_SETTINGS_DEFAULT)
schedule_settings = helpers._combine_settings_enforce_types(new_settings_dict=kwargs,
template_dict=SCHEDULE_SETTINGS_TEMPLATE,
default_dict=SCHEDULE_SETTINGS_DEFAULT)
if helpers._settings_are_complete(new_settings_dict=schedule_settings,
template_settings_dict=SCHEDULE_SETTINGS_TEMPLATE):
schedule = Schedule(data=schedule_settings, dizque_instance=None, channel_instance=self)
Expand Down Expand Up @@ -978,7 +979,7 @@ def remove_redirects(self) -> bool:
"""
non_redirects = []
for item in self.programs:
if not helpers._object_has_attribute(object=item, attribute_name='type') or item.type != 'redirect':
if not helpers._object_has_attribute(obj=item, attribute_name='type') or item.type != 'redirect':
non_redirects.append(item)
if non_redirects and self.delete_all_programs():
return self.add_programs(programs=non_redirects)
Expand All @@ -994,10 +995,10 @@ def remove_specials(self) -> bool:
:rtype: bool
"""
non_redirects = [item for item in self.programs if
(helpers._object_has_attribute(object=item, attribute_name='type')
(helpers._object_has_attribute(obj=item, attribute_name='type')
and item.type != 'redirect')]
non_specials = [item for item in non_redirects if
(helpers._object_has_attribute(object=item, attribute_name='season')
(helpers._object_has_attribute(obj=item, attribute_name='season')
and item.season != 0)]
if non_specials and self.delete_all_programs():
return self.add_programs(programs=non_specials)
Expand Down Expand Up @@ -1149,11 +1150,11 @@ def add_channel_at_night_alt(self,
)
final_programs_to_add = []
all_programs = self.programs
programs_to_add, total_running_time = helpers._get_first_x_minutes_of_programs(programs=all_programs,
minutes=int(
time_until_night_block_start /
1000 / 60)
)
programs_to_add, total_running_time = helpers._get_first_x_minutes_of_programs(
programs=all_programs,
minutes=int(
time_until_night_block_start / 1000 / 60)
)
if len(programs_to_add) == len(all_programs): # all programs can play before night channel even starts
if total_running_time < time_until_night_block_start: # add flex time between last item and night channel
time_needed = time_until_night_block_start - total_running_time
Expand Down
9 changes: 6 additions & 3 deletions dizqueTV/dizquetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def make_time_slot_from_dizque_program(program: Union[Program, Redirect],
item = TimeSlotItem(item_type='tv', item_value=program.showTitle)
else:
return None
data = {'time': helpers.convert_24_time_to_milliseconds_past_midnight(time_string=time), 'showId': item.showId, 'order': order}
data = {'time': helpers.convert_24_time_to_milliseconds_past_midnight(time_string=time),
'showId': item.showId,
'order': order}
return TimeSlot(data=data, program=item)


Expand Down Expand Up @@ -434,7 +436,8 @@ def _fill_in_default_channel_settings(self, settings_dict: dict, handle_errors:
# override duration regardless of user input
settings_dict['duration'] = sum(program['duration'] for program in settings_dict['programs'])
settings_dict['watermark'] = self._fill_in_watermark_settings(**settings_dict)
return helpers._combine_settings_add_new(new_settings_dict=settings_dict, template_dict=CHANNEL_SETTINGS_DEFAULT)
return helpers._combine_settings_add_new(new_settings_dict=settings_dict,
template_dict=CHANNEL_SETTINGS_DEFAULT)

def add_channel(self,
programs: List[Union[Program, Redirect, Video, Movie, Episode]] = None,
Expand Down Expand Up @@ -514,7 +517,7 @@ def _make_schedule(self, channel: Channel, schedule: Schedule = None, schedule_s
data = {'programs': []}
if schedule:
data['schedule'] = (schedule._data
if helpers._object_has_attribute(object=schedule, attribute_name="_data")
if helpers._object_has_attribute(obj=schedule, attribute_name="_data")
else {})
else:
data['schedule'] = schedule_settings
Expand Down
62 changes: 45 additions & 17 deletions dizqueTV/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ def _combine_settings(new_settings_dict: dict, template_dict: dict, ignore_keys:
template_dict[k] = v
return template_dict

def _combine_settings_enforce_types(new_settings_dict: dict, template_dict: dict, default_dict: dict, ignore_keys: List = None) -> dict:
"""
Build a complete dictionary for new settings, using old settings as a base
Do not add new keys to template
Enforce default options
:param new_settings_dict: Dictionary of new settings kwargs
:param template_dict: settings template
:param default_dict: default settings
:param ignore_keys: List of keys to ignore when combining dictionaries
:return: Dictionary of new settings
:rtype: dict
"""
if not ignore_keys:
ignore_keys = []
for k, v in new_settings_dict.items():
if k in template_dict.keys():
if k in ignore_keys:
pass
else:
if type(v) == template_dict[k]:
template_dict[k] = v
elif v in template_dict[k]:
template_dict[k] = v
else:
template_dict[k] = default_dict[k]
return template_dict


def _filter_dictionary(new_dictionary: dict, template_dict: dict) -> dict:
"""
Expand Down Expand Up @@ -137,17 +166,17 @@ def convert_icon_position(position_text) -> str:
return '3'


def _object_has_attribute(object, attribute_name: str) -> bool:
def _object_has_attribute(obj, attribute_name: str) -> bool:
"""
Check if an object has an attribute (exists and is not None)
:param object: object to check
:param obj: object to check
:param attribute_name: name of attribute to find
:return: True if exists and is not None, False otherwise
:rtype: bool
"""
if hasattr(object, attribute_name):
if getattr(object, attribute_name) is not None:
if hasattr(obj, attribute_name):
if getattr(obj, attribute_name) is not None:
return True
return False

Expand Down Expand Up @@ -267,7 +296,7 @@ def _separate_with_and_without(items: List, attribute_name: str) -> Tuple[List,
items_with = []
items_without = []
for item in items:
if _object_has_attribute(object=item, attribute_name=attribute_name):
if _object_has_attribute(obj=item, attribute_name=attribute_name):
items_with.append(item)
else:
items_without.append(item)
Expand All @@ -284,7 +313,7 @@ def get_items_of_type(item_type: str, items: List) -> List:
:rtype: list
"""
return [item for item in items if
(_object_has_attribute(object=item, attribute_name='type') and item.type == item_type)]
(_object_has_attribute(obj=item, attribute_name='type') and item.type == item_type)]


def get_items_of_not_type(item_type: str, items: List) -> List:
Expand All @@ -297,7 +326,7 @@ def get_items_of_not_type(item_type: str, items: List) -> List:
:rtype: list
"""
return [item for item in items if
(_object_has_attribute(object=item, attribute_name='type') and item.type != item_type)]
(_object_has_attribute(obj=item, attribute_name='type') and item.type != item_type)]


def get_non_shows(media_items: List) -> List:
Expand All @@ -309,8 +338,8 @@ def get_non_shows(media_items: List) -> List:
:rtype: list
"""
return [item for item in media_items if
((_object_has_attribute(object=item, attribute_name='type') and item.type != 'episode') or
(_object_has_attribute(object=item, attribute_name='season') and not item.season))]
((_object_has_attribute(obj=item, attribute_name='type') and item.type != 'episode') or
(_object_has_attribute(obj=item, attribute_name='season') and not item.season))]


def make_show_dict(media_items: List) -> dict:
Expand All @@ -324,7 +353,7 @@ def make_show_dict(media_items: List) -> dict:
"""
show_dict = {}
for item in media_items:
if _object_has_attribute(object=item, attribute_name='type') and item.type == 'episode' and item.episode:
if _object_has_attribute(obj=item, attribute_name='type') and item.type == 'episode' and item.episode:
if item.showTitle in show_dict.keys():
if item.season in show_dict[item.showTitle].keys():
show_dict[item.showTitle][item.season][item.episode] = item
Expand Down Expand Up @@ -698,8 +727,7 @@ def shuffle(items: List) -> bool:
random.shuffle(items)
return True
except:
pass
return False
return False


def rotate_items(items: List, shift_index: int = None) -> List:
Expand Down Expand Up @@ -830,8 +858,8 @@ def sort_media_by_duration(media_items: List[Union[Program, FillerItem]]) -> Lis
:rtype: list[Program | FillerItem]
"""
non_redirects = [item for item in media_items if
(_object_has_attribute(object=item, attribute_name='duration')
and _object_has_attribute(object=item, attribute_name='type')
(_object_has_attribute(obj=item, attribute_name='duration')
and _object_has_attribute(obj=item, attribute_name='type')
and item.type != 'redirect')]
sorted_media = sorted(non_redirects, key=lambda x: x.duration)
return sorted_media
Expand Down Expand Up @@ -991,12 +1019,12 @@ def remove_non_programs(media_items: List[Union[Program, Redirect, FillerItem]])
:rtype: list[Program | FillerItem]
"""
return [item for item in media_items if
(_object_has_attribute(object=item, attribute_name='type')
(_object_has_attribute(obj=item, attribute_name='type')
and item.type != 'redirect')]


def remove_duplicate_media_items(media_items: List[Union[Program, Redirect, FillerItem]]) -> List[
Union[Program, FillerItem]]:
def remove_duplicate_media_items(media_items: List[Union[Program, Redirect, FillerItem]]) -> \
List[Union[Program, FillerItem]]:
"""
Remove duplicate items from list of media items.
Check by ratingKey.
Expand Down
6 changes: 4 additions & 2 deletions dizqueTV/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@
SCHEDULE_SETTINGS_TEMPLATE = {
"lateness": int,
"maxDays": int,
"flexPreference": ["end", "distribute"],
"slots": [],
"pad": int,
"timeZoneOffset": int
"timeZoneOffset": int,
}

SCHEDULE_SETTINGS_DEFAULT = {
"lateness": 0,
"maxDays": 365,
"flexPreference": "distribute",
"slots": [],
"pad": 1,
"timeZoneOffset": 0
"timeZoneOffset": 0,
}

CHANNEL_SETTINGS_TEMPLATE = {
Expand Down
10 changes: 6 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from dizqueTV import _version

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand All @@ -18,11 +20,11 @@
# -- Project information -----------------------------------------------------

project = 'dizqueTV'
copyright = '2020, Nate Harris'
author = 'Nate Harris'
copyright = _version.__copyright__
author = _version.__author__

# The full version, including alpha/beta/rc tags
release = '0.0.64'
release = _version.__version__


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -52,4 +54,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
author=dizqueTV._version.__author__, # Type in your name
author_email='[email protected]', # Type in your E-Mail
url='https://github.com/nwithan8/dizqueTV-python', # Provide either the link to your github or to your website
download_url=f'https://github.com/nwithan8/dizqueTV-python/archive/{dizqueTV._version.__version__}.tar.gz', # I explain this later on
download_url=f'https://github.com/nwithan8/dizqueTV-python/archive/{dizqueTV._version.__version__}.tar.gz',
keywords=[
'dizqueTV',
'Plex',
Expand Down

0 comments on commit a9a5975

Please sign in to comment.