def get(self, devicekey, *args):
        """In some cases, channel scanning is a two-step process, where the first stage consists of scanning for networks (this is called "fast scan")."""

        out = xml.etree.ElementTree.Element('MediaContainer')
        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin_name = devicekey.split(
                self.fhdhr.config.dict["main"]["uuid"])[-1]
            out.set('size', "1")

            sub_el(
                out,
                'Network',
                key="%s%s" %
                (self.fhdhr.config.dict["main"]["uuid"], origin_name),
                title="%s %s" %
                (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin_name),
            )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
    def get(self, devicekey, *args):
        """Returns the current channels."""

        out = xml.etree.ElementTree.Element('MediaContainer')
        if devicekey == self.fhdhr.config.dict["main"]["uuid"]:
            out.set('size', str(len(self.fhdhr.device.channels.list)))
            for fhdhr_id in [x["id"] for x in self.fhdhr.device.channels.get_channels()]:
                channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
                if channel_obj.enabled:
                    sub_el(out, 'Channel',
                           drm="0",
                           channelIdentifier="id://%s" % channel_obj.number,
                           name=channel_obj.dict["name"],
                           origin=channel_obj.dict["callsign"],
                           number=str(channel_obj.number),
                           type="tv",
                           # TODO param
                           signalStrength="100",
                           signalQuality="100",
                           )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #3
0
    def get(self, *args):
        """This endpoint requests the grabber attempt to discover any devices it can, and it returns zero or more devices."""

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('MediaContainer')
        out.set('size', "1")
        sub_el(out,
               'Device',
               key=self.fhdhr.config.dict["main"]["uuid"],
               make=self.fhdhr.config.dict["fhdhr"]["reporting_manufacturer"],
               model=self.fhdhr.config.dict["fhdhr"]["reporting_model"],
               modelNumber=self.fhdhr.config.internal["versions"]["fHDHR"],
               protocol="livetv",
               status="alive",
               title=self.fhdhr.config.dict["fhdhr"]["friendlyname"],
               tuners=str(self.fhdhr.config.dict["fhdhr"]["tuner_count"]),
               uri=base_url,
               uuid="device://tv.plex.grabbers.fHDHR/%s" %
               self.fhdhr.config.dict["main"]["uuid"],
               thumb="favicon.ico",
               interface='network'
               # TODO add preferences
               )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
    def get(self, *args):
        """Probes a specific URI for a network device, and returns a device, if it exists at the given URI."""

        base_url = request.url_root[:-1]

        uri = request.args.get('uri', default=None, type=str)

        out = xml.etree.ElementTree.Element('MediaContainer')
        out.set('size', "1")
        if uri == base_url:
            sub_el(out, 'Device',
                   key=self.fhdhr.config.dict["main"]["uuid"],
                   make=self.fhdhr.config.dict["fhdhr"]["reporting_manufacturer"],
                   model=self.fhdhr.config.dict["fhdhr"]["reporting_model"],
                   modelNumber=self.fhdhr.config.internal["versions"]["fHDHR"],
                   protocol="livetv",
                   status="alive",
                   title=self.fhdhr.config.dict["fhdhr"]["friendlyname"],
                   tuners=str(self.fhdhr.config.dict["fhdhr"]["tuner_count"]),
                   uri=base_url,
                   uuid="device://tv.plex.grabbers.fHDHR/%s" % self.fhdhr.config.dict["main"]["uuid"],
                   thumb="favicon.ico",
                   interface='network'
                   )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
    def get(self, devicekey, *args):
        """Device.xml referenced from SSDP"""
        """Provides general information about the media grabber"""

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('MediaContainer')
        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin_name = devicekey.split(self.fhdhr.config.dict["main"]["uuid"])[-1]

            sub_el(out, 'MediaGrabber',
                   identifier="tv.plex.grabbers.fHDHR.%s" % origin_name,
                   title="%s %s" % (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin_name),
                   protocols="livetv",
                   icon="%s/favicon.ico" % base_url
                   )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #6
