using System;
using System.Data.Common;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml.Linq;

namespace DragonVideoPlayer
{
    public class channel_class
    {
        public static String? channel_id{ get; set; }
    }
    public class cat_url
    {
        public static List<string> music_urls = new List<string>();
        public static List<string> anime_urls = new List<string>();
        public static List<string> movie_urls = new List<string>();
        public static List<string> sports_urls = new List<string>();
        public static List<string> hobby_urls = new List<string>();
        public static List<string> culture_urls = new List<string>();
        public static List<string> kansai_urls = new List<string>();
        public static List<string> tv_urls = new List<string>();
        public static List<string> bs_urls = new List<string>();
        public static List<string> adult_urls = new List<string>();
        public static List<string> asia_urls = new List<string>();
        public static List<string> gamble_urls = new List<string>();
        public static List<string> news_urls = new List<string>();
        public static Dictionary<string, Dictionary<string, string>> category_map
            = new Dictionary<string, Dictionary<string, string>>();
    }
    public class title_generate
    {
       
public static readonly Dictionary<string, string> _rakuten_epg_ChannelNameMap = new Dictionary<string, string>
{
    { "fishing", "rch_46" },              // 釣り
    { "pet", "rch_86" },                  // ワンニャンチャンネル
    { "ntv-newsselect", "rch_101" },      // 日テレNEWSセレクト
    { "movie2", "rch_42" },               // 映画（年齢制限あり）
    { "game", "rch_113" },                // ぷれいば！ ～ゲーム専門チャンネル～
    { "rchannelmensneco", "rch_59" },     // おとなの歓楽街 by MEN’S NECO
    { "rvariety", "rch_98" },             // セクシーエンタメチャンネル
    { "enka", "rch_85" },                 // 演歌・歌謡
    { "nagoyanext", "rch_37" },           // エンタメ～テレDEEP
    { "fcbarcelona-fcbenglishcmag", "rch_89" }, // TOP BARCA
    { "pachislo", "rch_35" },             // パチンコ・パチスロ
    { "mahjong", "rch_74" },              // 麻雀
    { "shogi", "rch_36" },                // 将棋
    { "igo-shogi", "rch_100" },           // 囲碁・将棋ライト
    { "anime5", "rch_73" },               // 手塚プロダクションTV
    { "shigekisports", "rch_48" },        // 刺激ストロングSPORTS
    { "skya", "rch_49" },                 // スカイA
    { "ntv-pro-wrestling", "rch_97" },    // 日テレプロレスアーカイ部
    { "fitness", "rch_75" },              // ゴルフ
    { "news2", "rch_54" },                // オリコンニュース
    { "news3", "rch_56" },                // 共同通信News
    { "news4", "rch_108" },               // FNNプライムオンライン
    { "news5", "rch_115" },               // MBSニュース
    { "tandt", "rch_30" },                // 鉄道・旅
    // { "cplusi", 該当なし },            // Lifetime／C+I は XML に存在しない
    { "movie", "rch_34" },                // ムビドラTV
    { "history", "rch_43" },              // HISTORY
    // { "rchannelbenesse", 該当なし },   // しまじろうチャンネルは XML に存在しない
    // { "kids-english", 該当なし },      // キッズ・イングリッシュは XML に存在しない
    { "shigeki", "rch_40" },              // 刺激ストロング
    { "gaora", "rch_51" },                // GAORA ZERO
    { "fueltv", "rch_64" },               // FUEL TV
    { "news1", "rch_47" },                // 日テレNEWS
    { "gravure", "rch_41" },              // アイドル・グラビア
    { "local-contents", "rch_114" },      // 九州・沖縄 街ネタ
    { "nowrock", "rch_107" },             // that’s Rock
    { "-now90s00s", "rch_106" },          // that’s 90s00s
    { "now70s", "rch_104" },              // that’s 70s
    { "now80s", "rch_105" },              // that’s 80s
    { "tokyomx", "rch_88" },              // TOKYO MX チャンネル

    };
        public static readonly Dictionary<string, string> _fast_epg_channelMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
    { "69608FB2725E0FA3B972", "fastch_v2_kids" },       // アニマックスFREE
    { "69551F080000E209AD09", "fastch_v2_pett1" },      // ペットTV
    { "696095BC725E0FE5F3E9", "fastch_v2_travl" },      // 今日のごはん、なに？
    { "69998DB5725E30535DA6", "fastch_v2_tokai" },      // 東海ロキポch
    { "696074B664B80F46A876", "fastch_v2_samri" },      // 時代劇TV
    { "69998C7B725E30DA4170", "fastch_v2_goshogi" },    // 囲碁・将棋ライト
    { "69608EE9725E0F73BF30", "fastch_v2_jpthp" },      // ぴあ落語ざんまい
    { "696082290000105F1525", "fastch_v2_comdy" },      // Lemino TV
    { "6960905473F5101B6A17", "fastch_v2_krdrm" },      // 韓流チャンネル
    { "69607D5C725E103DDF9D", "fastch_v2_bgolf" },      // GOLF LIFE
    { "696078CF64B81069221E", "fastch_v2_asdrm" },      // エンタメ・アジアFree
    { "6960899D64B80F9C740C", "fastch_v2_entns" },      // エンタメニュース POWERED BY ORICON NEWS
    { "69609952725E0FA3B987", "fastch_v2_snyon" },      // FASHION+
    { "696090F573F51039B31F", "fastch_v2_news1" },      // 丸ごと九州ch
    { "69998D0964B83951E552", "fastch_v2_hokkaido" },   // 丸ごと北海道ch
    { "69607EBD725E0F65BEE4", "fastch_v2_busns" },      // ビジネス・プレミアムチャンネル
    { "6960965C64B80F2C027D", "fastch_v2_recip" },      // 観るたび PRODUCED by るるぶ
    { "69607E1D725E0FB5AC23", "fastch_v2_camng" },      // キャンプ・アウトドアチャンネル
};
        public static Dictionary<string, string> _mov3_epg_karenda_Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
            
