class ScrobbleParser(Parser):
    pattern = str_format(
        LOG_PATTERN,
        message=
        r'Library item (?P<rating_key>\d+) \'(?P<title>.*?)\' got (?P<action>(?:un)?played) by account (?P<account_key>\d+)!.*?'
    )
    regex = re.compile(pattern, re.IGNORECASE)

    events = ['logging.action.played', 'logging.action.unplayed']

    def __init__(self, main):
        super(ScrobbleParser, self).__init__(main)

        # Pipe events to the main logging activity instance
        self.pipe(self.events, main)

    def process(self, line):
        match = self.regex.match(line)
        if not match:
            return False

        action = match.group('action')
        if not action:
            return False

        self.emit(
            'logging.action.%s' % action, {
                'account_key': match.group('account_key'),
                'rating_key': match.group('rating_key'),
                'title': match.group('title')
            })

        return True
Beispiel #2
0
from plex.lib.six.moves import urllib_parse as urlparse
from plex_activity.core.helpers import str_format

from pyemitter import Emitter
import logging
import re

log = logging.getLogger(__name__)

LOG_PATTERN = r'^.*?\[\w+\]\s\w+\s-\s{message}$'
REQUEST_HEADER_PATTERN = str_format(LOG_PATTERN, message=r"Request: (\[(?P<address>.*?):(?P<port>\d+)[^]]*\]\s)?{method} {path}.*?")

IGNORE_PATTERNS = [
    r'error parsing allowedNetworks.*?',
    r'Comparing request from.*?',
    r'(Auth: )?We found auth token (.*?), enabling token-based authentication\.',
    r'(Auth: )?Came in with a super-token, authorization succeeded\.',
    r'(Auth: )?Refreshing tokens inside the token-based authentication filter\.',
    r'\[Now\] Updated play state for .*?',
    r'Play progress on .*? - got played .*? ms by account .*?!',
    r'(Statistics: )?\(.*?\) Reporting active playback in state \d+ of type \d+ \(.*?\) for account \d+',
    r'Request: \[.*?\] (GET|PUT) /video/:/transcode/.*?',
    r'Received transcode session ping for session .*?'
]

IGNORE_REGEX = re.compile(str_format(LOG_PATTERN, message='(%s)' % ('|'.join('(%s)' % x for x in IGNORE_PATTERNS))), re.IGNORECASE)


PARAM_REGEX = re.compile(str_format(LOG_PATTERN, message=r' \* (?P<key>.*?) =\> (?P<value>.*?)'), re.IGNORECASE)

from plex_activity.core.helpers import str_format
from plex_activity.sources.s_logging.parsers.base import Parser, LOG_PATTERN, REQUEST_HEADER_PATTERN

import logging
import re

log = logging.getLogger(__name__)

PLAYING_HEADER_PATTERN = str_format(REQUEST_HEADER_PATTERN, method="GET", path="/:/(?P<type>timeline|progress)/?(?:\?(?P<query>.*?))?\s")
PLAYING_HEADER_REGEX = re.compile(PLAYING_HEADER_PATTERN, re.IGNORECASE)

RANGE_REGEX = re.compile(str_format(LOG_PATTERN, message=r'Request range: \d+ to \d+'), re.IGNORECASE)
CLIENT_REGEX = re.compile(str_format(LOG_PATTERN, message=r'Client \[(?P<machineIdentifier>.*?)\].*?'), re.IGNORECASE)

NOW_USER_REGEX = re.compile(str_format(LOG_PATTERN, message=r'\[Now\] User is (?P<user_name>.+) \(ID: (?P<user_id>\d+)\)'), re.IGNORECASE)
NOW_CLIENT_REGEX = re.compile(str_format(LOG_PATTERN, message=r'\[Now\] Device is (?P<product>.+?) \((?P<client>.+)\)\.'), re.IGNORECASE)


class NowPlayingParser(Parser):
    required_info = [
        'ratingKey',
        'state', 'time'
    ]

    extra_info = [
        'duration',

        'user_name', 'user_id',
        'machineIdentifier', 'client'
    ]
Beispiel #4
0
from plex.lib.six.moves import urllib_parse as urlparse
from plex_activity.core.helpers import str_format

