<commit_before># -*- coding: utf-8 -*-
"""
    Copyright (C) 2017 <NAME> (plugin.video.netflix)
    Copyright (C) 2019 <NAME> - @CastagnaIT (original implementation module)
    Manages events to send to the netflix service for the progress of the played video

    SPDX-License-Identifier: MIT
    See LICENSES/MIT.md for more information.
"""
from __future__ import absolute_import, division, unicode_literals

import resources.lib.common as common
from resources.lib.services.msl.events_handler import EVENT_STOP, EVENT_KEEP_ALIVE, EVENT_START
from .action_manager import PlaybackActionManager


class ProgressManager(PlaybackActionManager):
    """Detect the progress of the played video and send the data to the netflix service"""

    def __init__(self):  # pylint: disable=super-on-old-class
        super(ProgressManager, self).__init__()
        self.current_videoid = None
        self.event_data = {}
        self.wait_for_first_start_event = True
        self.last_tick_count = 0
        self.tick_elapsed = 0
        self.last_player_state = {}
        self.is_video_started = False

    def _initialize(self, data):
        videoid = common.VideoId.from_dict(data['videoid'])
        if videoid.mediatype not in [common.VideoId.MOVIE, common.VideoId.EPISODE]:
            self.enabled = False
            return
        self.current_videoid = videoid \
            if videoid.mediatype == common.VideoId.MOVIE \
            else videoid.derive_parent(0)
        self.event_data = data['event_data']

    def _on_playback_started(self, player_state):
        self.tick_elapsed = 0
        self.player_elapsed_time = 0
        self.send_first_start_event = True
        self.is_video_started = True

    def _on_tick(self, player_state):
        if not self.is_video_started:
            return
        if self.wait_for_first_start_event:
            # Before start we have to wait a possible values changed by stream_continuity
            if self.tick_elapsed == 2:
                # Is needed to wait at least 2 seconds
                _send_event(EVENT_START, self.event_data, player_state)
                self.wait_for_first_start_event = False
        else:
            # Generate events to send to Netflix service every 1 minute
            if (self.tick_elapsed - self.last_tick_count) / 60 >= 1:
                # Todo: identify a possible fast forward / rewind
                _send_event(EVENT_KEEP_ALIVE, self.event_data, player_state)<commit_msg>Force event start time with 0 seconds<commit_after># -*- coding: utf-8 -*-
"""
    Copyright (C) 2017 <NAME> (plugin.video.netflix)
    Copyright (C) 2019 <NAME> - @CastagnaIT (original implementation module)
    Manages events to send to the netflix service for the progress of the played video

    SPDX-License-Identifier: MIT
    See LICENSES/MIT.md for more information.
"""
from __future__ import absolute_import, division, unicode_literals

import resources.lib.common as common
from resources.lib.services.msl.events_handler import EVENT_STOP, EVENT_KEEP_ALIVE, EVENT_START
from .action_manager import PlaybackActionManager


class ProgressManager(PlaybackActionManager):
    """Detect the progress of the played video and send the data to the netflix service"""

    def __init__(self):  # pylint: disable=super-on-old-class
        super(ProgressManager, self).__init__()
        self.current_videoid = None
        self.event_data = {}
        self.wait_for_first_start_event = True
        self.last_tick_count = 0
        self.tick_elapsed = 0
        self.last_player_state = {}
        self.is_video_started = False

    def _initialize(self, data):
        videoid = common.VideoId.from_dict(data['videoid'])
        if videoid.mediatype not in [common.VideoId.MOVIE, common.VideoId.EPISODE]:
            self.enabled = False
            return
        self.current_videoid = videoid \
            if videoid.mediatype == common.VideoId.MOVIE \
            else videoid.derive_parent(0)
        self.event_data = data['event_data']

    def _on_playback_started(self, player_state):
        self.tick_elapsed = 0
        self.player_elapsed_time = 0
        self.send_first_start_event = True
        self.is_video_started = True

    def _on_tick(self, player_state):
        if not self.is_video_started:
            return
        if self.wait_for_first_start_event:
            # Before start we have to wait a possible values changed by stream_continuity
            if self.tick_elapsed == 2:
                # Is needed to wait at least 2 seconds
                player_state['elapsed_seconds'] = 0  # Force set to 0
                _send_event(EVENT_START, self.event_data, player_state)
                self.wait_for_first_start_event = False
        else:
            # Generate events to send to Netflix service every 1 minute
            if (self.tick_elapsed - self.last_tick_count) / 60 >= 1:
                # Todo: identify a possible fast forward / rewind
                _send_event(EVENT_KEEP_ALIVE, self.event_data, player_state)
{'fraction_non_alphanumeric': 0.07545671167593328, 'fraction_numerical': 0.008538522637013502, 'mean_word_length': 2.639450867052023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '130334', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1430, 'n_words': 391}