Пример #1
0
    def get(self, *args):

        if self.origin.setup_success:
            donation_expire = humanized_time(
                int((self.origin.status_dict["donateExp"] -
                     datetime.datetime.utcnow()).total_seconds()))
            origin_status_dict = {
                "Login":
                "******",
                "Username":
                self.origin.username,
                "DMA":
                self.origin.location["DMA"],
                "City":
                self.origin.location["city"],
                "Latitude":
                self.origin.location["latitude"],
                "Longitude":
                self.origin.location["longitude"],
                "Donation Expiration":
                donation_expire,
                "Total Channels":
                len(list(self.fhdhr.device.channels.list["locast"].keys()))
            }
        else:
            origin_status_dict = {"Setup": "Failed"}
        return render_template_string(self.template.getvalue(),
                                      request=request,
                                      session=session,
                                      fhdhr=self.fhdhr,
                                      origin_status_dict=origin_status_dict,
                                      list=list)
Пример #2
0
 def get_status(self):
     current_status = self.status.copy()
     if current_status["status"] == "Active":
         current_status["Play Time"] = str(
             humanized_time(
                 int((datetime.datetime.utcnow() - current_status["time_start"]).total_seconds())))
         current_status["time_start"] = str(current_status["time_start"])
         current_status["epg"] = self.epg.whats_on_now(current_status["channel"])
     return current_status
Пример #3
0
 def get_status(self):
     current_status = self.status.copy()
     current_status["epg"] = {}
     if current_status["status"] in ["Acquired", "Active", "Scanning"]:
         current_status["running_time"] = str(
             humanized_time(
                 int((datetime.datetime.utcnow() -
                      current_status["time_start"]).total_seconds())))
         current_status["time_start"] = str(current_status["time_start"])
     if current_status["status"] in ["Active"]:
         if current_status["origin"] in self.epg.epg_methods:
             current_status["epg"] = self.epg.whats_on_now(
                 current_status["channel"], method=current_status["origin"])
     return current_status
Пример #4
0
    def get(self, *args):

        nowtime = datetime.datetime.utcnow().timestamp()

        chan_guide_list = []

        source = request.args.get('source',
                                  default=self.fhdhr.device.epg.def_method,
                                  type=str)
        epg_methods = self.fhdhr.device.epg.valid_epg_methods
        if source not in epg_methods:
            source = self.fhdhr.device.epg.def_method

        whatson = self.fhdhr.device.epg.whats_on_allchans(source)

        # Sort the channels
        sorted_channel_list = channel_sort(list(whatson.keys()))
        sorted_chan_guide = {}
        for channel in sorted_channel_list:
            sorted_chan_guide[channel] = whatson[channel]

        for channel in list(sorted_chan_guide.keys()):
            if sorted_chan_guide[channel]["listing"][0]["time_end"]:
                remaining_time = humanized_time(
                    sorted_chan_guide[channel]["listing"][0]["time_end"] -
                    nowtime)
            else:
                remaining_time = "N/A"

            chan_dict = {
                "name":
                sorted_chan_guide[channel]["name"],
                "number":
                sorted_chan_guide[channel]["number"],
                "chan_thumbnail":
                sorted_chan_guide[channel]["thumbnail"],
                "listing_title":
                sorted_chan_guide[channel]["listing"][0]["title"],
                "listing_thumbnail":
                sorted_chan_guide[channel]["listing"][0]["thumbnail"],
                "listing_description":
                sorted_chan_guide[channel]["listing"][0]["description"],
                "listing_remaining_time":
                str(remaining_time)
            }

            for time_item in ["time_start", "time_end"]:

                if not sorted_chan_guide[channel]["listing"][0][time_item]:
                    chan_dict["listing_%s" % time_item] = "N/A"
                elif str(sorted_chan_guide[channel]["listing"][0]
                         [time_item]).endswith(tuple(["+0000", "+00:00"])):
                    chan_dict["listing_%s" % time_item] = str(
                        sorted_chan_guide[channel]["listing"][0][time_item])
                else:
                    chan_dict["listing_%s" % time_item] = str(
                        datetime.datetime.fromtimestamp(
                            sorted_chan_guide[channel]["listing"][0]
                            [time_item]))

            if source in [
                    "blocks", "origin",
                    self.fhdhr.config.dict["main"]["dictpopname"]
            ]:
                chan_obj = self.fhdhr.device.channels.get_channel_obj(
                    "origin_id", sorted_chan_guide[channel]["id"])

                chan_dict["name"] = chan_obj.dict["name"]
                chan_dict["number"] = chan_obj.number
                chan_dict["chan_thumbnail"] = chan_obj.thumbnail
                chan_dict["enabled"] = chan_obj.dict["enabled"]
                chan_dict["play_url"] = chan_obj.play_url

                chan_dict["listing_thumbnail"] = chan_dict[
                    "listing_thumbnail"] or chan_obj.thumbnail
            else:
                if not chan_dict["listing_thumbnail"]:
                    chan_dict["listing_thumbnail"] = chan_dict[
                        "chan_thumbnail"]
                if not chan_dict["listing_thumbnail"]:
                    chan_dict[
                        "listing_thumbnail"] = "/api/images?method=generate&type=channel&message=%s" % chan_dict[
                            "number"]

            chan_guide_list.append(chan_dict)

        return render_template('guide.html',
                               session=session,
                               request=request,
                               fhdhr=self.fhdhr,
                               chan_guide_list=chan_guide_list,
                               epg_methods=epg_methods,
                               source=source)