0
    def get(self, devicekey, *args):
        """ascertain which type of scanners are supported."""

        method = request.args.get('type', default="0", type=str)
        # 0 (atsc), 1 (cqam), 2 (dvb-s), 3 (iptv), 4 (virtual), 5 (dvb-t), 6 (dvb-c), 7 (isdbt)

        out = xml.etree.ElementTree.Element('MediaContainer')
        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin_name = devicekey.split(
                self.fhdhr.config.dict["main"]["uuid"])[-1]

            if method == "0":
                out.set('size', "1")
                out.set('simultaneousScanners', "1")

                scanner_out = sub_el(
                    out,
                    'Scanner',
                    type="atsc",
                    # TODO country
                )
                sub_el(scanner_out,
                       'Setting',
                       id="provider",
                       type="text",
                       enumValues=origin_name)

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #7
0
    def get(self, origin, *args):

        base_url = request.url_root[:-1]

        show = request.args.get('show', default="all", type=str)

        chan_guide = []
        if origin in self.fhdhr.origins.valid_origins:
            chan_guide = self.interface.get_channel_lineup(
                origin, base_url, show)

        out = xml.etree.ElementTree.Element('Lineup')
        for lineup_dict in chan_guide:
            program_out = sub_el(out, 'Program')
            for key in list(lineup_dict.keys()):
                sub_el(program_out, str(key), str(lineup_dict[key]))

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        lineup_xml = fakefile.getvalue()

        return Response(status=200,
                        response=lineup_xml,
                        mimetype='application/xml')
    def handler(self, *args):
        """Probes a specific URI for a network device, and returns a device, if it exists at the given URI."""

        base_url = request.url_root[:-1]

        uri = request.args.get('uri', default=None, type=str)

        out = xml.etree.ElementTree.Element('MediaContainer')
        out.set('size', str(len(self.fhdhr.origins.list_origins)))

        for origin_name in self.fhdhr.origins.list_origins:

            if uri == "%s/rmg/%s%s" % (base_url,
                                       self.fhdhr.config.dict["main"]["uuid"],
                                       origin_name):

                if self.fhdhr.origins.get_origin_property(
                        origin_name, "setup_success"):
                    alive_status = "alive"
                else:
                    alive_status = "dead"

                sub_el(out,
                       'Device',
                       key="%s%s" %
                       (self.fhdhr.config.dict["main"]["uuid"], origin_name),
                       make=self.fhdhr.config.dict["rmg"]
                       ["reporting_manufacturer"],
                       model=self.fhdhr.config.dict["rmg"]["reporting_model"],
                       modelNumber=self.fhdhr.config.internal["versions"]
                       ["fHDHR"],
                       protocol="livetv",
                       status=alive_status,
                       title="%s %s" %
                       (self.fhdhr.config.dict["fhdhr"]["friendlyname"],
                        origin_name),
                       tuners=str(
                           self.fhdhr.origins.get_origin_property(
                               origin_name, "tuners")),
                       uri="%s/rmg/%s%s" %
                       (base_url, self.fhdhr.config.dict["main"]["uuid"],
                        origin_name),
                       uuid="device://tv.plex.grabbers.fHDHR/%s%s" %
                       (self.fhdhr.config.dict["main"]["uuid"], origin_name),
                       thumb="favicon.ico",
                       interface='network')

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #9
0
    def get(self, *args):

        base_url = request.url_root[:-1]

        show = request.args.get('show', default="all", type=str)

        origin = self.source

        channelslist = {}
        sorted_chan_guide = []
        for fhdhr_id in [
                x["id"]
                for x in self.fhdhr.device.channels.get_channels(origin)
        ]:
            channel_obj = self.fhdhr.device.channels.get_channel_obj(
                "id", fhdhr_id, origin)
            if channel_obj.enabled:
                channelslist[channel_obj.number] = channel_obj

        # Sort the channels
        sorted_channel_list = channel_sort(list(channelslist.keys()))
        for channel in sorted_channel_list:

            channel_obj = channelslist[channel]
            lineup_dict = {
                'GuideNumber': channel_obj.number,
                'GuideName': channel_obj.dict['name'],
                'Tags': ",".join(channel_obj.dict['tags']),
                'URL': '/hdhr/auto/v%s' % channel_obj.number,
                'HD': channel_obj.dict["HD"],
                "Favorite": channel_obj.dict["favorite"],
            }
            lineup_dict["URL"] = "%s%s" % (base_url, lineup_dict["URL"])
            if show == "found" and channel_obj.enabled:
                lineup_dict["Enabled"] = 1
            elif show == "found" and not channel_obj.enabled:
                lineup_dict["Enabled"] = 0

            sorted_chan_guide.append(lineup_dict)

        out = xml.etree.ElementTree.Element('Lineup')
        for lineup_dict in sorted_chan_guide:
            program_out = sub_el(out, 'Program')
            for key in list(lineup_dict.keys()):
                sub_el(program_out, str(key), str(lineup_dict[key]))

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        lineup_xml = fakefile.getvalue()

        return Response(status=200,
                        response=lineup_xml,
                        mimetype='application/xml')