    // ニュース・総合
    
                { "https://fujitv4.mov3.co/hls/fujitv.m3u8","フジテレビ_jp" },
                 { "https://nhk4.mov3.co/hls/nhk.m3u8","NHK東京・総合_jp" },
                   { "https://tbs5.mov3.co/hls/tbs.m3u8","TBS_jp" },
            { "https://ntv5.mov3.co/hls/ntv.m3u8", "日本テレビ_jp" },


    { "https://tvtokyo.mov3.co/hls/tvtokyo.m3u8", "テレ東_jp" },
   { "https://tvasahi.mov3.co/hls/tvasahi.m3u8", "テレビ朝日_jp" },

{ "https://ok.ru/videoembed/16358768582178", "TOKYO・MX_jp" }

            };
        public static readonly Dictionary<string, string> _akari_ChannelMap = new Dictionary<string, string>
    {
        // 地上波 (関東)
        { "fuji_tv", "フジテレビ" },
        { "nhk_e", "NHK Eテレ" },
        { "nhk_g", "NHK総合" },
        { "nhk_g_%28subch%29", "NHK総合 (サブチャンネル)" },
        { "ntv", "日本テレビ" },
        { "tbs", "TBS" },
        { "tokyo_mx1", "TOKYO MX1" },
        { "tokyo_mx2", "TOKYO MX2" },
        { "tv_asahi", "テレビ朝日" },
        { "tv_tokyo", "テレビ東京" },

        // 地上波 (近畿)
        { "abc", "朝日放送テレビ" },
        { "kbs", "KBS京都" },
        { "kansai_tv", "関西テレビ" },
        { "mbs", "MBS毎日放送" },
        { "nhk_g_osaka", "NHK総合・大阪" },
        { "sun", "サンテレビ" },
        { "tv_osaka", "テレビ大阪" },
        { "ytv", "読売テレビ" },

        // BS
        { "bs_10", "bs10" },
           { "bs_yoshimoto", "BSよしもと" },
        { "bs_10_premium", "BS10プレミアム" },
        { "bs_asahi", "BS朝日" },
        { "bs_fuji", "BSフジ" },
        { "bs_ntv", "BS日テレ" },
        { "bs_tbs", "BS-TBS" },
        { "bs_tv_tokyo", "BSテレ東" },
        { "bs11", "BS11イレブン" },
        { "bs_12", "BS12 トゥエルビ" },
        { "nhk_bs", "NHK BS" },
        { "nhk_bs_%28subch%29", "NHK BS (サブチャンネル)" },
        { "nhk_bs4k", "NHK BSプレミアム4K" },
        { "jcom_bs", "JCOM BS" },
              { "bs_asahi_4k", "BS朝日4K" },

        // CS / BS専門チャンネル
        { "animax", "アニマックス" },
        { "disney_channel", "ディズニー・チャンネル" },
        { "fishing_vision", "釣りビジョン" },
        { "green_channel", "グリーンチャンネル" },
        { "jsport_1", "J SPORTS 1" },
        { "jsport_2", "J SPORTS 2" },
        { "jsport_3", "J SPORTS 3" },
        { "dlife", "Dlife" },
        { "jsport_4", "J SPORTS 4" },
        { "nihon_eiga_senmon", "日本映画専門チャンネル" },
        { "sky_a", "スカイA" },
        { "wowow_cinema", "WOWOWシネマ" },
        { "wowow_live", "WOWOWライブ" },
        { "wowow_plus", "WOWOWプラス" },
        { "wowow_prime", "WOWOWプライム" },
        { "at-x", "AT-X" },
        { "action_channel", "アクションチャンネル" },
        { "animal_planet", "アニマルプラネット" },
        { "bbc_news", "BBCニュース" },
        { "cnnj", "CNNj" },
        { "cartoon_network", "カートゥーン ネットワーク" },
        { "channel_ginga", "チャンネル銀河" },
        { "dance_channel", "ダンスチャンネル" },
        { "discovery_channel", "ディスカバリーチャンネル" },
        { "disney_junior", "ディズニージュニア" },
        { "eisei_gekijo", "衛星劇場" },
        { "family_gekijyo", "ファミリー劇場" },
        { "fighting_tv_samurai", "FIGHTING TV サムライ" },
        { "fuji_tv_next", "フジテレビNEXT" },
        { "fuji_tv_one", "フジテレビONE" },
        { "fuji_tv_two", "フジテレビTWO" },
        { "gaora_sports", "GAORA SPORTS" },
        { "golf_network", "ゴルフネットワーク" },
        { "history", "ヒストリーチャンネル" },
        { "home_drama_channel", "ホームドラマチャンネル" },
        { "jidaigeki_senmon", "時代劇専門チャンネル" },
        { "kbs_world", "KBS World" },
        { "kntv", "KNTV" },
        { "kayo_pops", "歌謡ポップスチャンネル" },
        { "kids_station_tv", "キッズステーション" },
        { "lala_tv", "LaLa TV" },
        { "mtv", "MTV" },
        { "me-tele_next", "メーテレNEWS" },
        { "mnet", "Mnet" },
        { "mondo_tv", "MONDO TV" },
        { "movie_plus", "ムービープラス" },
        { "music_japan_tv", "ミュージック・ジャパンTV" },
        { "music_on_tv", "MUSIC ON! TV" },
        { "mystery_channel", "ミステリーチャンネル" },
        { "neco_ch", "映画・チャンネルNECO" },
        { "ntv_news24", "日テレNEWS24" },
        { "national_geographic_japan", "ナショナル ジオグラフィック" },
        { "nittele_g+", "日テレジータス" },
        { "nittele_plus", "日テレプラス" },
        { "pigoo_nsfw", "アイドル専用チャンネルPigoo" },
        { "shogi_channel", "囲碁・将棋チャンネル" },
        { "space_shower_tv", "スペースシャワーTV" },
        { "sport_live_plus", "スポーツライブ＋" },
        { "super_drama_tv", "スーパー! ドラマTV" },
        { "tbs_channel_1", "TBSチャンネル1" },
        { "tbs_channel_2", "TBSチャンネル2" },
        { "tbs_news", "TBS NEWS" },
        { "tv_asahi_channel_1", "テレ朝チャンネル1" },
        { "tv_asahi_channel_2", "テレ朝チャンネル2" },
        { "tabi_channel", "旅チャンネル" },
        { "takarazuka_sky_stage", "宝塚スカイステージ" },
        { "tetsudo_channel", "鉄道チャンネル" },
        { "the_cinema", "ザ・シネマ" },
        { "toei_channel", "東映チャンネル" },
        { "v_paradise_nsfw", "Vパラダイス" },
        { "weather_news", "ウェザーニュース" },
          { "music_air", "ミュージック・エア" }
    };
        public static Dictionary<string, string> _mov3_epg_animenosekai_Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
            
    // ニュース・総合
    
                { "https://fujitv4.mov3.co/hls/fujitv.m3u8","JOCXDTV.jp" },
                 { "https://nhk4.mov3.co/hls/nhk.m3u8","JOAKDTV.jp" },
                   { "https://tbs5.mov3.co/hls/tbs.m3u8","JORXDTV.jp" },
            { "https://ntv5.mov3.co/hls/ntv.m3u8", "JOAXDTV.jp" },


    { "https://tvtokyo.mov3.co/hls/tvtokyo.m3u8", "JOTXDTV.jp" },
   { "https://tvasahi.mov3.co/hls/tvasahi.m3u8", "JOEXDTV.jp" },
{ "https://ok.ru/videoembed/16358768582178", "TokyoMX1.jp" }
            };
     
        private static Dictionary<string, string> _mov3Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
        { 
            
    // ニュース・総合
    
                { "https://fujitv4.mov3.co/hls/fujitv.m3u8","フジテレビ" },
                 { "https://nhk4.mov3.co/hls/nhk.m3u8","NHK" },
                   { "https://tbs5.mov3.co/hls/tbs.m3u8","TBS" },
            { "https://ntv5.mov3.co/hls/ntv.m3u8", "日本テレビ" },
            { "https://tvtokyo.mov3.co/hls/tvtokyo.m3u8", "TV東京" },
{ "https://tvasahi.mov3.co/hls/tvasahi.m3u8", "TV朝日" },

{ "https://ok.ru/videoembed/16358768582178", "TokyoMX" },

};


        public static readonly Dictionary<string, string> _Epg_naori_karenda_Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
    // 地上波(関東)
    { "gd01", "NHK東京・総合_jp" },
    { "gd02", "NHK東京・教育_jp" },
    { "gd03", "日本テレビ_jp" },
    { "gd04", "TBS_jp" },
    { "gd05", "フジテレビ_jp" },
    { "gd06", "テレビ朝日_jp" },
    { "gd07", "テレ東_jp" },
    { "gd08", "TOKYO・MX_jp" },

    { "hdgd01", "NHK東京・総合_jp" },
    { "hdgd02", "NHK東京・教育_jp" },
    { "hdgd03", "日本テレビ_jp" },
    { "hdgd04", "TBS_jp" },
    { "hdgd05", "フジテレビ_jp" },
    { "hdgd06", "テレビ朝日_jp" },
    { "hdgd07", "テレ東_jp" },
    { "hdgd08", "TOKYO・MX_jp" },

    // 地上波(関西)
    { "gx01", "毎日テレビ_jp" },
    { "gx02", "ABCテレビ_jp" },
    { "gx03", "関西テレビ_jp" },
    { "gx04", "読売テレビ_jp" },
    { "gx05", "テレビ大阪_jp" },
    { "gx06", "NHK大阪・総合_jp" },
    { "gx07", "サンテレビ_jp" },
    { "gx08", "TOKYO・MX_jp" },

    // BS
    { "bs01", "NHK・BSP_jp" },
    { "bs02", "BS日テレ_jp" },
    { "bs03", "BS朝日_jp" },
    { "bs04", "BS-TBS_jp" },
    { "bs05", "BSテレ東_jp" },
    { "bs06", "BSフジ_jp" },
    { "bs07", "WOWOWシネマ_jp" },
    { "bs11", "NHK・BS_jp" },
    { "bs12", "WOWOWプライム_jp" },
    { "bs14", "グリーンチャンネル_jp" },
    { "bs15", "アニマックス_jp" },
    { "bs16", "日本映画専門チャンネル_jp" },
    { "bs18", "J-SPORTS-1_jp" },
    { "bs19", "J-SPORTS-2_jp" },
    { "bs20", "WOWOWライブ_jp" },
    { "bs21", "J-SPORTS-3_jp" },
    { "bs22", "J-SPORTS-4_jp" },
    { "bs24", "ディズニー・チャンネル_jp" },
    { "bs25", "釣りビジョン_jp" },
    { "bs26", "スペースシャワーTV_jp" },
    { "bs31", "J-COM-BS_jp" },

    // CS
    { "cs01", "スカイA_jp" },
    { "cs02", "日テレジータス_jp" },
    { "cs03", "ゴルフネットワーク_jp" },
    { "cs04", "時代劇専門チャンネル_jp" },
    { "cs05", "ホームドラマチャンネル_jp" },
    { "cs06", "ミュージック・ジャパンTV_jp" },
    { "cs07", "キッズステーション_jp" },
    { "cs08", "ディスカバリーチャンネル_jp" },
    { "cs09", "ヒストリーチャンネル_jp" },
    { "cs10", "ナショナル-ジオグラフィック_jp" },
    { "cs11", "TBS-NEWS_jp" },
    { "cs12", "旅チャンネル_jp" },
    { "cs13", "歌謡ポップスチャンネル_jp" },
    { "cs15", "BBCニュース_jp" },
    { "cs16", "CNNj_jp" },
    { "cs17", "GAORA-SPORTS_jp" },
    { "cs18", "MTV_jp" },
    { "cs19", "LaLa-TV_jp" },
    { "cs20", "ファミリー劇場_jp" },
    { "cs21", "MONDOTV_jp" },
    { "cs22", "衛星劇場_jp" },
    { "cs23", "ディズニージュニア_jp" },
    { "cs24", "アニマルプラネット_jp" },
    { "cs25", "カートゥーン-ネットワーク_jp" },
    { "cs26", "フジテレビNEXT_jp" },
    { "cs27", "東映チャンネル_jp" },
    { "cs28", "タカラヅカ・スカイ・ステージ_jp" },
    { "cs29", "チャンネル銀河_jp" }
};
        public static readonly Dictionary<string, string> _Epg_naori_animenosekai_Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
    // 地上波(関東)
    { "gd01", "nhk_g" },
    { "gd02", "nhk_e" },
    { "gd03", "ntv" },
    { "gd04", "tbs" },
    { "gd05", "fuji_tv" },
    { "gd06", "tv_asahi" },
    { "gd07", "tv_tokyo" },
    { "gd08", "tokyo_mx1" },

    { "hdgd01", "nhk_g" },
    { "hdgd02", "nhk_e" },
    { "hdgd03", "ntv" },
    { "hdgd04", "tbs" },
    { "hdgd05", "fuji_tv" },
    { "hdgd06", "tv_asahi" },
    { "hdgd07", "tv_tokyo" },
    { "hdgd08", "tokyo_mx1" },

    // 地上波(関西)
    { "gx01", "mbs" },
    { "gx02", "abc" },
    { "gx03", "kansai_tv" },
    { "gx04", "ytv" },
    { "gx05", "tv_osaka" },
    { "gx06", "nhk_g_osaka" },
    { "gx07", "sun" },
    { "gx08", "tokyo_mx1" },

    // BS
    { "bs01", "nhk_bs4k" },
    { "bs02", "bs_ntv" },
    { "bs03", "bs_asahi" },
    { "bs04", "bs_tbs" },
    { "bs05", "bs_tv_tokyo" },
    { "bs06", "bs_fuji" },
    { "bs07", "wowow_cinema" },
    { "bs11", "nhk_bs" },
    { "bs12", "wowow_prime" },
    { "bs14", "green_channel" },
    { "bs15", "animax" },
    { "bs16", "nihon_eiga_senmon" },
    { "bs18", "jsport_1" },
    { "bs19", "jsport_2" },
    { "bs20", "wowow_live" },
    { "bs21", "jsport_3" },
    { "bs22", "jsport_4" },
    { "bs24", "disney_channel" },
    { "bs25", "fishing_vision" },
    { "bs26", "space_shower_tv" },
    { "bs31", "jcom_bs" },

    // CS
    { "cs01", "sky_a" },
    { "cs02", "nittele_g+" },
    { "cs03", "golf_network" },
    { "cs04", "jidaigeki_senmon" },
    { "cs05", "home_drama_channel" },
  { "cs06", "Music Japan TV" },         
    { "cs07", "kids_station_tv" },
    { "cs08", "discovery_channel" },
    { "cs09", "history" },
    { "cs10", "national_geographic_japan" },
    { "cs11", "tbs_news" },
    { "cs12", "tabi_channel" },
    { "cs13", "kayo_pops" },
    { "cs15", "bbc_news" },
    { "cs16", "cnnj" },
    { "cs17", "gaora_sports" },
    { "cs18", "mtv" },
    { "cs19", "lala_tv" },
    { "cs20", "family_gekijyo" },
    { "cs21", "mondo_tv" },
    { "cs22", "eisei_gekijo" },
    { "cs23", "disney_junior" },
    { "cs24", "animal_planet" },
    { "cs25", "cartoon_network" },
    { "cs26", "fuji_tv_next" },
    { "cs27", "toei_channel" },
    { "cs28", "takarazuka_sky_stage" },
    { "cs29", "channel_ginga" }
};
 
        public static Dictionary<string, string> _naori_channelMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
 // HD Channels
            { "hdgd01", "NHK東京・総合" },
    { "hdgd02", "NHK東京・教育" },
    { "hdgd03", "日本テレビ" },
    { "hdgd06", "テレビ朝日" },
    { "hdgd04", "TBS" },
    { "hdgd07", "テレ東" },
    { "hdgd05", "フジテレビ" },
    { "hdgd08", "TOKYO・MX" },
    // CS Channels
    { "CS04", "時代劇専門チャンネル" },
    { "cs05", "ホームドラマチャンネル" },
    { "cs12", "旅チャンネル" },
    { "cs01", "スカイA" }, // ※Channel Gingaも同じID
    { "cs17", "GAORA SPORTS" },
    { "cs03", "ゴルフネットワークk" },
    { "cs02", "日テレジータス" },
    { "cs21", "Mondo TV" },
    { "cs08", "ディスカバリーチャンネル" },
    { "cs06", "Music Japan TV" },
    { "cs23", "ディズニージュニア" },
    { "cs24", "アニマルプラネット" },
    { "cs09", "ヒストリーチャンネル" },
    { "cs13", "歌謡ポップスチャンネル" },
    { "cs18", "MTV" },
    { "cs19", "LaLa TV" },
    { "cs28", "宝塚歌劇専門チャンネル" },
    { "cs07", "キッズステーション" },
    { "cs25", "カートゥーン ネットワーク" },
    { "cs10", "ナショナルジオグラフィック" },
    { "cs16", "CNNj" },
    { "cs15", "BBC News" },
    { "cs11", "TBS News" },
    { "cs27", "東映チャンネル" },
    { "cs22", "衛星劇場" },
    { "cs20", "ファミリー劇場" },
    { "cs14", "ムービープラス" },
    { "cs26", "フジテレビNext" },
         { "cs29", "チャンネル銀河" },

    // BS Channels

    { "bs15", "アニマックス" },
    { "bs12", "WOWOWプライム" },
    { "bs07", "WOWOWシネマ" }, // ※WOWOW Cinemaも同じID
    { "bs08", "スターチャンネル2" },
    { "bs18", "JSports 1" },
    { "bs19", "JSports 2" },
    { "bs21", "JSports 3" },
    { "bs22", "JSports 4" },
    { "bs25", "釣りビジョン" },
    { "bs11", "NHK BS" },
    { "bs02", "BS日テレ" },
    { "bs03", "BS朝日" },
    { "bs04", "BS TBS" },
    { "bs05", "BS TV東京" },
    { "bs06", "BSフジ" },
    { "bs01", "NHK BS4K" },
      { "bs14", "グリーンチャンネル" },
  { "bs20", "WOWOWライブ" },
  { "bs16", "日本映画専門チャンネル" },
  { "bs23", "NHK BS4K" },
  { "bs24", "ディズニー・チャンネル" },
  { "bs26", "スペースシャワーTV" },
  { "bs27", "スターチャンネル2" },
   { "bs28", "スターチャンネル3" },
         { "bs31", "JCOM BS" },

    // Terrestrial Channels (HD/SD)

    { "gx01", "MBS" },
    { "gx02", "朝日放送" },
 { "gx03", "関西TV" },
 { "gx04", "読売TV" },
 { "gx05", "TV大阪" },
 { "gx06", "NHK G 大阪" },
 { "gx07", "サンテレビ" },
 { "gx08", "TOKYO MX1" },
    { "gd01", "NHK G" },
    { "gd02", "NHK E" },
    { "gd03", "日テレ" },
    { "gd04", "TBS" },
    { "gd05", "フジテレビ" },
    { "gd06", "TV朝日" },
    { "gd07", "TV東京" },
    { "gd08", "TOKYO MX1" }
};
      

 
        public static readonly Dictionary<string, string> _rakuten_ChannelNameMap = new Dictionary<string, string>
    {
        { "fishing", "釣り" },
        { "pet", "ワンニャン(ペット)" },
          { "ntv-newsselect", "日テレニュースセレクト" },
        { "movie2", "映画2(アダルト）" },
         { "game", "ぷれいば！(game)" },
        { "rchannelmensneco", "おとなの歓楽街 by MEN’S NECO" },
        { "rvariety", "セクシーエンタメチャンネル" },
        { "enka", "演歌・歌謡" },
        { "nagoyanext", "エンタメーテレDEEP" },
          { "fcbarcelona-fcbenglishcmag", "TOP BARÇA(サッカー）" },
        { "pachislo", "パチンコ・パチスロ" },
        { "mahjong", "麻雀" },
        { "shogi", "将棋" },
      
        { "igo-shogi", "囲碁・将棋ライト" },
        { "anime5", "手塚プロダクションTV" },
        { "shigekisports", "刺激ストロングSPORTS" },
          { "skya", "スカイA(スポーツ)" },
        { "ntv-pro-wrestling", "日テレプロレスアーカイ部" },
        { "fitness", "ゴルフネットTV" },
        { "news2", "オリコンニュース" },
        { "news3", "共同通信News" },
         { "news4", "FNNプライム" },
            { "news5", "MBSニュース" },
        { "tandt", "鉄道・旅" },
        { "cplusi", "Lifetime／C+I" },
        { "movie", "ムビドラTV" },
        { "history", "ヒストリー" },
        { "rchannelbenesse", "しまじろうチャンネル" },
        { "kids-english", "キッズ・イングリッシュ" },
        { "shigeki", "刺激ストロング" },
        { "gaora", "GAORA(スポーツ)" },
        { "fueltv", "FUEL TV" },
        { "news1", "日テレニュース" },
        { "gravure", "グラビア" }  ,
        { "local-contents", "九州・沖縄街ネタ" }  ,
          { "nowrock", "that'sRock(Rock音楽)" }  ,

         { "-now90s00s", "that's90/00/(90年/2000代音楽)" }  ,
            { "now70s", "that's70s!(70年代音楽)" }  ,
                { "now80s", "that's 80s(80年代音楽)" }  ,
            { "tokyomx", "TOKYO MX(文字ニュース)" }  
      
    };
        public static Dictionary<string, string> _abemaMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
    {
        // ニュース・総合
   
         { "abema-news", "Abemaニュース" },
        { "news-plus", "Abemaニュースプラス" },
        { "abema-special", "Abemaスペシャル" },
        { "special-plus", "Abemaスペシャル2" },
        { "special-plus-7", "Abemaスペシャル3" }, // 以前の名称などの互換用

           { "metrock", "メトロック" },
        // アニメ・専門枠
  

          { "abema-anime", "Abemaアニメ" },
        { "abema-anime-2", "Abemaアニメ2" },
        { "abema-anime-3", "Abemaアニメ3" },
         { "naruto", "ナルト" },
           { "mushokutensei", "無職転生" },
                { "dr-stone", "Dr.STONE" },
        { "anime-special-2", "アニメ・スペシャル2" },
        { "anime-live", "アニメライブ2" },
         { "anime-live2", "アニメライブ2" },
              { "anime-live3", "アニメライブ3" },
        { "chibimaruko", "ちびまる子ちゃん" },
        { "atashinchi", "あたしンち" },
      
        { "isekai-anime", "異世界アニメ" },
        { "isekai-anime-2", "異世界アニメ2" },
        { "isekai-anime-3", "異世界アニメ3" },
        { "pokemon-1", "ポケモン1" },
    
        { "pokemon-2", "ポケモン2" },
        { "conan", "名探偵コナン" },
             { "keroro", "ケロロ軍曹" },
                { "Poker", "ポーカー" },
        { "onepiece", "ワンピース" },
        { "family-anime-1", "ファミリーアニメ1" },
        { "family-anime-2", "ファミリーアニメ2" },
              { "family-anime-3", "ファミリーアニメ3" },
        { "lovecomedy-anime", "ラブコメアニメ" },
        { "dailylife-anime", "日常・コメディアニメ" },
        { "late-night-anime", "深夜アニメ" },
        { "80s-anime-1", "80年代アニメ" },
        { "90s-anime-1", "90年代アニメ" },
        { "00s-anime-1", "2000年代アニメ" },

        // ドラマ・アジア
        { "asia-drama", "アジア・ドラマ" },
        { "asia-drama-2", "アジア・ドラマ 2" },
        { "chinese-drama", "中国ドラマ" },
        { "asia-love-comedy", "アジア・ラブコメ" },
        { "asia-loveromance", "アジア・ロマンス" },
        { "asia-historical", "アジア時代劇" },
        { "k-world", "K WORLD" },
        { "drama", "ドラマ" },
        { "drama-2", "ドラマ2" },
        { "drama-3", "ドラマ3" },

        // スポーツ・エンタメ・趣味
            { "rally-japan", "ラリージャパン" },
        { "mahjong", "麻雀" },
           { "mahjong-2", "麻雀2" },
        { "shogi", "将棋" },
        { "world-sports", "ワールドスポーツ" },
            { "world-sports-1", "ワールドスポーツ1" },
        { "motor-sport", "モータースポーツ" },
        { "sumo", "大相撲" },
        { "fighting-sports", "格闘" },
        { "hiphop", "HIPHOP" },
        { "commercial", "CM" },
        { "boatrace", "ボートレース" },
        { "keirin-auto", "競輪・オートレース" }
    };

        public static readonly Dictionary<string, string> _fast_channelMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
    {
        // 地上波 (Terrestrial)
        { "69608FB2725E0FA3B972","アニマックスFREE" },
        { "69551F080000E209AD09" ,"ペットTV" },
        { "696095BC725E0FE5F3E9", "今日のごはん、なに？" },
        { "69998DB5725E30535DA6", "東海ロキポch" },
        { "696074B664B80F46A876", "時代劇TV" },
        { "69998C7B725E30DA4170", "囲碁・将棋ライト" },
        { "69608EE9725E0F73BF30", "ぴあ落語ざんまい" },
        { "696082290000105F1525", "Lemino TV" },
        { "6960905473F5101B6A17", "韓流チャンネル" },
        { "69607D5C725E103DDF9D", "GOLF LIFE" },
        { "696078CF64B81069221E", "エンタメ・アジアFree" },
        { "6960899D64B80F9C740C", "エンタメニュース(オリコン)" },
        { "69609952725E0FA3B987", "FASHION＋" },
        { "696090F573F51039B31F", "丸ごと九州ch" },
        { "69998D0964B83951E552", "丸ごと北海道ch" },
         { "69607EBD725E0F65BEE4", "ビジネス・プレミアムチャンネル" },
        { "6960965C64B80F2C027D", "観るたび" },
        { "69607E1D725E0FB5AC23", "キャンプ・アウトドアチャンネル" }
      
    };
        public static (string title, string desc,String image_path,String category) Get_mov3_bungumi_title(String url, String xml, Dictionary<String, String> _EpgMap, XDocument doc)
        {



 
            if (_EpgMap.TryGetValue(url, out string epg_id))
            {
              

                if (File.Exists(xml))
                {
                   
                    var tuple_epg = epg.GetCurrentProgram(xml, epg_id,doc);
                  
                    channel_class.channel_id = epg_id;
                    return (
       tuple_epg.title,
       tuple_epg.desc,
          tuple_epg.image_path,
               tuple_epg.category
           );
                }

            }
            return ("", "","","");
        }
     
        public static (string title, string desc, String image_path, string category) Get_abema_bungumi_title(String url, int Segment, String xml, Dictionary<String, String> _EpgMapm, XDocument doc)
        {


            string epg_id = Get_SegmentsName(url, Segment);
            channel_class.channel_id = epg_id;


            if (File.Exists(xml))
                {

                    var tuple_epg = epg.GetCurrentProgram(xml, epg_id,doc);

                    return (
       tuple_epg.title,
       tuple_epg.desc,
        tuple_epg.image_path,
        tuple_epg.category
           );
                }

           
            return ("", "", "", "");
        }

        public static (string title, string desc,String image_path,string category) Get_bungumi_title(String url, int Segment,String xml,Dictionary<String,String> _EpgMap, XDocument doc)
        {
           

            String channe_name = Get_SegmentsName(url, Segment);

            if (System.Text.RegularExpressions.Regex.IsMatch(url, "zhon", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                try
                {
                    var uri = new Uri(url);

                    var query = HttpUtility.ParseQueryString(uri.Query);
                    channe_name = query["gid"];
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                }


            }
          
            if (System.Text.RegularExpressions.Regex.IsMatch(url, "rakuten", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                try
                {
                    var uri = new Uri(url);

                    if (uri.Segments.Length >= Segment)
                    {
                        channe_name = uri.Segments[Segment].Trim('/');
                        channe_name = channe_name.Replace("amg01076-lightningintern-lightning", "");
                        channe_name = channe_name.Replace("amg17560-", "");
                        channe_name = channe_name.Replace("amg17560-", "");


                        channe_name = channe_name.Replace("amg01287-rakutentvjapan-", "");
                        channe_name = channe_name.Replace("-cmaf-rakutenjp", "");
                        channe_name = channe_name.Replace("cmaf-rakutenjp", "");
                        channe_name = channe_name.Replace("-rakutenjp", "");
                        channe_name = channe_name.Replace("-cmaf1", "");
                        channe_name = channe_name.Replace("cmaf", "");
                        channe_name = channe_name.Replace("-hls", "");
                        channe_name = channe_name.Replace("hls", "");
                        channe_name = channe_name.Replace("amg01074-", "");
                        channe_name = channe_name.Replace("-fueltvjp", "");



                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                }
            }
          

            if (_EpgMap.TryGetValue(channe_name, out string epg_id))
            {
              
                if (File.Exists(xml))
                {
               

                    var tuple_epg = epg.GetCurrentProgram(xml, epg_id, doc);
               
                    return (
       tuple_epg.title,
       tuple_epg.desc,
        tuple_epg.image_path,
        tuple_epg.category
           );
                }
                    
            }
            return ("", "","","");
        }

        public static string Get_title(string url, Dictionary<string, string> ChannelMap, int Segment,String site_name)
        {
          
            String channe_name = Get_SegmentsName(url, Segment);


            if (System.Text.RegularExpressions.Regex.IsMatch(site_name, "zhon", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                try
                {
                    var uri = new Uri(url);

                    var query = HttpUtility.ParseQueryString(uri.Query);
                    channe_name = query["gid"];
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                }


            }
         
            
         


            if (System.Text.RegularExpressions.Regex.IsMatch(site_name, "rakuten", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                try
                {
                    var uri = new Uri(url);
                  
                    if (uri.Segments.Length >= Segment)
                    {
                        channe_name = uri.Segments[Segment].Trim('/');
                        channe_name = channe_name.Replace("amg01076-lightningintern-lightning", "");
                        channe_name = channe_name.Replace("amg17560-", "");
                        channe_name = channe_name.Replace("amg17560-", "");


                        channe_name = channe_name.Replace("amg01287-rakutentvjapan-", "");
                        channe_name = channe_name.Replace("-cmaf-rakutenjp", "");
                        channe_name = channe_name.Replace("cmaf-rakutenjp", "");
                        channe_name = channe_name.Replace("-rakutenjp", "");
                        channe_name = channe_name.Replace("-cmaf1", "");
                        channe_name = channe_name.Replace("cmaf", "");
                        channe_name = channe_name.Replace("-hls", "");
                        channe_name = channe_name.Replace("hls", "");
                        channe_name = channe_name.Replace("amg01074-", "");
                        channe_name = channe_name.Replace("-fueltvjp", "");

                   
                     
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                }
            }

          
            if (string.IsNullOrEmpty(channe_name)){

                channe_name= url;
            }
        
            if (ChannelMap.TryGetValue(channe_name, out string japaneseName))
            {


               
            }
            if (string.IsNullOrEmpty(japaneseName))
            {

                japaneseName = channe_name;
            }
                if (config_class.config_bool_read("カテゴリーを有効") == true)
                {

                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(mtv|music|音楽|スペースシャワー|ミュージック|ポップ|歌謡)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "音楽";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.music_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }

                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(sports|スカイA|相撲|格闘|ジータス|GOLF|プロレス|FIGHTING|ゴルフ)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "スポーツ";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.sports_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(九州|北海道|東海)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                {
                    string category = "ローカル・地方";

                    if (!cat_url.category_map.ContainsKey(category))
                        cat_url.category_map[category] = new Dictionary<string, string>();
                   
                    cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                }


                if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(映画|^ドラマ|チャンネル銀河|アクションチャンネル|ミステリーチャンネル|時代劇|シネマ|劇場|ムビドラ|東映|ムービー|WOWOWプラス|WOWOWプライム)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "映画・ドラマ";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.movie_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(パチンコ|メーテレDEEP|麻雀|競輪|ボートレース|グリーンチャンネル|MONDO)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "ギャンブル";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.gamble_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(AT-X|アニマックス|ポケモン|ちびまる子|ワンピース|あたしンち|キッズステーション|ディズニー|アニメ|カートゥーン|手塚プロ)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "アニメ";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.anime_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(セクシー|アダルト|刺激ストロング$|おとなの|Pigoo|グラビア|Vパラダイス|アイドル)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "アダルト・アイドル";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();

                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(釣り|キャンプ|鉄道|将棋)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "趣味";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.hobby_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(ヒストリ|アニマル|ディスカバリ|ジオグラフィック)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "教養";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.culture_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(大阪|関西|読売|朝日放送|京都|ABC|KBS|読売|サンテレビ|MBS$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "関西の地上波TV";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.kansai_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                Debug.WriteLine("japaneseName" + japaneseName);
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(フジテレビ$|^日テレ$|^日本テレビ$|^TBS$|^テレビ朝日$|^テレ東$|^TV朝日$|^テレビ東京$|^TOKYO MX([12])|NHK総合$|NHK Eテレ|NHK東京|NHK G|NHK E)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                {
                    Debug.WriteLine("地上波TV " + japaneseName);
                    string category = "地上波TV";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.tv_urls.Add(url);
                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(アジア|韓流|中国|K WORLD|KBS WORLD|KNTV)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "韓流・華流";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();

                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(BBC|CNNj|ニュース|news)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "ニュース";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();
                        cat_url.news_urls.Add(url);

                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(japaneseName, "(BS朝日|BSフジ|NHK BS|BSよしもと|BS日テレ|BS-TBS|BSテレ東|BS11|BS12|JCOM|BS10$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        string category = "BS無料";

                        if (!cat_url.category_map.ContainsKey(category))
                            cat_url.category_map[category] = new Dictionary<string, string>();

                        cat_url.category_map[category][url] = japaneseName + "(" + site_name + ")";
                    }
               

            }
         
            return japaneseName;
        
         
        }
        public static string Get_mov3(string channe_name)
        {


            if (string.IsNullOrEmpty(channe_name)) return channe_name;

            if (_mov3Map.TryGetValue(channe_name, out string japaneseName))
            {


                return japaneseName;
            }

            return channe_name;
        }
        public static string Get_epg_mov3(string channe_name)
        {


            if (string.IsNullOrEmpty(channe_name)) return channe_name;

            if (_mov3Map.TryGetValue(channe_name, out string japaneseName))
            {


                return japaneseName;
            }

            return channe_name;
        }
        public static string Get_abema(string url, int segment)
        {
            String channe_name = Get_SegmentsName(url, segment);


            if (string.IsNullOrEmpty(channe_name)) return channe_name;

            if (_abemaMap.TryGetValue(channe_name, out string japaneseName))
            {
                return japaneseName;
            }

            return channe_name;
        }
       

        public static string Get_SegmentsName(string url, int count)
        {
            try
            {
                var uri = new Uri(url);

                if (uri.Segments.Length >= count)
                    return uri.Segments[count].Trim('/');

            }
            catch (System.Exception ex)
            {

                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
            return "";
        }
     
        public static string GetRadikoStation(string url)
        {
            var uri = new Uri(url);

            string fragment = uri.Fragment; // #!/live/GBS

            if (fragment.StartsWith("#!/live/"))
                return fragment.Replace("#!/live/", "");

            return "";
        }
    }


}