Пример #5
0
    def get_channels(self, origin=None, forceupdate=False):
        """Pull Channels from origin.

        Output a list.

        Don't pull more often than 12 hours.
        """

        if not origin:
            origins_list = list(self.list.keys())
        else:
            origins_list = origin.lower().lower()

        if isinstance(origins_list, str):
            origins_list = [origins_list]

        return_chan_list = []
        for origin in origins_list:

            if not len(list(self.list[origin].keys())):
                self.get_db_channels(origin=origin)

            if not forceupdate:
                return_chan_list.extend([
                    self.list[origin][x].dict
                    for x in list(self.list[origin].keys())
                ])

            else:

                channel_origin_id_list = [
                    str(self.list[origin][x].dict["origin_id"])
                    for x in list(self.list[origin].keys())
                ]

                self.fhdhr.logger.info("Performing Channel Scan for %s." %
                                       origin)

                channel_dict_list = self.origins.origins_dict[
                    origin].get_channels()
                self.fhdhr.logger.info("Found %s channels for %s." %
                                       (len(channel_dict_list), origin))

                self.fhdhr.logger.info(
                    "Performing Channel Import, This can take some time, Please wait."
                )

                newchan = 0
                chan_scan_start = time.time()
                for channel_info in channel_dict_list:

                    chan_existing = str(
                        channel_info["id"]) in channel_origin_id_list

                    if chan_existing:
                        channel_obj = self.get_channel_obj(
                            "origin_id", channel_info["id"], origin)
                    else:
                        channel_obj = Channel(self.fhdhr,
                                              self.id_system,
                                              origin,
                                              origin_id=channel_info["id"])

                    channel_id = channel_obj.dict["id"]
                    channel_obj.basics(channel_info)
                    if not chan_existing:
                        self.list[origin][channel_id] = channel_obj
                        newchan += 1

                self.fhdhr.logger.info(
                    "%s Channel Import took %s" %
                    (origin, humanized_time(time.time() - chan_scan_start)))

                if not newchan:
                    newchan = "no"
                self.fhdhr.logger.info("Found %s NEW channels for %s." %
                                       (newchan, origin))

                self.fhdhr.logger.info("Total %s Channel Count: %s" %
                                       (origin, len(self.list[origin].keys())))
                self.save_db_channels(origin=origin)

                self.fhdhr.db.set_fhdhr_value("channels", "scanned_time",
                                              time.time(), origin)
                return_chan_list.extend([
                    self.list[origin][x].dict
                    for x in list(self.list[origin].keys())
                ])

        return return_chan_list
    def get_channel_guide_html(self, force_update=False):

        friendlyname = self.config.dict["fhdhr"]["friendlyname"]

        nowtime = datetime.datetime.utcnow()

        fakefile = StringIO()
        page_elements = self.page_elements.get()

        for line in page_elements["top"]:
            fakefile.write(line + "\n")

        fakefile.write(
            "<h4 id=\"mcetoc_1cdobsl3g0\" style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong><em>What's On %s</em></strong></span></h4>\n"
            % friendlyname)
        fakefile.write("\n")

        fakefile.write("<table style=\"width:100%\">\n")
        fakefile.write("  <tr>\n")
        fakefile.write("    <th>Play</th>\n")
        fakefile.write("    <th>Channel Name</th>\n")
        fakefile.write("    <th>Channel Number</th>\n")
        fakefile.write("    <th>Channel Thumbnail</th>\n")
        fakefile.write("    <th>Content Title</th>\n")
        fakefile.write("    <th>Content Thumbnail</th>\n")
        fakefile.write("    <th>Content Description</th>\n")
        fakefile.write("    <th>Content Remaining Time</th>\n")
        fakefile.write("  </tr>\n")

        for channel in self.device.epg.whats_on_allchans():
            end_time = datetime.datetime.strptime(
                channel["listing"][0]["time_end"], '%Y%m%d%H%M%S +0000')
            remaining_time = humanized_time(
                int((end_time - nowtime).total_seconds()))
            play_url = ("/%s.m3u\n" % (channel["number"]))

            fakefile.write("  <tr>\n")
            fakefile.write("    <td><a href=\"%s\">%s</a>\n" %
                           (play_url, "Play"))
            fakefile.write("    <td>%s</td>\n" % (channel["name"]))
            fakefile.write("    <td>%s</td>\n" % (channel["number"]))
            fakefile.write(
                "    <td><img src=\"%s\" alt=\"%s\" width=\"100\" height=\"100\">\n"
                % (channel["thumbnail"], channel["name"]))
            fakefile.write("    <td>%s</td>\n" %
                           (channel["listing"][0]["title"]))
            fakefile.write(
                "    <td><img src=\"%s\" alt=\"%s\" width=\"100\" height=\"100\">\n"
                % (channel["listing"][0]["thumbnail"],
                   channel["listing"][0]["title"]))
            fakefile.write("    <td>%s</td>\n" %
                           (channel["listing"][0]["description"]))
            fakefile.write("    <td>%s</td>\n" % (str(remaining_time)))
            fakefile.write("  </tr>\n")

        for line in page_elements["end"]:
            fakefile.write(line + "\n")

        channel_guide_html = fakefile.getvalue()

        return channel_guide_html
