예제 #1
0
    def handle_yt_state_change(self, request, session, data):
        user = self.flaskserver.get_user_by_request(request, session)
        if user.room is None:
            return

        if user.room.get_host_mode() and not user.room.is_creator(user):
            return

        offset = self.getval(data, 'offset', lambda x: isinstance(x, float),
                             lambda x: abs(float(x)), 0)
        rate = self.getval(data, 'rate', lambda x: isinstance(x, float),
                           lambda x: abs(float(x)), 1)
        run_at = self.getval(data, 'runAt', lambda x: isinstance(x, int),
                             lambda x: max(0, int(x)), 0)
        timestamp = self.getval(data, 'timestamp',
                                lambda x: isinstance(x, int), lambda x: int(x),
                                unix_timestamp())

        if data.get('state') not in [
                'ready', 'unstarted', 'ended', 'playing', 'paused',
                'buffering', 'cued', 'playback'
        ]:
            return

        user.room.emit(
            EVENT_YT_STATE_CHANGE, {
                'state': data['state'],
                'sender': user.username,
                'offset': offset,
                'rate': rate,
                'runAt': run_at,
                'timestamp': timestamp
            })
예제 #2
0
 def parent_path_id(self, path):
     """
     Video DB: Adds all subdirectories to path table while setting a "trail"
     of parent path ids
     """
     if "\\" in path:
         # Local path
         parentpath = "%s\\" % dirname(dirname(path))
     else:
         # Network path
         parentpath = "%s/" % dirname(dirname(path))
     pathid = self.get_path(parentpath)
     if pathid is None:
         self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
         pathid = self.cursor.fetchone()[0] + 1
         datetime = unix_date_to_kodi(unix_timestamp())
         query = '''
             INSERT INTO path(idPath, strPath, dateAdded)
             VALUES (?, ?, ?)
         '''
         self.cursor.execute(query, (pathid, parentpath, datetime))
         parent_id = self.parent_path_id(parentpath)
         query = 'UPDATE path SET idParentPath = ? WHERE idPath = ?'
         self.cursor.execute(query, (parent_id, pathid))
     return pathid
예제 #3
0
 def serialize(self):
     return {
         'message_id': self.message_id,
         'text': self.text,
         'timestamp': utils.unix_timestamp(self.timestamp),
         'room_id': self.room_id,
         'user_id': self.user_id,
         'user': self.userdata
     }
예제 #4
0
def _record_playstate(status, ended):
    with kodidb.GetKodiDB('video') as kodi_db:
        # Hack - remove any obsolete file entries Kodi made
        kodi_db.clean_file_table()
    if not status['plex_id']:
        LOG.debug('No Plex id found to record playstate for status %s', status)
        return
    with plexdb.Get_Plex_DB() as plex_db:
        kodi_db_item = plex_db.getItem_byId(status['plex_id'])
    if kodi_db_item is None:
        # Item not (yet) in Kodi library
        LOG.debug('No playstate update due to Plex id not found: %s', status)
        return
    totaltime = float(kodi_time_to_millis(status['totaltime'])) / 1000
    if ended:
        progress = 0.99
        time = v.IGNORE_SECONDS_AT_START + 1
    else:
        time = float(kodi_time_to_millis(status['time'])) / 1000
        try:
            progress = time / totaltime
        except ZeroDivisionError:
            progress = 0.0
        LOG.debug('Playback progress %s (%s of %s seconds)', progress, time,
                  totaltime)
    playcount = status['playcount']
    last_played = unix_date_to_kodi(unix_timestamp())
    if playcount is None:
        LOG.info('playcount not found, looking it up in the Kodi DB')
        with kodidb.GetKodiDB('video') as kodi_db:
            playcount = kodi_db.get_playcount(kodi_db_item[1])
        playcount = 0 if playcount is None else playcount
    if time < v.IGNORE_SECONDS_AT_START:
        LOG.debug('Ignoring playback less than %s seconds',
                  v.IGNORE_SECONDS_AT_START)
        # Annoying Plex bug - it'll reset an already watched video to unwatched
        playcount = 0
        last_played = None
        time = 0
    elif progress >= v.MARK_PLAYED_AT:
        LOG.debug('Recording entirely played video since progress > %s',
                  v.MARK_PLAYED_AT)
        playcount += 1
        time = 0
    with kodidb.GetKodiDB('video') as kodi_db:
        kodi_db.addPlaystate(kodi_db_item[1], time, totaltime, playcount,
                             last_played)
    # Hack to force "in progress" widget to appear if it wasn't visible before
    if (state.FORCE_RELOAD_SKIN
            and xbmc.getCondVisibility('Window.IsVisible(Home.xml)')):
        LOG.debug('Refreshing skin to update widgets')
        xbmc.executebuiltin('ReloadSkin()')
예제 #5
0
 def _create_filename(self) -> str:
     basename = unix_timestamp()
     filename = os.path.join(self.path, f"{basename}.json")
     return filename
예제 #6
0
 def save(self, file: FileStorage, filename: str) -> str:
     """"""
     savename = os.path.join(self.unprocessed_path,
                             str(unix_timestamp()) + filename)
     file.save(savename)
     return savename
예제 #7
0
def prepare_file_details(details: Dict[str, Any], filename: str, storage_method: str, reference: str) -> Dict[str, Any]:
    details["original_filename"] = filename
    details["upload_timestamp"] = unix_timestamp()
    details["storage_method"] = storage_method
    details["storage_reference"] = reference
    return details