Example #10
0
    def get(self, devicekey, *args):
        """Returns the current channels."""

        out = xml.etree.ElementTree.Element('MediaContainer')

        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin_name = devicekey.split(
                self.fhdhr.config.dict["main"]["uuid"])[-1]
            out.set(
                'size',
                str(self.fhdhr.origins.origins_dict[origin_name].channels.
                    count_channels))

            channelslist = {}
            for fhdhr_channel_id in self.fhdhr.origins.origins_dict[
                    origin_name].channels.list_channel_ids:
                channel_obj = self.fhdhr.origins.origins_dict[
                    origin_name].channels.get_channel_obj(
                        "id", fhdhr_channel_id)
                if channel_obj:
                    if channel_obj.enabled:
                        channelslist[channel_obj.number] = channel_obj

            # Sort the channels
            sorted_channel_list = channel_sort(list(channelslist.keys()))
            for channel in sorted_channel_list:

                channel_obj = channelslist[channel]

                sub_el(
                    out,
                    'Channel',
                    drm="0",
                    channelIdentifier="id://%s" % channel_obj.number,
                    name=channel_obj.dict["name"],
                    origin_name=channel_obj.dict["callsign"],
                    number=str(channel_obj.number),
                    type="tv",
                    # TODO param
                    signalStrength="100",
                    signalQuality="100",
                )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #11
0
    def get(self, *args):

        base_url = request.url_root[:-1]

        show = request.args.get('show', default="all", type=str)

        channelslist = {}
        for fhdhr_id in [
                x["id"] for x in self.fhdhr.device.channels.get_channels()
        ]:
            channel_obj = self.fhdhr.device.channels.list[fhdhr_id]
            if channel_obj.enabled or show == "found":
                lineup_dict = channel_obj.lineup_dict
                lineup_dict["URL"] = "%s%s" % (base_url, lineup_dict["URL"])
                if show == "found" and channel_obj.enabled:
                    lineup_dict["Enabled"] = 1
                elif show == "found" and not channel_obj.enabled:
                    lineup_dict["Enabled"] = 0

                channelslist[channel_obj.number] = lineup_dict

        # Sort the channels
        sorted_channel_list = channel_sort(list(channelslist.keys()))
        sorted_chan_guide = []
        for channel in sorted_channel_list:
            sorted_chan_guide.append(channelslist[channel])

        out = xml.etree.ElementTree.Element('Lineup')
        for lineup_dict in sorted_chan_guide:
            program_out = sub_el(out, 'Program')
            for key in list(lineup_dict.keys()):
                sub_el(program_out, str(key), str(lineup_dict[key]))

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        lineup_xml = fakefile.getvalue()

        return Response(status=200,
                        response=lineup_xml,
                        mimetype='application/xml')
    def get(self, *args):
        """Provides general information about the media grabber"""

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('MediaContainer')
        sub_el(out,
               'MediaGrabber',
               identifier="tv.plex.grabbers.fHDHR",
               title=str(self.fhdhr.config.dict["fhdhr"]["friendlyname"]),
               protocols="livetv",
               icon="%s/favicon.ico" % base_url)

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #13
0
    def get(self, *args):

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('Lineup')
        station_list = self.fhdhr.device.channels.get_station_list(base_url)
        for station_item in station_list:
            program_out = sub_el(out, 'Program')
            sub_el(program_out, 'GuideNumber', station_item['GuideNumber'])
            sub_el(program_out, 'GuideName', station_item['GuideName'])
            sub_el(program_out, 'Tags', ",".join(station_item['Tags']))
            sub_el(program_out, 'URL', station_item['URL'])

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        lineup_xml = fakefile.getvalue()

        return Response(status=200,
                        response=lineup_xml,
                        mimetype='application/xml')