Пример #7
0
    def get_channels(self, forceupdate=False):
        """Pull Channels from origin.

        Output a list.

        Don't pull more often than 12 hours.
        """

        if not len(list(self.list.keys())):
            self.get_db_channels()

        if not forceupdate:
            return [self.list[x].dict for x in list(self.list.keys())]

        channel_origin_id_list = [
            str(self.list[x].dict["origin_id"]) for x in list(self.list.keys())
        ]

        self.fhdhr.logger.info("Performing Channel Scan.")

        channel_dict_list = self.origin.get_channels()
        self.fhdhr.logger.info("Found %s channels for %s." %
                               (len(channel_dict_list),
                                self.fhdhr.config.dict["main"]["servicename"]))

        self.fhdhr.logger.info(
            "Performing Channel Import, This can take some time, Please wait.")

        newchan = 0
        chan_scan_start = time.time()
        for channel_info in channel_dict_list:

            chan_existing = str(channel_info["id"]) in channel_origin_id_list

            if chan_existing:
                channel_obj = self.get_channel_obj("origin_id",
                                                   channel_info["id"])
            else:
                channel_obj = Channel(self.fhdhr,
                                      self.id_system,
                                      origin_id=channel_info["id"])

            channel_id = channel_obj.dict["id"]
            channel_obj.basics(channel_info)
            if not chan_existing:
                self.list[channel_id] = channel_obj
                newchan += 1

        self.fhdhr.logger.info("Channel Import took %s" %
                               humanized_time(time.time() - chan_scan_start))

        if not newchan:
            newchan = "no"
        self.fhdhr.logger.info("Found %s NEW channels." % newchan)

        self.fhdhr.logger.info("Total Channel Count: %s" %
                               len(self.list.keys()))
        self.save_db_channels()

        self.fhdhr.db.set_fhdhr_value("channels", "scanned_time", time.time())

        return [self.list[x].dict for x in list(self.list.keys())]