from pyemitter import Emitter
import logging
import re

log = logging.getLogger(__name__)

LOG_PATTERN = r'^.*?\[\w+\]\s\w+\s-\s{message}$'
REQUEST_HEADER_PATTERN = str_format(
    LOG_PATTERN,
    message=
    r"Request: (\[(?P<address>.*?):(?P<port>\d+)[^]]*\]\s)?{method} {path}.*?")

IGNORE_PATTERNS = [
    r'error parsing allowedNetworks.*?', r'Comparing request from.*?',
    r'(Auth: )?We found auth token (.*?), enabling token-based authentication\.',
    r'(Auth: )?Came in with a super-token, authorization succeeded\.',
    r'(Auth: )?Refreshing tokens inside the token-based authentication filter\.',
    r'\[Now\] Updated play state for .*?',
    r'Play progress on .*? - got played .*? ms by account .*?!',
    r'(Statistics: )?\(.*?\) Reporting active playback in state \d+ of type \d+ \(.*?\) for account \d+',
    r'Request: \[.*?\] (GET|PUT) /video/:/transcode/.*?',
    r'Received transcode session ping for session .*?'
]

IGNORE_REGEX = re.compile(
    str_format(LOG_PATTERN,
               message='(%s)' % ('|'.join('(%s)' % x
                                          for x in IGNORE_PATTERNS))),
Beispiel #5
0
from plex_activity.core.helpers import str_format
from plex_activity.sources.s_logging.parsers.base import Parser, LOG_PATTERN, REQUEST_HEADER_PATTERN

import logging
import re

log = logging.getLogger(__name__)

PLAYING_HEADER_PATTERN = str_format(
    REQUEST_HEADER_PATTERN,
    method="GET",
    path="/:/(?P<type>timeline|progress)/?(?:\?(?P<query>.*?))?\s")
PLAYING_HEADER_REGEX = re.compile(PLAYING_HEADER_PATTERN, re.IGNORECASE)

RANGE_REGEX = re.compile(
    str_format(LOG_PATTERN, message=r'Request range: \d+ to \d+'),
    re.IGNORECASE)
CLIENT_REGEX = re.compile(
    str_format(LOG_PATTERN,
               message=r'Client \[(?P<machineIdentifier>.*?)\].*?'),
    re.IGNORECASE)

NOW_USER_REGEX = re.compile(
    str_format(
        LOG_PATTERN,
        message=r'\[Now\] User is (?P<user_name>.+) \(ID: (?P<user_id>\d+)\)'),
    re.IGNORECASE)
NOW_CLIENT_REGEX = re.compile(
    str_format(
        LOG_PATTERN,
        message=r'\[Now\] Device is (?P<product>.+?) \((?P<client>.+)\)\.'),
Beispiel #6
0
from plex.lib.six.moves import urllib_parse as urlparse
from plex_activity.core.helpers import str_format

from pyemitter import Emitter
import logging
import re

log = logging.getLogger(__name__)

LOG_PATTERN = r"^.*?\[\w+\]\s\w+\s-\s{message}$"
REQUEST_HEADER_PATTERN = str_format(
    LOG_PATTERN, message=r"Request: (\[(?P<address>.*?):(?P<port>\d+)\]\s)?{method} {path}.*?"
)

IGNORE_PATTERNS = [
    r"error parsing allowedNetworks.*?",
    r"Comparing request from.*?",
    r"(Auth: )?We found auth token (.*?), enabling token-based authentication\.",
    r"(Auth: )?Came in with a super-token, authorization succeeded\.",
    r"(Auth: )?Refreshing tokens inside the token-based authentication filter\.",
    r"\[Now\] Updated play state for .*?",
    r"Play progress on .*? - got played .*? ms by account .*?!",
    r"(Statistics: )?\(.*?\) Reporting active playback in state \d+ of type \d+ \(.*?\) for account \d+",
    r"Request: \[.*?\] (GET|PUT) /video/:/transcode/.*?",
    r"Received transcode session ping for session .*?",
]

IGNORE_REGEX = re.compile(
    str_format(LOG_PATTERN, message="(%s)" % ("|".join("(%s)" % x for x in IGNORE_PATTERNS))), re.IGNORECASE
)