Example #14
0
    def get_lineup_xml(self, base_url, force_update=False):
        if not self.device_xml or force_update:
            out = xml.etree.ElementTree.Element('Lineup')
            station_list = self.device.channels.get_station_list(base_url)
            for station_item in station_list:
                program_out = sub_el(out, 'Program')
                sub_el(program_out, 'GuideNumber', station_item['GuideNumber'])
                sub_el(program_out, 'GuideName', station_item['GuideName'])
                sub_el(program_out, 'URL', station_item['URL'])

            fakefile = BytesIO()
            fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
            fakefile.write(
                xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
            self.device_xml = fakefile.getvalue()

        return self.device_xml
Example #15
0
    def get(self, devicekey, *args):
        """Returns the identity, capabilities, and current status of the devices and each of its tuners."""

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('MediaContainer')

        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin = devicekey.split(self.fhdhr.config.dict["main"]["uuid"])[-1]
            out.set('size', "1")

            if self.fhdhr.origins.origins_dict[origin].setup_success:
                alive_status = "alive"
            else:
                alive_status = "dead"

            device_out = sub_el(out, 'Device',
                                key="%s%s" % (self.fhdhr.config.dict["main"]["uuid"], origin),
                                make=self.fhdhr.config.dict["rmg"]["reporting_manufacturer"],
                                model=self.fhdhr.config.dict["rmg"]["reporting_model"],
                                modelNumber=self.fhdhr.config.internal["versions"]["fHDHR"],
                                protocol="livetv",
                                status=alive_status,
                                title="%s %s" % (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin),
                                tuners=str(self.fhdhr.origins.origins_dict[origin].tuners),
                                uri="%s/rmg/%s%s" % (base_url, self.fhdhr.config.dict["main"]["uuid"], origin),
                                uuid="device://tv.plex.grabbers.fHDHR/%s%s" % (self.fhdhr.config.dict["main"]["uuid"], origin),
                                )

            tuner_status = self.fhdhr.device.tuners.status(origin)

            for tuner_number in list(tuner_status.keys()):
                tuner_dict = tuner_status[tuner_number]

                # Idle
                if tuner_dict["status"] in ["Inactive"]:
                    sub_el(device_out, 'Tuner',
                           index=tuner_number,
                           status="idle",
                           )

                # Streaming
                elif tuner_dict["status"] in ["Active", "Acquired"]:
                    sub_el(device_out, 'Tuner',
                           index=tuner_number,
                           status="streaming",
                           channelIdentifier="id://%s" % tuner_dict["channel"],
                           signalStrength="100",
                           signalQuality="100",
                           symbolQuality="100",
                           lock="1",
                           )

                # Scanning
                elif tuner_dict["status"] in ["Scanning"]:
                    sub_el(device_out, 'Tuner',
                           index=tuner_number,
                           status="scanning",
                           progress="99",
                           channelsFound=str(len(list(self.fhdhr.device.channels.list[origin].keys()))),
                           )

                # TODO networksScanned
                elif tuner_dict["status"] in ["networksScanned"]:
                    sub_el(device_out, 'Tuner',
                           index=tuner_number,
                           status="networksScanned",
                           )

                # Error
                elif tuner_dict["status"] in ["Error"]:
                    sub_el(device_out, 'Tuner',
                           index=tuner_number,
                           status="error",
                           )

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #16
0
    def create_xmltv(self, base_url, epgdict):
        if not epgdict:
            return self.xmltv_empty()

        out = self.xmltv_headers()

        for c in list(epgdict.keys()):

            c_out = sub_el(out, 'channel', id=str(epgdict[c]['number']))
            sub_el(c_out,
                   'display-name',
                   text='%s %s' %
                   (epgdict[c]['number'], epgdict[c]['callsign']))
            sub_el(c_out,
                   'display-name',
                   text='%s %s %s' %
                   (epgdict[c]['number'], epgdict[c]['callsign'],
                    str(epgdict[c]['id'])))
            sub_el(c_out, 'display-name', text=epgdict[c]['number'])
            sub_el(c_out,
                   'display-name',
                   text='%s %s fcc' %
                   (epgdict[c]['number'], epgdict[c]['callsign']))
            sub_el(c_out, 'display-name', text=epgdict[c]['callsign'])
            sub_el(c_out, 'display-name', text=epgdict[c]['callsign'])
            sub_el(c_out, 'display-name', text=epgdict[c]['name'])

            if epgdict[c]["thumbnail"] is not None:
                sub_el(c_out,
                       'icon',
                       src=("http://" + str(base_url) +
                            "/images?source=epg&type=channel&id=" +
                            str(epgdict[c]['id'])))
            else:
                sub_el(c_out,
                       'icon',
                       src=("http://" + str(base_url) +
                            "/images?source=generate&message=" +
                            str(epgdict[c]['number'])))

        for channelnum in list(epgdict.keys()):

            channel_listing = epgdict[channelnum]['listing']

            for program in channel_listing:

                prog_out = sub_el(out,
                                  'programme',
                                  start=program['time_start'],
                                  stop=program['time_end'],
                                  channel=str(channelnum))

                sub_el(prog_out, 'title', lang='en', text=program['title'])

                sub_el(prog_out,
                       'desc',
                       lang='en',
                       text=program['description'])

                sub_el(prog_out,
                       'sub-title',
                       lang='en',
                       text='Movie: ' + program['sub-title'])

                sub_el(prog_out,
                       'length',
                       units='minutes',
                       text=str(int(program['duration_minutes'])))

                for f in program['genres']:
                    sub_el(prog_out, 'category', lang='en', text=f)
                    sub_el(prog_out, 'genre', lang='en', text=f)

                if program['seasonnumber'] and program['episodenumber']:
                    s_ = int(str(program['seasonnumber']), 10)
                    e_ = int(str(program['episodenumber']), 10)
                    sub_el(prog_out,
                           'episode-num',
                           system='dd_progid',
                           text=str(program['id']))
                    sub_el(prog_out,
                           'episode-num',
                           system='common',
                           text='S%02dE%02d' % (s_, e_))
                    sub_el(prog_out,
                           'episode-num',
                           system='xmltv_ns',
                           text='%d.%d.' % (int(s_) - 1, int(e_) - 1))
                    sub_el(prog_out,
                           'episode-num',
                           system='SxxExx">S',
                           text='S%02dE%02d' % (s_, e_))

                if program["thumbnail"]:
                    sub_el(prog_out,
                           'icon',
                           src=("http://" + str(base_url) +
                                "/images?source=epg&type=content&id=" +
                                str(program['id'])))
                else:
                    sub_el(prog_out,
                           'icon',
                           src=("http://" + str(base_url) +
                                "/images?source=generate&message=" +
                                program['title'].replace(" ", "")))

                if program['rating']:
                    rating_out = sub_el(prog_out, 'rating', system="MPAA")
                    sub_el(rating_out, 'value', text=program['rating'])

                if program['isnew']:
                    sub_el(prog_out, 'new')

        return self.xmltv_file(out)
    def get(self, *args):
        """Device.xml referenced from SSDP"""

        base_url = request.url_root[:-1]

        origin = self.source
        origin_plugin_name = self.fhdhr.origins.origins_dict[
            origin].plugin_utils.plugin_name
        origin_plugin_version = self.fhdhr.origins.origins_dict[
            origin].plugin_utils.plugin_manifest["version"]

        out = xml.etree.ElementTree.Element('root')
        out.set('xmlns', "urn:schemas-upnp-org:device-1-0")

        sub_el(out, 'URLBase', "%s/hdhr" % base_url)

        specVersion_out = sub_el(out, 'specVersion')
        sub_el(specVersion_out, 'major', "1")
        sub_el(specVersion_out, 'minor', "0")

        device_out = sub_el(out, 'device')

        sub_el(device_out, 'deviceType',
               "urn:schemas-upnp-org:device:MediaServer:1")

        sub_el(
            device_out, 'friendlyName', "%s %s" %
            (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin))
        sub_el(device_out, 'manufacturer',
               self.fhdhr.config.dict["hdhr"]["reporting_manufacturer"])
        sub_el(device_out, 'manufacturerURL',
               "https://github.com/fHDHR/%s" % origin_plugin_name)
        sub_el(device_out, 'modelName',
               self.fhdhr.config.dict["hdhr"]["reporting_model"])
        sub_el(device_out, 'modelNumber', origin_plugin_version)

        sub_el(device_out, 'serialNumber')

        sub_el(device_out, 'UDN',
               "uuid:%s%s" % (self.fhdhr.config.dict["main"]["uuid"], origin))

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
    def get(self, devicekey, *args):
        """Device.xml referenced from SSDP"""

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('root')
        out.set('xmlns', "urn:schemas-upnp-org:device-1-0")

        if devicekey.startswith(self.fhdhr.config.dict["main"]["uuid"]):
            origin_name = devicekey.split(
                self.fhdhr.config.dict["main"]["uuid"])[-1]

            origin_obj = self.fhdhr.origins.get_origin_obj(origin_name)

            origin_plugin_name = origin_obj.plugin_utils.plugin_name
            origin_plugin_version = origin_obj.plugin_utils.plugin_manifest[
                "version"]

            specVersion_out = sub_el(out, 'specVersion')
            sub_el(specVersion_out, 'major', "1")
            sub_el(specVersion_out, 'minor', "0")

            device_out = sub_el(out, 'device')

            sub_el(device_out, 'deviceType', "urn:plex-tv:device:Media:1")

            sub_el(
                device_out, 'friendlyName', "%s %s" %
                (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin_name))
            sub_el(device_out, 'manufacturer',
                   self.fhdhr.config.dict["rmg"]["reporting_manufacturer"])
            sub_el(device_out, 'manufacturerURL',
                   "https://github.com/fHDHR/%s" % origin_plugin_name)
            sub_el(device_out, 'modelName',
                   self.fhdhr.config.dict["rmg"]["reporting_model"])
            sub_el(device_out, 'modelNumber', origin_plugin_version)

            sub_el(
                device_out, 'modelDescription', "%s %s" %
                (self.fhdhr.config.dict["fhdhr"]["friendlyname"], origin_name))
            sub_el(
                device_out, 'modelURL', "https://github.com/fHDHR/%s" %
                self.fhdhr.config.dict["main"]["reponame"])

            serviceList_out = sub_el(device_out, 'serviceList')
            service_out = sub_el(serviceList_out, 'service')
            sub_el(
                out, 'URLBase', "%s/rmg/%s%s" %
                (base_url, self.fhdhr.config.dict["main"]["uuid"],
                 origin_name))
            sub_el(service_out, 'serviceType',
                   "urn:plex-tv:service:MediaGrabber:1")
            sub_el(service_out, 'serviceId',
                   "urn:plex-tv:serviceId:MediaGrabber")

            sub_el(
                device_out, 'UDN', "uuid:%s%s" %
                (self.fhdhr.config.dict["main"]["uuid"], origin_name))

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')
Example #19
0
    def get_device_xml(self, base_url, force_update=False):
        if not self.device_xml or force_update:
            out = xml.etree.ElementTree.Element('root')
            out.set('xmlns', "urn:schemas-upnp-org:device-1-0")

            sub_el(out, 'URLBase', "http://" + base_url)

            specVersion_out = sub_el(out, 'specVersion')
            sub_el(specVersion_out, 'major', "1")
            sub_el(specVersion_out, 'minor', "0")

            device_out = sub_el(out, 'device')
            sub_el(device_out, 'deviceType',
                   "urn:schemas-upnp-org:device:MediaServer:1")
            sub_el(device_out, 'friendlyName',
                   self.config.dict["fhdhr"]["friendlyname"])
            sub_el(device_out, 'manufacturer',
                   self.config.dict["dev"]["reporting_manufacturer"])
            sub_el(device_out, 'modelName',
                   self.config.dict["dev"]["reporting_model"])
            sub_el(device_out, 'modelNumber',
                   self.config.dict["dev"]["reporting_model"])
            sub_el(device_out, 'serialNumber')
            sub_el(device_out, 'UDN',
                   "uuid:" + self.config.dict["main"]["uuid"])

            fakefile = BytesIO()
            fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
            fakefile.write(
                xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
            self.device_xml = fakefile.getvalue()

        return self.device_xml
Example #20
0
    def create_xmltv(self, base_url, epgdict, source):
        if not epgdict:
            return self.xmltv_empty()
        epgdict = epgdict.copy()

        out = self.xmltv_headers()

        if source in self.fhdhr.origins.valid_origins:
            for c in list(epgdict.keys()):
                chan_obj = self.fhdhr.device.channels.get_channel_obj(
                    "origin_id", epgdict[c]["id"], source)
                epgdict[chan_obj.number] = epgdict.pop(c)
                epgdict[chan_obj.number]["name"] = chan_obj.dict["name"]
                epgdict[
                    chan_obj.number]["callsign"] = chan_obj.dict["callsign"]
                epgdict[chan_obj.number]["number"] = chan_obj.number
                epgdict[chan_obj.number]["id"] = chan_obj.dict["origin_id"]
                epgdict[chan_obj.number]["thumbnail"] = chan_obj.thumbnail

        for c in list(epgdict.keys()):

            c_out = sub_el(out, 'channel', id=str(epgdict[c]['number']))
            sub_el(c_out,
                   'display-name',
                   text='%s %s' %
                   (epgdict[c]['number'], epgdict[c]['callsign']))
            sub_el(c_out,
                   'display-name',
                   text='%s %s %s' %
                   (epgdict[c]['number'], epgdict[c]['callsign'],
                    str(epgdict[c]['id'])))
            sub_el(c_out, 'display-name', text=epgdict[c]['number'])
            sub_el(c_out, 'display-name', text=epgdict[c]['callsign'])
            sub_el(c_out, 'display-name', text=epgdict[c]['name'])

            if self.fhdhr.config.dict["epg"]["images"] == "proxy":
                sub_el(c_out,
                       'icon',
                       src=("%s/api/images?method=get&type=channel&id=%s" %
                            (base_url, epgdict[c]['id'])))
            else:
                sub_el(c_out, 'icon', src=(epgdict[c]["thumbnail"]))

        for channelnum in list(epgdict.keys()):

            channel_listing = epgdict[channelnum]['listing']

            for program in channel_listing:

                xmltvtimetamps = self.timestamp_to_datetime(
                    program['time_start'], program['time_end'], source)

                prog_out = sub_el(out,
                                  'programme',
                                  start=xmltvtimetamps['time_start'],
                                  stop=xmltvtimetamps['time_end'],
                                  channel=str(channelnum))

                sub_el(prog_out, 'title', lang='en', text=program['title'])

                sub_el(prog_out,
                       'desc',
                       lang='en',
                       text=program['description'])

                sub_el(prog_out,
                       'sub-title',
                       lang='en',
                       text='Movie: %s' % program['sub-title'])

                sub_el(prog_out,
                       'length',
                       units='minutes',
                       text=str(int(program['duration_minutes'])))

                for f in program['genres']:
                    sub_el(prog_out, 'category', lang='en', text=f)
                    sub_el(prog_out, 'genre', lang='en', text=f)

                if program['seasonnumber'] and program['episodenumber']:
                    s_ = int(str(program['seasonnumber']), 10)
                    e_ = int(str(program['episodenumber']), 10)
                    sub_el(prog_out,
                           'episode-num',
                           system='dd_progid',
                           text=str(program['id']))
                    sub_el(prog_out,
                           'episode-num',
                           system='common',
                           text='S%02dE%02d' % (s_, e_))
                    sub_el(prog_out,
                           'episode-num',
                           system='xmltv_ns',
                           text='%d.%d.' % (int(s_) - 1, int(e_) - 1))
                    sub_el(prog_out,
                           'episode-num',
                           system='SxxExx">S',
                           text='S%02dE%02d' % (s_, e_))

                if program["thumbnail"]:
                    if self.fhdhr.config.dict["epg"]["images"] == "proxy":
                        sub_el(
                            prog_out,
                            'icon',
                            src=(
                                "%s/api/images?method=get&type=content&id=%s" %
                                (base_url, program['id'])))
                    else:
                        sub_el(prog_out, 'icon', src=(program["thumbnail"]))
                else:
                    sub_el(
                        prog_out,
                        'icon',
                        src=
                        ("%s/api/images?method=generate&type=content&message=%s"
                         % (base_url, urllib.parse.quote(program['title']))))

                if program['rating']:
                    rating_out = sub_el(prog_out, 'rating', system="MPAA")
                    sub_el(rating_out, 'value', text=program['rating'])

                if program['isnew']:
                    sub_el(prog_out, 'new')

        return self.xmltv_file(out)
Example #21
0
    def get(self, *args):

        base_url = request.url_root[:-1]

        out = xml.etree.ElementTree.Element('root')
        out.set('xmlns', "urn:schemas-upnp-org:device-1-0")

        sub_el(out, 'URLBase', base_url)

        specVersion_out = sub_el(out, 'specVersion')
        sub_el(specVersion_out, 'major', "1")
        sub_el(specVersion_out, 'minor', "0")

        device_out = sub_el(out, 'device')
        sub_el(device_out, 'deviceType',
               "urn:schemas-upnp-org:device:MediaServer:1")
        sub_el(device_out, 'friendlyName',
               self.fhdhr.config.dict["fhdhr"]["friendlyname"])
        sub_el(device_out, 'manufacturer',
               self.fhdhr.config.dict["fhdhr"]["reporting_manufacturer"])
        sub_el(device_out, 'modelName',
               self.fhdhr.config.dict["fhdhr"]["reporting_model"])
        sub_el(device_out, 'modelNumber',
               self.fhdhr.config.dict["fhdhr"]["reporting_model"])
        sub_el(device_out, 'serialNumber')
        sub_el(device_out, 'UDN',
               "uuid:" + self.fhdhr.config.dict["main"]["uuid"])

        fakefile = BytesIO()
        fakefile.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
        fakefile.write(xml.etree.ElementTree.tostring(out, encoding='UTF-8'))
        device_xml = fakefile.getvalue()

        return Response(status=200,
                        response=device_xml,
                        mimetype='application/xml')