Пример #8
0
    def get(self, *args):

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

        source = request.args.get(
            'source',
            default=self.fhdhr.config.dict["epg"]["def_method"],
            type=str)
        if source not in list(
                self.fhdhr.config.dict["epg"]["valid_methods"].keys()):
            return "%s Invalid epg method" % source

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

        if method == "get":

            epgdict = self.fhdhr.device.epg.get_epg(source)
            if source in self.fhdhr.origins.valid_origins:
                epgdict = epgdict.copy()
                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

            # Sort the channels
            sorted_channel_list = channel_sort(list(epgdict.keys()))
            sorted_chan_guide = {}
            for channel in sorted_channel_list:
                sorted_chan_guide[channel] = epgdict[channel]

            epg_json = json.dumps(sorted_chan_guide, indent=4)

            return Response(status=200,
                            response=epg_json,
                            mimetype='application/json')

        elif method == "current":

            nowtime = datetime.datetime.utcnow().timestamp()

            chan_guide_list = []

            whatson = self.fhdhr.device.epg.whats_on_allchans(source)

            # Sort the channels
            sorted_channel_list = channel_sort(list(whatson.keys()))
            sorted_chan_guide = {}
            for channel in sorted_channel_list:
                sorted_chan_guide[channel] = whatson[channel]

            for channel in list(sorted_chan_guide.keys()):
                if sorted_chan_guide[channel]["listing"][0]["time_end"]:
                    remaining_time = humanized_time(
                        sorted_chan_guide[channel]["listing"][0]["time_end"] -
                        nowtime)
                else:
                    remaining_time = "N/A"

                chan_dict = {
                    "name":
                    sorted_chan_guide[channel]["name"],
                    "number":
                    sorted_chan_guide[channel]["number"],
                    "chan_thumbnail":
                    sorted_chan_guide[channel]["thumbnail"],
                    "listing_title":
                    sorted_chan_guide[channel]["listing"][0]["title"],
                    "listing_thumbnail":
                    sorted_chan_guide[channel]["listing"][0]["thumbnail"],
                    "listing_description":
                    sorted_chan_guide[channel]["listing"][0]["description"],
                    "listing_remaining_time":
                    str(remaining_time)
                }

                for time_item in ["time_start", "time_end"]:

                    if not sorted_chan_guide[channel]["listing"][0][time_item]:
                        chan_dict["listing_%s" % time_item] = "N/A"
                    elif str(sorted_chan_guide[channel]["listing"][0]
                             [time_item]).endswith(tuple(["+0000", "+00:00"])):
                        chan_dict["listing_%s" %
                                  time_item] = str(sorted_chan_guide[channel]
                                                   ["listing"][0][time_item])
                    else:
                        chan_dict["listing_%s" % time_item] = str(
                            datetime.datetime.fromtimestamp(
                                sorted_chan_guide[channel]["listing"][0]
                                [time_item]))

                if source in self.fhdhr.origins.valid_origins:
                    chan_obj = self.fhdhr.device.channels.get_channel_obj(
                        "origin_id", sorted_chan_guide[channel]["id"], source)

                    chan_dict["name"] = chan_obj.dict["name"]
                    chan_dict["number"] = chan_obj.number
                    chan_dict["chan_thumbnail"] = chan_obj.thumbnail
                    chan_dict["enabled"] = chan_obj.dict["enabled"]
                    chan_dict["m3u_url"] = chan_obj.api_m3u_url

                    chan_dict["listing_thumbnail"] = chan_dict[
                        "listing_thumbnail"] or chan_obj.thumbnail
                else:
                    if not chan_dict["listing_thumbnail"]:
                        chan_dict["listing_thumbnail"] = chan_dict[
                            "chan_thumbnail"]
                    if not chan_dict["listing_thumbnail"]:
                        chan_dict[
                            "listing_thumbnail"] = "/api/images?method=generate&type=channel&message=%s" % chan_dict[
                                "number"]

                chan_guide_list.append(chan_dict)

            epg_json = json.dumps(chan_guide_list, indent=4)

            return Response(status=200,
                            response=epg_json,
                            mimetype='application/json')

        elif method == "update":
            self.fhdhr.device.epg.update(source)

        elif method == "clearcache":
            self.fhdhr.device.epg.clear_epg_cache(source)

        else:
            return "%s Invalid Method" % method

        if redirect_url:
            return redirect(
                "%s?retmessage=%s" %
                (redirect_url, urllib.parse.quote("%s Success" % method)))
        else:
            return "%s Success" % method
