Ejemplo n.º 1
0
    def __init__(self):
        self.archive = site_registry().archive
        self.log = site_registry().log
        self.session = site_registry().session
        self.queue_check_loop = LoopingCall(self.queue_check)
        self.recordings = Recordings()
        self.config = site_registry().config

        reactor.callLater(2, self.start_loop)
Ejemplo n.º 2
0
    def __init__(self):
        self.recordings = Recordings()
        self.transcode = Transcode()
        self.log = site_registry().log
        self.session = site_registry().session
        self.config = site_registry().config
        self.record_loop = LoopingCall(self.check_message)
        self.record_loop.start(self.record_loop_time, now=False)

        self.working_files = []
Ejemplo n.º 3
0
 def recorded_from_program(self, program, recursive=False):
     try:
         return Recorded((program.chanid, program.recstartts), self.db)
     except OperationalError, e:
         if recursive is False:
             if site_registry().mysql_gone_away(e):
                 return self.recorded_from_program(program, recursive=True)
         raise
Ejemplo n.º 4
0
    def _log(self, level, msg, recursive=False):

        try:
            self.log(self.default_log_mask, level, msg)
        except OperationalError, e:
            if recursive is False:
                if site_registry().mysql_gone_away(e):
                    self._log(level, msg, recursive=True)
                    return
            raise
Ejemplo n.º 5
0
    def __init__(self, file_, recorded, recorder, db, export_type=ExportType.mythvideo):
        self.file_ = file_
        self.db = db
        self.recorder = recorder
        self.config = site_registry().config

        if export_type == ExportType.mythvideo:
            self.vid = Video(db=self.db).create({'title': '', 'filename': '', 'host': self.config.export_hostname})
        elif export_type == ExportType.file_:
            self.vid = VideoStub()
        else:
            raise ArchiveError('Invalid Export Type: %r' % export_type)

        self.rec = recorded

        self.log = site_registry().log

        ###############
        ## Set Formats

        self.ext = 'm4v'
        self.type = 'TV'

        # TV Format
        self.tfmt = 'Television/%TITLE%/Season_%SEASON%/'+\
                        '%TITLE%-S%SEASON%E%EPISODEPAD%-%SUBTITLE%'
        # Movie Format
        self.mfmt = 'Movies/%TITLE%'
        # Generic Format
        self.gfmt = 'Videos/%TITLE%'

        self.get_metadata()
        self.get_destination()

        if export_type == ExportType.mythvideo:
            self.copy()
            self.vid.update()
        elif export_type == ExportType.file_:
            self.write_file()
Ejemplo n.º 6
0
def media_plugin():

    registry.init_registry(init_server=False)

    config = site_registry().config

    static_path = os.path.abspath('../web/static')
    if os.path.exists(static_path) is False:
        static_path = '/usr/share/mythtvarchiveservermedia/web/static'

    media_path = config.archive_directory
    port = config.media_server_port
    root = DefaultResource()
    root.putChild('media', File(media_path, defaultType='video/mpeg'))
    root.putChild('queue', QueueResource())
    root.putChild('recordings', RecordingsResource())
    root.putChild('static', File(static_path))
    reactor.listenTCP(port, Site(root))

    if config.enable_media_server is False:
        reactor.callLater(0.1, reactor.stop)

    reactor.run()
Ejemplo n.º 7
0
def twistd_plugin():
    registry.init_registry()
    config = registry.site_registry().config
    reactor.listenTCP(config.server_port, Site(ArchiveServer()))
    reactor.run()
Ejemplo n.º 8
0
 def queue(self):
     return registry.site_registry().queue
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     XMLRPC.__init__(self, *args, **kwargs)
     self.recording = Recordings()
     self.log = registry.site_registry().log
Ejemplo n.º 10
0
    def custom_render(self, request):

        _default_params = default_params(['page', 'storage', 'status'], request.args)

        quality = 'Universal'
        page = request.args.get('page', [0])[0]
        page, paginate_links = build_paginate_links(page, 'recordings',
                                                    default_params(['storage', 'status'], request.args))
        rows = 15

        storage = request.args.get('storage', [])
        status = request.args.get('status', [])

        server_url = 'http://localhost:%s' % site_registry().config.server_port
        archive_response = process_archive(server_url, request)
        delete_response = process_delete(request, self.recordings.get_recording)

        recording_list = self.recordings.get_recordings()

        session = site_registry().session

        prune = []

        if storage:
            for program in recording_list:
                if not program.storagegroup in storage:
                    prune.append(program)

        if status:
            for program in recording_list:
                queue_status = self.get_queue(session, program)
                if not queue_status in status:
                    prune.append(program)
                else:
                    program.queue_status = queue_status

        if prune:
            for program in prune:
                recording_list.remove(program)

        chunks = []
        start = rows * page
        for i in range(start, start+rows+1):
            try:
                program = recording_list[i]
            except IndexError:
                break

            chunks.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
                          % (program.title, program.subtitle if program.subtitle else '',
                             program.season, program.episode, program.inetref, program.category, program.storagegroup,
                             program.description[0:80] if program.description else ''))
            archive_link = build_archive_link(program.chanid, str(program.recstartts.utcisoformat()),
                                              quality, 'recordings', _default_params)
            delete_link = build_delete_link(program.chanid, str(program.recstartts.utcisoformat()), 'recordings',
                                            _default_params)

            if status:
                queue_status = program.queue_status
            else:
                queue_status = self.get_queue(session, program)

            chunks.append('<td>%s</td><td>%s</td><td>%s</td><tr>\n' % (queue_status, archive_link, delete_link))

        storage_values = {
            'LiveTV': 'LiveTV',
            'Default': 'Default',
        }
        storage_checkbox = build_checkbox('storage', storage_values, storage)

        status_values = {
            'n/a': 'n/a',
            'Ready': 'ready',
            'running': 'running',
            'Queued': 'queued',
            'finished': 'finished',
            'error': 'error',
        }
        status_checkbox = build_checkbox( 'status', status_values, status)

        content = '''
        %s%s
        <table>
        <tr>
        <td>
        %s
        <a href="recordings">Refresh</a>
        </td>
        <td>
        <form action="recordings">
        <table>
        <tr>
        <td><b>Storage:</b></td><td>%s</td>
        <td><b>Status:</b></td><td>%s</td>
        <td><input type="submit" value="Submit"></td>
        </tr>
        </table>
        <input type="hidden" name="page" value="%d">
        </form>
        </td>
        </tr>
        </table>
        <table class="gridtable">
        <tr>
        <th>Title</th><th>SubTitle</th><th>Sea.</th><th>Ep.</th><th>Ref</th><th>Category</th><th>Storage</th>
        <th>Description</th><th>Status</th><th></th><th></th>
        </tr>
        %s
        </table>
        ''' % (archive_response, delete_response, paginate_links, storage_checkbox, status_checkbox, page,
               ''.join(chunks))

        return default_template(content)
