1 /* 2 * Copyright (C) 2005-2021 Team Kodi (https://kodi.tv) 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 * See LICENSE.md for more information. 6 */ 7 8 #pragma once 9 10 #include <map> 11 #include <string> 12 13 #include <kodi/addon-instance/pvr/Channels.h> 14 15 namespace iptvsimple 16 { 17 enum class CatchupMode 18 : int // same type as addon settings 19 { 20 DISABLED = 0, 21 DEFAULT, 22 APPEND, 23 SHIFT, 24 FLUSSONIC, 25 XTREAM_CODES, 26 TIMESHIFT, // Obsolete but still used by some providers, predates SHIFT 27 VOD 28 }; 29 30 constexpr int IGNORE_CATCHUP_DAYS = -1; 31 32 namespace data 33 { 34 static const std::string CHANNEL_LOGO_EXTENSION = ".png"; 35 36 class Channel 37 { 38 public: 39 static const std::string GetCatchupModeText(const CatchupMode& catchupMode); 40 41 Channel() = default; Channel(const Channel & c)42 Channel(const Channel &c) : m_radio(c.IsRadio()), m_uniqueId(c.GetUniqueId()), 43 m_channelNumber(c.GetChannelNumber()), m_subChannelNumber(c.GetSubChannelNumber()), 44 m_encryptionSystem(c.GetEncryptionSystem()), m_tvgShift(c.GetTvgShift()), m_channelName(c.GetChannelName()), 45 m_iconPath(c.GetIconPath()), m_streamURL(c.GetStreamURL()), m_hasCatchup(c.HasCatchup()), 46 m_catchupMode(c.GetCatchupMode()), m_catchupDays(c.GetCatchupDays()), m_catchupSource(c.GetCatchupSource()), 47 m_isCatchupTSStream(c.IsCatchupTSStream()), m_catchupSupportsTimeshifting(c.CatchupSupportsTimeshifting()), 48 m_catchupSourceTerminates(c.CatchupSourceTerminates()), m_catchupGranularitySeconds(c.GetCatchupGranularitySeconds()), 49 m_catchupCorrectionSecs(c.GetCatchupCorrectionSecs()), m_tvgId(c.GetTvgId()), m_tvgName(c.GetTvgName()), 50 m_properties(c.GetProperties()), m_inputStreamName(c.GetInputStreamName()) {}; 51 ~Channel() = default; 52 IsRadio()53 bool IsRadio() const { return m_radio; } SetRadio(bool value)54 void SetRadio(bool value) { m_radio = value; } 55 GetUniqueId()56 int GetUniqueId() const { return m_uniqueId; } SetUniqueId(int value)57 void SetUniqueId(int value) { m_uniqueId = value; } 58 GetChannelNumber()59 int GetChannelNumber() const { return m_channelNumber; } SetChannelNumber(int value)60 void SetChannelNumber(int value) { m_channelNumber = value; } 61 GetSubChannelNumber()62 int GetSubChannelNumber() const { return m_subChannelNumber; } SetSubChannelNumber(int value)63 void SetSubChannelNumber(int value) { m_subChannelNumber = value; } 64 GetEncryptionSystem()65 int GetEncryptionSystem() const { return m_encryptionSystem; } SetEncryptionSystem(int value)66 void SetEncryptionSystem(int value) { m_encryptionSystem = value; } 67 GetTvgShift()68 int GetTvgShift() const { return m_tvgShift; } SetTvgShift(int value)69 void SetTvgShift(int value) { m_tvgShift = value; } 70 GetChannelName()71 const std::string& GetChannelName() const { return m_channelName; } SetChannelName(const std::string & value)72 void SetChannelName(const std::string& value) { m_channelName = value; } 73 GetIconPath()74 const std::string& GetIconPath() const { return m_iconPath; } SetIconPath(const std::string & value)75 void SetIconPath(const std::string& value) { m_iconPath = value; } 76 GetStreamURL()77 const std::string& GetStreamURL() const { return m_streamURL; } 78 void SetStreamURL(const std::string& url); 79 80 bool IsCatchupSupported() const; // Does the M3U entry or default settings denote catchup support HasCatchup()81 bool HasCatchup() const { return m_hasCatchup; } // Does the M3U entry denote catchup support SetHasCatchup(bool value)82 void SetHasCatchup(bool value) { m_hasCatchup = value; } GetCatchupMode()83 const CatchupMode& GetCatchupMode() const { return m_catchupMode; } SetCatchupMode(const CatchupMode & value)84 void SetCatchupMode(const CatchupMode& value) { m_catchupMode = value; } 85 GetCatchupDays()86 int GetCatchupDays() const { return m_catchupDays; } IgnoreCatchupDays()87 bool IgnoreCatchupDays() const { return m_catchupDays == IGNORE_CATCHUP_DAYS; } 88 void SetCatchupDays(int catchupDays); GetCatchupDaysInSeconds()89 int GetCatchupDaysInSeconds() const { return m_catchupDays * 24 * 60 * 60; } 90 GetCatchupSource()91 const std::string& GetCatchupSource() const { return m_catchupSource; } SetCatchupSource(const std::string & value)92 void SetCatchupSource(const std::string& value) { m_catchupSource = value; } 93 IsCatchupTSStream()94 bool IsCatchupTSStream() const { return m_isCatchupTSStream; } SetCatchupTSStream(bool value)95 void SetCatchupTSStream(bool value) { m_isCatchupTSStream = value; } 96 CatchupSupportsTimeshifting()97 bool CatchupSupportsTimeshifting() const { return m_catchupSupportsTimeshifting; } SetCatchupSupportsTimeshifting(bool value)98 void SetCatchupSupportsTimeshifting(bool value) { m_catchupSupportsTimeshifting = value; } 99 CatchupSourceTerminates()100 bool CatchupSourceTerminates() const { return m_catchupSourceTerminates; } SetCatchupSourceTerminates(bool value)101 void SetCatchupSourceTerminates(bool value) { m_catchupSourceTerminates = value; } 102 GetCatchupGranularitySeconds()103 int GetCatchupGranularitySeconds() const { return m_catchupGranularitySeconds; } SetCatchupGranularitySeconds(int value)104 void SetCatchupGranularitySeconds(int value) { m_catchupGranularitySeconds = value; } 105 GetCatchupCorrectionSecs()106 int GetCatchupCorrectionSecs() const { return m_catchupCorrectionSecs; } SetCatchupCorrectionSecs(int value)107 void SetCatchupCorrectionSecs(int value) { m_catchupCorrectionSecs = value; } 108 GetTvgId()109 const std::string& GetTvgId() const { return m_tvgId; } SetTvgId(const std::string & value)110 void SetTvgId(const std::string& value) { m_tvgId = value; } 111 GetTvgName()112 const std::string& GetTvgName() const { return m_tvgName; } SetTvgName(const std::string & value)113 void SetTvgName(const std::string& value) { m_tvgName = value; } 114 115 bool SupportsLiveStreamTimeshifting() const; 116 GetProperties()117 const std::map<std::string, std::string>& GetProperties() const { return m_properties; } SetProperties(std::map<std::string,std::string> & value)118 void SetProperties(std::map<std::string, std::string>& value) { m_properties = value; } AddProperty(const std::string & prop,const std::string & value)119 void AddProperty(const std::string& prop, const std::string& value) { m_properties.insert({prop, value}); } 120 std::string GetProperty(const std::string& propName) const; HasMimeType()121 bool HasMimeType() const { return !GetProperty(PVR_STREAM_PROPERTY_MIMETYPE).empty(); } GetMimeType()122 std::string GetMimeType() const { return GetProperty(PVR_STREAM_PROPERTY_MIMETYPE); } 123 GetInputStreamName()124 const std::string& GetInputStreamName() const { return m_inputStreamName; }; SetInputStreamName(const std::string & value)125 void SetInputStreamName(const std::string& value) { m_inputStreamName = value; } 126 127 void UpdateTo(Channel& left) const; 128 void UpdateTo(kodi::addon::PVRChannel& left) const; 129 void Reset(); 130 void SetIconPathFromTvgLogo(const std::string& tvgLogo, std::string& channelName); 131 void ConfigureCatchupMode(); 132 133 bool ChannelTypeAllowsGroupsOnly() const; 134 135 private: 136 void RemoveProperty(const std::string& propName); 137 void TryToAddPropertyAsHeader(const std::string& propertyName, const std::string& headerName); 138 139 bool GenerateAppendCatchupSource(const std::string& url); 140 void GenerateShiftCatchupSource(const std::string& url); 141 bool GenerateFlussonicCatchupSource(const std::string& url); 142 bool GenerateXtreamCodesCatchupSource(const std::string& url); 143 144 bool m_radio = false; 145 int m_uniqueId = 0; 146 int m_channelNumber = 0; 147 int m_subChannelNumber = 0; 148 int m_encryptionSystem = 0; 149 int m_tvgShift = 0; 150 std::string m_channelName = ""; 151 std::string m_iconPath = ""; 152 std::string m_streamURL = ""; 153 bool m_hasCatchup = false; 154 CatchupMode m_catchupMode = CatchupMode::DISABLED; 155 int m_catchupDays = 0; 156 std::string m_catchupSource = ""; 157 bool m_isCatchupTSStream = false; 158 bool m_catchupSupportsTimeshifting = false; 159 bool m_catchupSourceTerminates = false; 160 int m_catchupGranularitySeconds = 1; 161 int m_catchupCorrectionSecs = 0; 162 std::string m_tvgId = ""; 163 std::string m_tvgName = ""; 164 std::map<std::string, std::string> m_properties; 165 std::string m_inputStreamName; 166 }; 167 } //namespace data 168 } //namespace iptvsimple 169