Пример #9
0
    def get(self, *args):

        nowtime = datetime.datetime.utcnow().timestamp()

        source = request.args.get('source',
                                  default=self.fhdhr.device.epg.def_method,
                                  type=str)
        epg_methods = self.fhdhr.device.epg.valid_epg_methods
        if source not in epg_methods:
            source = self.fhdhr.device.epg.def_method

        origin_methods = self.fhdhr.origins.valid_origins

        channelslist = {}

        if not source:
            return render_template('guide.html',
                                   request=request,
                                   session=session,
                                   fhdhr=self.fhdhr,
                                   channelslist=channelslist,
                                   epg_methods=epg_methods,
                                   origin=source,
                                   origin_methods=origin_methods,
                                   list=list)

        whatson_all = self.fhdhr.device.epg.whats_on_allchans(source)

        if source in origin_methods:

            sorted_channel_list = channel_sort([
                self.fhdhr.device.channels.list[source][x].number
                for x in list(self.fhdhr.device.channels.list[source].keys())
            ])
            for channel in sorted_channel_list:

                channel_obj = self.fhdhr.device.channels.get_channel_obj(
                    "number", channel, source)
                channel_dict = channel_obj.dict.copy()

                now_playing = whatson_all[channel]

                channel_dict["number"] = channel_obj.number
                channel_dict["chan_thumbnail"] = channel_obj.thumbnail
                channel_dict["m3u_url"] = channel_obj.api_m3u_url

                current_listing = now_playing["listing"][0]

                channel_dict["listing_title"] = current_listing["title"]
                channel_dict["listing_thumbnail"] = current_listing[
                    "thumbnail"]
                channel_dict["listing_description"] = current_listing[
                    "description"]

                if current_listing["time_end"]:
                    channel_dict["listing_remaining_time"] = humanized_time(
                        current_listing["time_end"] - nowtime)
                else:
                    channel_dict["listing_remaining_time"] = "N/A"

                for time_item in ["time_start", "time_end"]:

                    if not current_listing[time_item]:
                        channel_dict["listing_%s" % time_item] = "N/A"
                    elif str(current_listing[time_item]).endswith(
                            tuple(["+0000", "+00:00"])):
                        channel_dict["listing_%s" % time_item] = str(
                            current_listing[time_item])
                    else:
                        channel_dict["listing_%s" % time_item] = str(
                            datetime.datetime.fromtimestamp(
                                current_listing[time_item]))

                channelslist[channel_obj.number] = channel_dict

        elif source in epg_methods:
            sorted_channel_list = channel_sort(
                [x for x in list(whatson_all.keys())])

            for channel in sorted_channel_list:

                channel_dict = {
                    "name": whatson_all[channel]["name"],
                    "number": whatson_all[channel]["number"],
                    "chan_thumbnail": whatson_all[channel]["thumbnail"],
                }

                now_playing = whatson_all[channel]

                current_listing = now_playing["listing"][0]

                channel_dict["listing_title"] = current_listing["title"]
                channel_dict["listing_thumbnail"] = current_listing[
                    "thumbnail"]
                channel_dict["listing_description"] = current_listing[
                    "description"]

                if current_listing["time_end"]:
                    channel_dict["listing_remaining_time"] = humanized_time(
                        current_listing["time_end"] - nowtime)
                else:
                    channel_dict["listing_remaining_time"] = "N/A"

                for time_item in ["time_start", "time_end"]:

                    if not current_listing[time_item]:
                        channel_dict["listing_%s" % time_item] = "N/A"
                    elif str(current_listing[time_item]).endswith(
                            tuple(["+0000", "+00:00"])):
                        channel_dict["listing_%s" % time_item] = str(
                            current_listing[time_item])
                    else:
                        channel_dict["listing_%s" % time_item] = str(
                            datetime.datetime.fromtimestamp(
                                current_listing[time_item]))

                channelslist[channel] = channel_dict

        return render_template('guide.html',
                               request=request,
                               session=session,
                               fhdhr=self.fhdhr,
                               channelslist=channelslist,
                               epg_methods=epg_methods,
                               origin=source,
                               origin_methods=origin_methods,
                               list=list)