Ejemplo n.º 11
0
 def _session(*args, **kwargs):
     site_registry().init_session()
     ret_val = meth(*args, **kwargs)
     site_registry().close_session()
     return ret_val
Ejemplo n.º 12
0
 def __init__(self):
     self.log = site_registry().log
     self.config = site_registry().config
     self.be = site_registry().mythbe
     self.db = site_registry().mythdb
Ejemplo n.º 13
0
 def __init__(self):
     self.log = site_registry().log
     self.config = site_registry().config
Ejemplo n.º 14
0
        except Exception, e:
            raise ArchiveError('Error cutting commercials: %r' % e)

        tmp_handbrake_file_name = '%s.m4v' % program.filename.split('.')[0]
        tmp_handbrake_file_path = '%s/%s' % (self.config.working_directory, tmp_handbrake_file_name)

        self.working_files.append(tmp_handbrake_file_path)
        try:
            yield self.transcode.handbrake_transcode(mpg_file, tmp_handbrake_file_path,
                                                    queue.quality, self.recorder)
            self.log.info('Handbrake finished')
        except Exception, e:
            raise ArchiveError('Error handbrake transcode: %r' % e)

        try:
            yield deferToThread(self.create_video, tmp_handbrake_file_path, rec, site_registry().mythdb)
        except Exception, e:
            logging.exception(e)
            raise ArchiveError('Create Video Error: %r' % e)

        try:
            self.cleanup()
        except Exception, e:
            raise ArchiveError('Error cleaning up file: %r' % e)

        try:
            if self.config.delete_recording_on_finish:
                program.delete()
        except Exception, e:
            raise ArchiveError('Attempt to Delete Recording: %r' % e)
Ejemplo n.º 15
0
    def custom_render(self, request):

        _default_params = default_params(['page'], request.args)

        page = request.args.get('page', [0])[0]
        page, paginate_links = build_paginate_links(page, 'queue')
        rows = 15

        session = site_registry().session
        session.expire_all()

        server_url = 'http://localhost:%s' % site_registry().config.server_port
        retry_response = process_archive(server_url, request)
        delete_response = process_delete(request, self.recordings.get_recording)

        queues = session.query(Queue)\
                    .order_by(Queue.created.desc())\
                    .offset(page*rows)\
                    .limit(rows).all()
        chunks = []
        for queue in queues:
            chunks.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
                          % (queue.info, queue.created, queue.quality, queue.message))
            starttime = endtime = runtime = status_msg = None
            row_css = retry_link = delete_link = ''
            for status in queue.status:
                if status.status == 'running':
                    starttime = status.created
                elif status.status == 'finished':
                    endtime = status.created
                elif status.status == 'error':
                    # Job Errored
                    status_msg = 'Error: %s' % status.message
                    row_css = ' style="background-color: #FFB2B2"'
                    retry_link = build_archive_link(queue.chan_id, queue.start_time, queue.quality, 'queue',
                                                    _default_params)

                if starttime and endtime:
                    # Job Finished Successfully
                    runtime = endtime - starttime
                    status_msg = 'Job Time: %s' % runtime
                    row_css = ' style="background-color: #D4FFA9"'
                    retry_link = build_archive_link(queue.chan_id, queue.start_time, queue.quality, 'queue',
                                                    _default_params)
                    delete_link = build_delete_link(queue.chan_id, queue.start_time, 'recordings', _default_params)

            if status_msg is None and starttime is None:
                # Hasn't Started Yet
                status_msg = 'Queued'
                row_css = ' style="background-color: #FFFF85"'
            elif status_msg is None:
                # Job is Running
                runtime = datetime.now() - starttime
                status_msg = 'Job Running for: %s' % runtime
                row_css = ' style="background-color: #E7F0FF"'

            chunks.append('<td%s>%s</td><td>%s</td><td>%s</td><tr>\n' % (row_css, status_msg, retry_link, delete_link))

        content = '''
        %s
        <table>
        <tr>
        <td>
        %s%s
        <a href="queue">Refresh</a>
        </td>
        </tr>
        </table>
        <table class="gridtable">
        <tr>
        <th>Title</th><th>Created</th><th>Quality</th><th>Message</th><th>Status</th><th></th><th></th>
        </tr>
        %s
        </tr>
        </table>
        ''' % (retry_response, delete_response, paginate_links, ''.join(chunks))

        return default_template(content)