-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWebRemocon.vb
1448 lines (1318 loc) · 71.6 KB
/
WebRemocon.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.IO
Imports System.Net
'★参幸にしたサイト★
'★簡易Webサーバを実装するには?
'☆http://www.atmarkit.co.jp/fdotnet/dotnettips/695httplistener/httplistener.html
'
'★HttpListener BeginGetContext を使わないと並列にリクエストを処理できない気がする。。。
'http://d.hatena.ne.jp/m_yamamo0417/20091220/1261324204
'http://msdn.microsoft.com/ja-jp/library/system.net.httplistener.begingetcontext%28v=vs.110%29.aspx
'
'★.NETを使った簡易HTTPサーバーの実装
'http://ivis-mynikki.blogspot.jp/2011/02/nethttp.html
'
'★DOSコマンドを実行し出力データを取得する
'http://dobon.net/vb/dotnet/process/standardoutput.html
'
'★外部アプリケーションを起動して終了まで待機する
'http://dobon.net/vb/dotnet/process/openfile.html
'
'★PT2/Friioの映像をiPhone/Kindle Fire HDで見る
'http://frmmpgit.blog.fc2.com/blog-entry-127.html
'
Class WebRemocon
Public _isWebStart As [Boolean] = False
Private _listener As HttpListener = Nothing
Private _procMan As ProcessManager = Nothing
'form1から変更されるパラメーター
Public _udpApp As String = Nothing
Public _udpOpt3 As String = Nothing
Public _chSpace As Integer = Nothing
Public _hlsApp As String = Nothing
Public _hlsroot As String = Nothing
Public _hlsOpt1 As String = Nothing
Public _hlsOpt2 As String = Nothing
Public _BonDriverPath As String = Nothing
Public _ShowConsole As Boolean = Nothing
Public _id As String
Public _pass As String
'変更されたら再起動が必要なパラメーター
Private _udpPort As Integer = Nothing
Private _wwwroot As String = Nothing
Private _fileroot As String = Nothing
Private _wwwport As Integer = Nothing
Private _BonDriver_NGword As String() = Nothing
Public _videopath() As String
Public _AddSubFolder As Integer
'NHK音声モード
'0=主副ステレオ 1=主モノラル固定 2=副モノラル固定 3=選択式 9=VLC使用
Public _NHK_dual_mono_mode As Integer = 0
'空きUDPポートが取得できないので暫定
Private _updCount As Integer
'VLCのオプション用
Public vlc_option() As VLCoptionstructure
Public Structure VLCoptionstructure
Public resolution As String '解像度 "640x360"
Public opt As String 'VLCオプション文字列
End Structure
'配信準備中 指定tsファイル数まで配信準備中にする
Public _tsfile_wait As Integer = 3
'MIME TYPE
Public _MIME_TYPE_DEFAULT As String = ""
Public _MIME_TYPE() As String
Public Sub New(udpApp As String, udpPort As Integer, udpOpt3 As String, chSpace As Integer, hlsApp As String, hlsOpt1 As String, hlsOpt2 As String, wwwroot As String, fileroot As String, wwwport As Integer, BonDriverPath As String, ShowConsole As Boolean, BonDriver_NGword As String(), ByVal id As String, ByVal pass As String)
'Public Sub New(udpPort As Integer, wwwroot As String, wwwport As Integer) ', num As Integer)
'初期化
'一度WEBサーバーが起動したら変わらないパラメーターを読み込む(変更は要再起動)
Me._udpPort = udpPort
Me._wwwroot = wwwroot
Me._wwwport = wwwport
Me._fileroot = fileroot
Me._BonDriver_NGword = BonDriver_NGword
'現在ファームにセットされている値をセット
Me._udpApp = udpApp
Me._udpOpt3 = udpOpt3
Me._hlsApp = hlsApp
Dim ss As String = "\"
Dim sp As Integer = hlsApp.LastIndexOf(ss)
If sp > 0 Then
Me._hlsroot = hlsApp.Substring(0, sp)
Else
Me._hlsroot = ""
End If
Me._hlsOpt1 = hlsOpt1
Me._hlsOpt2 = hlsOpt2
Me._chSpace = chSpace
Me._BonDriverPath = BonDriverPath
Me._ShowConsole = ShowConsole
Me._id = id
Me._pass = pass
'VLCオプションを読み込む
Me.read_vlc_option()
'ストリーム用インスタンス作成
Me._procMan = New ProcessManager(udpPort, wwwroot, fileroot)
End Sub
'urlからMIMETYPEを取得
Private Function get_mimetype(ByVal url As String) As String
Dim r As String = ""
Dim sp As Integer = url.LastIndexOf(".")
If sp >= 0 Then
Dim k As String = url.Substring(sp)
If (url.Length - sp) = k.Length And k.Length > 1 Then
k = k.Substring(1)
'kに拡張子が入っている
If Me._MIME_TYPE IsNot Nothing Then
For i As Integer = 0 To Me._MIME_TYPE.Length - 1
Dim d() As String = Me._MIME_TYPE(i).Split(":")
If d IsNot Nothing Then
If d.Length = 2 Then
If k = d(0) Then
r = d(1)
Exit For
End If
End If
End If
Next
End If
End If
End If
Return r
End Function
'HTTPサーバー開始
Public Sub Web_Start()
If Me._wwwport = 0 Then
MsgBox("httpサーバーの起動に失敗しました。" & vbCrLf & "httpポートを指定してこのアプリを再起動してください")
Exit Sub
End If
If Me._udpPort = 0 Then
MsgBox("httpサーバーの起動に失敗しました。" & vbCrLf & "UDPポートを指定してこのアプリを再起動してください")
Exit Sub
End If
Me._isWebStart = True
'string root = @"D:\html\"; // ドキュメント・ルート
'Dim root As String = ".\html\"
Dim root As String = Me._wwwroot
' ドキュメント・ルート
'★ localhost以外の場合、UACが有効だとHttpListenerExceptionが発生する
'★ 回避するには管理者権限で実行するか、コマンドプロンプトで
'★ 「netsh http add urlacl url=http://+:40003/ user=Everyone」(ENTER)と実行する。
'string prefix = "http://localhost:" + this._portNumber + "/"; // 受け付けるURL
Dim prefix As String = "http://+:" & Me._wwwport & "/"
' 受け付けるURL
Me._listener = New HttpListener()
Me._listener.Prefixes.Add(prefix)
'BASIC認証
If Me._id.Length > 0 And Me._pass.Length > 0 Then
'IDとパスが設定されていれば
Me._listener.AuthenticationSchemes = AuthenticationSchemes.Basic
Me._listener.Realm = "SECRET AREA"
End If
' プレフィックスの登録
Me._listener.Start()
While Me._isWebStart
Try
Dim context As HttpListenerContext = Me._listener.GetContext()
Dim req As HttpListenerRequest = context.Request
Dim res As HttpListenerResponse = context.Response
'MIME TYPE
Dim mimetype As String = get_mimetype(req.Url.LocalPath)
If mimetype.Length > 0 Then
res.ContentType = mimetype
ElseIf Me._MIME_TYPE_DEFAULT.Length > 0 Then
res.ContentType = Me._MIME_TYPE_DEFAULT
End If
Dim auth_ok As Integer = 0
If Me._id.Length = 0 Or Me._pass.Length = 0 Then
'パスワード未設定は素通り
auth_ok = 1
ElseIf req.IsAuthenticated Then
Dim identity As HttpListenerBasicIdentity = DirectCast(context.User.Identity, HttpListenerBasicIdentity)
'判定
If Me._id = identity.Name And Me._pass = identity.Password Then
'受付
auth_ok = 2
Else
auth_ok = -1
End If
Else
auth_ok = -2
End If
If auth_ok > 0 Then
' リクエストされたURLからファイルのパスを求める
Dim path As String = root & req.Url.LocalPath.Replace("/", "\")
'ルートにアクセスされた場合、index.htmlを表示する
Dim se1 As Integer = path.LastIndexOf("\")
If se1 >= 0 And (se1 + 1) = path.Length Then
path = path & "index.html"
End If
log1write(req.Url.LocalPath & "へのリクエストがありました。")
If res.ContentType IsNot Nothing Then
If res.ContentType.Length > 0 Then
log1write("MIME TYPE : " & res.ContentType)
End If
End If
If path.IndexOf(".htm") > 0 Then
'HTMLなら
'反応が速くなるかなとこの1行を前に出してみたが何も変わらなかった・・
Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
'ToLower小文字で比較
Dim StartTv_param As Integer = 0 'StartTvパラメーターが正常かどうか
Dim request_page As Integer = 0 '特別なリクエストかどうか
Dim chk_viewtv_ok As Integer = 0 'ViewTV.htmlへのリクエストなら1になる
'★リクエストパラメーターを取得
'スレッドナンバー
Dim num As Integer = 0
num = Val(System.Web.HttpUtility.ParseQueryString(req.Url.Query)("num") & "")
'Int32.TryParse(System.Web.HttpUtility.ParseQueryString(req.Url.Query)("num"), num)
'BonDriver指定
Dim bondriver As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("BonDriver") & ""
'サービスID指定
Dim sid As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("ServiceID") & ""
'chspace指定
Dim chspace As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("ChSpace") & ""
'Bon_Sid_Ch一括指定があった場合(JavaScript等でBon_Sid_Ch="BonDriver_t0.dll,12345,0"というように指定された場合)
Dim bon_sid_ch_str As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("Bon_Sid_Ch") & ""
Dim bon_sid_ch() As String = bon_sid_ch_str.Split(",")
If bon_sid_ch.Length = 3 Then
'個別に値が決まっていなければセット
If bondriver.Length = 0 Then bondriver = Trim(bon_sid_ch(0))
If sid.Length = 0 Then sid = Trim(bon_sid_ch(1))
If chspace.Length = 0 Then chspace = Trim(bon_sid_ch(2))
End If
'解像度指定 "640x360"等
Dim resolution As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("resolution") & ""
'redirect指定
Dim redirect As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("redirect") & ""
'm3u8,tsの準備状況
Dim check_m3u8_ts As Integer = 0
'ストリームモード 0=UDP 1=ファイル再生
Dim stream_mode As Integer = Val(System.Web.HttpUtility.ParseQueryString(req.Url.Query)("StreamMode") & "")
'ファイル名
Dim videoname As String = System.Web.HttpUtility.ParseQueryString(req.Url.Query)("VideoName") & ""
'URLエンコードしておいたフルパスを文字列に変換
videoname = System.Web.HttpUtility.UrlDecode(videoname)
'NHKの音声モード
Dim NHK_dual_mono_mode_select As Integer = 0
If Me._NHK_dual_mono_mode = 3 Then
NHK_dual_mono_mode_select = Val(System.Web.HttpUtility.ParseQueryString(req.Url.Query)("NHKMODE") & "")
Else
NHK_dual_mono_mode_select = Me._NHK_dual_mono_mode
End If
'WEBページ表示前処理
'特別なページ 配信スタート停止などサーバー動作を実行
If req.Url.LocalPath.ToLower.IndexOf("/ViewTV".ToLower) >= 0 Then
'通常視聴
request_page = 2
'numが<form>から渡されていなければURLから取得するViewTV2.htmlなら2
If num = 0 Then
Dim num_url As String = Val(req.Url.LocalPath.ToLower.Substring(req.Url.LocalPath.ToLower.IndexOf("ViewTV".ToLower) + "ViewTV".Length))
If num_url > 0 Then
num = num_url
End If
End If
Dim gln As String = Me._procMan.get_live_numbers()
gln = gln.Replace("x", "")
If gln.IndexOf(" " & num.ToString & " ") >= 0 Then
check_m3u8_ts = check_m3u8_ts_status(num)
If check_m3u8_ts < Me._tsfile_wait Then
'準備ができていない
request_page = 1 'waiting表示
Else
'ViewTV.html用
chk_viewtv_ok = 1
End If
Else
'配信されていない
request_page = 11
End If
ElseIf req.Url.LocalPath.ToLower = ("/StartTv.html").ToLower Then
'配信スタート
request_page = 3
'パラメーターが正しいかチェック
If num > 0 And bondriver.Length > 0 And Val(sid) > 0 And Val(chspace) >= 0 Then
'正しければ配信スタート
Me.start_movie(num, bondriver, Val(sid), Val(chspace), Me._udpApp, Me._hlsApp, Me._hlsOpt1, Me._hlsOpt2, Me._wwwroot, Me._fileroot, Me._hlsroot, Me._ShowConsole, Me._udpOpt3, videoname, NHK_dual_mono_mode_select, resolution)
'すぐさま視聴ページへリダイレクトする
redirect = "ViewTV" & num & ".html"
ElseIf num > 0 And videoname.Length > 0 Then
'ファイル再生
If Me._hlsApp.IndexOf("ffmpeg") > 0 Then
'ffmpegなら
Me.start_movie(num, "", 0, 0, "", Me._hlsApp, Me._hlsOpt1, Me._hlsOpt2, Me._wwwroot, Me._fileroot, Me._hlsroot, Me._ShowConsole, "", videoname, NHK_dual_mono_mode_select, resolution)
Else
'今のところVLCには未対応
request_page = 12
End If
'すぐさま視聴ページへリダイレクトする
redirect = "ViewTV" & num & ".html"
Else
StartTv_param = -1
End If
ElseIf req.Url.LocalPath.ToLower = "/CloseTv.html".ToLower Then
'配信停止
request_page = 4
Me.stop_movie(num)
ElseIf req.Url.LocalPath.ToLower = "/StopAll.html".ToLower Then
'すべてのプロセスと関連アプリを停止する
request_page = 5
stop_movie(-2)
ElseIf req.Url.LocalPath.ToLower = "/SelectVideo.html".ToLower Then
'ファイル選択ページ
request_page = 6
End If
'WEBページ表示
If StartTv_param = -1 Then
'/StartTvにリクエストがあったがパラメーターが不正な場合
'Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
sw.WriteLine(ERROR_PAGE("パラメーターが不正です", "パラメーターが不正です"))
'sw.Flush()
log1write("パラメーターが不正です")
ElseIf request_page = 1 Or request_page = 11 Then
'waitingページを表示する
'Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
sw.WriteLine("<!doctype html>")
sw.WriteLine("<html>")
sw.WriteLine("<head>")
sw.WriteLine("<title>Waiting " & num.ToString & "</title>")
sw.WriteLine("<meta http-equiv=""Content-Type"" content=""text/html; charset=shift_jis"" />")
sw.WriteLine("<meta http-equiv=""refresh"" content=""1 ; URL=ViewTV" & num.ToString & ".html"">")
sw.WriteLine("</head>")
sw.WriteLine("<body>")
If request_page = 1 Then
sw.WriteLine("配信準備中です..(" & check_m3u8_ts.ToString & ")")
log1write(num.ToString & ":配信準備中です")
ElseIf request_page = 11 Then
sw.WriteLine("配信されていません")
log1write(num.ToString & ":配信されていません")
End If
sw.WriteLine("<br><br>")
sw.WriteLine("<input type=""button"" value=""トップメニュー"" onClick=""location.href='index.html'"">")
sw.WriteLine("<br><br>")
sw.WriteLine("<input type=""button"" value=""直前のページへ戻る"" onClick=""history.go(-1);"">")
'sw.WriteLine("<input type=""button"" value=""地デジ番組表"" onClick=""location.href='TvProgram.html'"">")
sw.WriteLine("</body>")
sw.WriteLine("</html>")
'sw.Flush()
ElseIf request_page = 12 Then
'VLCはファイル再生未対応
'Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
sw.WriteLine(ERROR_PAGE("ファイル再生失敗", "VLCでのファイル再生には対応していません"))
'sw.Flush()
log1write(num.ToString & ":配信されていません")
ElseIf path.IndexOf(".htm") > 0 And File.Exists(path) Then
'ElseIf request_page >= 2 Then
'パラメーターを置換する必要があるページ
Dim s As String = ReadAllTexts(path)
'Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
'BonDriverと番組名連携選択
If s.IndexOf("%SELECTBONSIDCH") >= 0 Then
Dim gt() As String = get_atags("%SELECTBONSIDCH", s)
Dim selectbon As String = WEB_make_select_Bondriver_html(gt)
If selectbon.Length > 0 Then
s = s.Replace("%SELECTBONSIDCH" & gt(0) & "%", selectbon)
Else
s = s.Replace("%SELECTBONSIDCH" & gt(0) & "%", gt(4))
End If
End If
'Viewボタン作成
If s.IndexOf("%VIEWBUTTONS") >= 0 Then
Dim gt() As String = get_atags("%VIEWBUTTONS", s)
Dim viewbutton_html As String = WEB_make_ViewLink_html(gt)
If viewbutton_html.Length > 0 Then
s = s.Replace("%VIEWBUTTONS" & gt(0) & "%", viewbutton_html)
Else
s = s.Replace("%VIEWBUTTONS" & gt(0) & "%", gt(4))
End If
End If
'ストリーム番号
If s.IndexOf("%NUM%") >= 0 Then
s = s.Replace("%NUM%", num.ToString)
End If
'NHK音声モード
If s.IndexOf("%SELECTNHKMODE") >= 0 Then
Dim gt() As String = get_atags("%SELECTNHKMODE", s)
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
If Me._NHK_dual_mono_mode = 3 Then
Dim viewbutton_html As String = "<span id=""NHKVIEW"">" & WEB_make_NHKMODE_html(gt, num) & "</span>"
s = s.Replace("%SELECTNHKMODE" & gt(0) & "%", viewbutton_html)
Else
s = s.Replace("%SELECTNHKMODE" & gt(0) & "%", "<input type=""hidden"" name=""NHKMODE"" value=""" & Me._NHK_dual_mono_mode & """>")
End If
Else
s = s.Replace("%SELECTNHKMODE" & gt(0) & "%", gt(4))
End If
End If
'ViewTV.html用
If chk_viewtv_ok = 1 And num > 0 Then
'配信中ならば
'_listから取得resolutionを取得
Dim rez As String = Me._procMan.get_resolution(num)
Dim rezx As Integer = 0
Dim rezy As Integer = 0
Dim rez_hlsopt As Integer = 0
If rez.Length = 0 Then
'_listから取得できなければ_hlsOpt2から取得する
rez_hlsopt = 1
Dim ho As String = Me._hlsOpt2
Dim sp1, sp2 As Integer
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
Try
sp1 = ho.IndexOf("-s ")
sp2 = ho.IndexOf(" ", sp1 + 3)
rez = ho.Substring(sp1 + "-s ".Length, sp2 - sp1 - "-s ".Length)
Catch ex As Exception
rez = ""
End Try
ElseIf Me._hlsApp.IndexOf("vlc") >= 0 Then
Try
sp1 = ho.IndexOf("width=")
sp2 = ho.IndexOf(",", sp1)
rezx = ho.Substring(sp1 + "width=".Length, sp2 - sp1 - "width=".Length)
sp1 = ho.IndexOf("height=")
sp2 = ho.IndexOf(",", sp1)
rezy = ho.Substring(sp1 + "height=".Length, sp2 - sp1 - "height=".Length)
If rezx > 0 And rezy > 0 Then
rez = Trim(rezx) & "x" & Trim(rezy)
Else
rez = ""
End If
Catch ex As Exception
rez = ""
End Try
End If
End If
Dim d() As String = rez.Split("x")
If d.Length = 2 Then
If Val(d(0)) > 0 And Val(d(1)) > 0 Then
rezx = Val(d(0))
rezy = Val(d(1))
Else
rez = ""
End If
Else
rez = ""
End If
If rezx > 0 And rezy > 0 Then
s = s.Replace("%WIDTH%", rezx.ToString)
s = s.Replace("%HEIGHT%", rezy.ToString)
Else
'値がなければデフォルトをセット
s = s.Replace("%WIDTH%", "640")
s = s.Replace("%HEIGHT%", "360")
End If
'配信中ならばnumからBonDriver_pathとBonDriverを取得
If s.IndexOf("%SELECTCH") >= 0 Then
'%SELECTCHをhtmlに置換
Dim gt() As String = get_atags("%SELECTCH", s)
Dim vhtml As String
If rez_hlsopt = 0 Then
vhtml = replace_html_selectch(num, rez, gt, Me._NHK_dual_mono_mode)
Else
'hlsOptから解像度を取得した場合は値を渡さない(HLS_option.txtのオプションが使われてしまうため)
vhtml = replace_html_selectch(num, "", gt, Me._NHK_dual_mono_mode)
End If
If vhtml.Length > 0 Then
s = s.Replace("%SELECTCH" & gt(0) & "%", vhtml)
Else
s = s.Replace("%SELECTCH" & gt(0) & "%", gt(4))
End If
End If
End If
'%FILEROOT%変換
If s.IndexOf("%FILEROOT%") >= 0 Then
Dim fileroot As String = Me._fileroot
If Me._fileroot.Length = 0 Then
fileroot = Me._wwwroot
End If
'相対アドレスに変換
fileroot = fileroot.Replace(Me._wwwroot, "")
If fileroot.Length > 0 Then
'先頭が\なら削除
If fileroot.Substring(0, 1) = "\" Then
Try
fileroot = fileroot.Substring(1)
Catch ex As Exception
End Try
End If
fileroot = fileroot.Replace("\", "/")
fileroot &= "/"
End If
s = s.Replace("%FILEROOT%", fileroot)
End If
'ファイル選択ページ用
If request_page = 6 Then
Dim shtml As String = make_file_select_html()
s = s.Replace("%SELECTVIDEO%", shtml)
End If
'配信中簡易リスト
If s.IndexOf("%PROCBONLIST") >= 0 Then
Dim gt() As String = get_atags("%PROCBONLIST", s)
Dim js As String = Me._procMan.get_live_numbers_bon().Replace(vbCrLf, "<br>")
If js.Length > 0 Then
js = gt(1) & js & gt(3)
End If
If js.Length > 0 Then
s = s.Replace("%PROCBONLIST" & gt(0) & "%", js)
Else
s = s.Replace("%PROCBONLIST" & gt(0) & "%", gt(4))
End If
End If
'リダイレクト
If s.IndexOf("%REDIRECT%") >= 0 Then
If redirect.Length > 3 Then
'リダイレクト指定があれば
s = s.Replace("%REDIRECT%", "<meta http-equiv=""refresh"" content=""0 ; URL=" & redirect & """>")
Else
'無ければリダイレクト変数を消す
s = s.Replace("%REDIRECT%", "")
End If
End If
'地デジ番組表(通常のネットから取得)
If s.IndexOf("%TVPROGRAM-D%") >= 0 Then
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
s = s.Replace("%TVPROGRAM-D%", make_TVprogram_html_now(0, Me._NHK_dual_mono_mode))
Else
s = s.Replace("%TVPROGRAM-D%", make_TVprogram_html_now(0, -1))
End If
End If
'TvRock番組表
If s.IndexOf("%TVPROGRAM-TVROCK%") >= 0 Then
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
s = s.Replace("%TVPROGRAM-TVROCK%", make_TVprogram_html_now(999, Me._NHK_dual_mono_mode))
Else
s = s.Replace("%TVPROGRAM-TVROCK%", make_TVprogram_html_now(999, -1))
End If
End If
'TvRock番組表ボタン
If s.IndexOf("%TVPROGRAM-TVROCK-BUTTON") >= 0 Then
Dim gt() As String = get_atags("%TVPROGRAM-TVROCK-BUTTON", s)
If TvProgram_tvrock_url.Length > 0 Then
s = s.Replace("%TVPROGRAM-TVROCK-BUTTON" & gt(0) & "%", gt(1) & "<input type=""button"" value=""TvRock番組表"" onClick=""location.href='TvProgram_TvRock.html'"">") & gt(3)
Else
s = s.Replace("%TVPROGRAM-TVROCK-BUTTON" & gt(0) & "%", gt(4))
End If
End If
'EDCB番組表
If s.IndexOf("%TVPROGRAM-EDCB%") >= 0 Then
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
s = s.Replace("%TVPROGRAM-EDCB%", make_TVprogram_html_now(998, Me._NHK_dual_mono_mode))
Else
s = s.Replace("%TVPROGRAM-EDCB%", make_TVprogram_html_now(998, -1))
End If
End If
'EDCB番組表ボタン
If s.IndexOf("%TVPROGRAM-EDCB-BUTTON") >= 0 Then
Dim gt() As String = get_atags("%TVPROGRAM-EDCB-BUTTON", s)
If TvProgram_EDCB_url.Length > 0 Then
s = s.Replace("%TVPROGRAM-EDCB-BUTTON" & gt(0) & "%", gt(1) & "<input type=""button"" value=""EDCB番組表"" onClick=""location.href='TvProgram_EDCB.html'"">") & gt(3)
Else
s = s.Replace("%TVPROGRAM-EDCB-BUTTON" & gt(0) & "%", gt(4))
End If
End If
sw.WriteLine(s)
'sw.Flush()
log1write(path & "へのアクセスを受け付けました")
Else
'ローカルファイルが存在していない
'Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
sw.WriteLine(ERROR_PAGE("bad request", "ページが見つかりません"))
'sw.Flush()
log1write(path & "が見つかりませんでした")
End If
sw.Flush()
Else
'HTML以外なら
If File.Exists(path) Then
' ローカルファイルが存在すればレスポンス・ストリームに書き出す
'm3u8、tsへの要求はこちらへ来る
Dim content As Byte() = ReadAllBytes(path)
res.OutputStream.Write(content, 0, content.Length)
log1write(path & "へのアクセスを受け付けました")
Else
'ローカルファイルが存在していない
Dim sw As New StreamWriter(res.OutputStream, System.Text.Encoding.GetEncoding("shift_jis"))
sw.WriteLine(ERROR_PAGE("bad request", "ページが見つかりません"))
sw.Flush()
log1write(path & "が見つかりませんでした")
End If
End If
Else
'認証エラー
context.Response.StatusCode = 401
End If
res.Close()
Try
context.Response.Close()
Catch ex As Exception
' client closed connection before the content was sent
End Try
Catch httpEx As HttpListenerException
log1write(httpEx.Message)
log1write(httpEx.StackTrace)
End Try
End While
End Sub
'%変数に埋め込まれた前中後に挿入すべきhtmlタグを抽出
Private Function get_atags(ByVal tag As String, ByVal s As String) As Object
'tag="%~:" s=html
'返値 d(0)=抽出タグ文字列 d(1)=前 d(2)=中 d(3)=後 d(4)=要素がnothingだった場合に替わりに表示するタグ
Dim d() As String
ReDim Preserve d(4)
Dim vb1 As Integer = s.IndexOf(tag)
Dim vb2 As Integer = s.IndexOf("%", vb1 + 1)
Dim vbs As String = ""
If vb1 >= 0 And vb2 > vb1 Then
vbs = s.Substring(vb1 + tag.Length, vb2 - vb1 - tag.Length)
End If
Dim vbt() As String = vbs.Split(":")
d(0) = vbs
d(1) = ""
d(2) = ""
d(3) = ""
d(4) = ""
If vbt.Length = 2 Then
d(2) = vbt(1)
ElseIf vbt.Length = 3 Then
d(2) = vbt(1)
d(3) = vbt(2)
ElseIf vbt.Length = 4 Then
d(1) = vbt(1)
d(2) = vbt(2)
d(3) = vbt(3)
ElseIf vbt.Length = 5 Then
d(1) = vbt(1)
d(2) = vbt(2)
d(3) = vbt(3)
d(4) = vbt(4)
End If
Return d
End Function
'%SELECTCHをhtmlに置換して返す
Private Function replace_html_selectch(ByVal num As Integer, ByVal rez As String, ByVal atag() As String, ByVal NHKMODE As Integer) As String
Dim bon As String = Me._procMan.get_bondriver_name(num)
Dim bonp As String = Me._BonDriverPath
If bonp.Length = 0 Then
'指定が無い場合はUDPAPPと同じフォルダにあると見なす
bonp = filepath2path(Me._udpApp.ToString)
End If
Dim vhtml As String = WEB_search_ServiceID(bonp, bon, 1, num)
If vhtml.Length > 0 Then
vhtml = "<option value="""">---</option>" & vbCrLf & vhtml
vhtml = "<select name=""Bon_Sid_Ch"" id=""SEL2"" onChange=""changeSelect()"">" & vbCrLf & vhtml
vhtml = "<form action=""StartTV.html"">" & vbCrLf & vhtml
vhtml = atag(1) & vhtml
vhtml &= "</select>" & vbCrLf
vhtml &= atag(2)
'NHKかどうか調べる
'If Me._procMan.check_isNHK(num) = 1 Then
'NHKなら
If Me._hlsApp.IndexOf("ffmpeg") >= 0 Then
If NHKMODE = 3 Then
Dim atag2(3) As String
vhtml &= "<span id=""NHKVIEW"">" & WEB_make_NHKMODE_html(atag2, num) & "</span>"
Else
vhtml &= "<input type=""hidden"" name=""NHKMODE"" value=""" & NHKMODE & """>" & vbCrLf
End If
End If
'End If
vhtml &= "<input type=""submit"" value=""視聴"" />" & vbCrLf
vhtml &= "<input type=""hidden"" name=""num"" value=""" & num & """>" & vbCrLf
vhtml &= "<input type=""hidden"" name=""redirect"" value=""ViewTV" & num & ".html"">" & vbCrLf
If rez.Length > 0 Then
vhtml &= "<input type=""hidden"" name=""resolution"" value=""" & rez & """>" & vbCrLf
End If
vhtml &= "</form>" & vbCrLf
vhtml &= atag(3)
End If
Return vhtml
End Function
'ファイル再生ページ用 ビデオ選択htmlを作成する
Private Function make_file_select_html() As String
Dim shtml As String = ""
Dim i, k As Integer
If Me._videopath IsNot Nothing Then
If Me._videopath.Length > 0 Then
For i = 0 To Me._videopath.Length - 1
If Me._videopath(i).Length > 0 Then
Try
For Each stFilePath As String In System.IO.Directory.GetFiles(Me._videopath(i), "*.*") ', "*.ts")
Dim s As String = stFilePath & System.Environment.NewLine
s = trim8(s)
'フルパスファイル名がsに入る
Dim fullpath As String = s
Dim filename As String = ""
If fullpath.IndexOf("\") >= 0 Then
'ファイル名だけを取り出す
k = fullpath.LastIndexOf("\")
filename = fullpath.Substring(k + 1)
End If
filename = trim8(filename)
If filename.IndexOf(".db") < 0 Then
'なぜかそのまま渡すと返ってきたときに文字化けするのでURLエンコードしておく
fullpath = System.Web.HttpUtility.UrlEncode(fullpath)
shtml &= "<option value=""" & fullpath & """>" & filename & "</option>" & vbCrLf
End If
Next stFilePath
Catch ex As Exception
End Try
End If
Next
End If
End If
'If shtml.Length > 0 Then
shtml = "<option value="""">---</option>" & vbCrLf & shtml
shtml = "<select name=""VideoName"">" & vbCrLf & shtml
shtml &= "</select>" & vbCrLf
'End If
Return shtml
End Function
'エラーページ用ひな形
Public Function ERROR_PAGE(ByVal title As String, ByVal body As String, Optional ByVal a As Integer = 0) As String
Dim r As String = ""
r &= "<!doctype html>" & vbCrLf
r &= "<html>" & vbCrLf
r &= "<head>" & vbCrLf
r &= "<title>" & title & "</title>" & vbCrLf
r &= "<meta http-equiv=""Content-Type"" content=""text/html; charset=shift_jis"" />" & vbCrLf
r &= "</head>" & vbCrLf
r &= "<body>" & vbCrLf
r &= body & vbCrLf
r &= "<br><br>" & vbCrLf
r &= "<input type=""button"" value=""トップメニュー"" onClick=""location.href='index.html'"">" & vbCrLf
If a = 1 Then
r &= "<input type=""button"" Value=""再読み込み"" onClick=""location.reload();"">" & vbCrLf
End If
r &= "<br><br>" & vbCrLf
r &= "<input type=""button"" value=""直前のページへ戻る"" onClick=""history.go(-1);"">" & vbCrLf
r &= "</body>" & vbCrLf
r &= "</html>" & vbCrLf
Return r
End Function
'NHK音声選択用セレクト作成
Public Function WEB_make_NHKMODE_html(ByVal atag() As String, ByVal num As Integer) As String
Dim html As String = ""
Dim bst As String = ""
html &= atag(1)
html &= "<select name=""NHKMODE"">"
html &= vbCrLf & "<option value=""0"">主・副</option>" & vbCrLf
html &= "<option value=""1"">主</option>" & vbCrLf
html &= "<option value=""2"">副</option>" & vbCrLf
If BS1_hlsApp.Length > 0 Then
html &= "<option value=""9"">VLCで再生</option>" & vbCrLf
End If
html &= "</select>" & vbCrLf
html &= atag(3)
'現在放映中なら選択する
Dim NHKmode As Integer = Me._procMan.get_NHKmode(num)
If NHKmode >= 0 Then
html = html.Replace("value=""" & NHKmode.ToString & """", "value=""" & NHKmode.ToString & """" & " selected")
End If
Return html
End Function
'HTML内置換用 配信しているストリームのボタンを作成
Public Function WEB_make_ViewLink_html(ByVal atag() As String) As String
Dim html As String = ""
Dim bst As String = ""
Dim gln As String = Trim(Me._procMan.get_live_numbers())
If gln.Length > 0 Then
Dim d() As String = gln.Split(" ")
For i As Integer = 0 To d.Length - 1
Dim chkstr As String = ""
If d(i).IndexOf("x") >= 0 Then
chkstr = "[X]" '配信停止中
End If
d(i) = d(i).Replace("x", "")
If Val(d(i)) > 0 Then
html &= bst
Dim ChannelName As String = Me._procMan.get_channelname(Val(d(i)))
If ChannelName.Length > 20 Then
'長すぎるときはカット
ChannelName = ChannelName.Substring(0, 18) & ".."
End If
If ChannelName.Length > 0 Then
html &= "<input type=""button"" value=""" & chkstr & d(i) & " " & ChannelName & """ onClick=""location.href='ViewTV" & d(i).ToString & ".html'"">" & vbCrLf
Else
html &= "<input type=""button"" value=""ストリーム" & chkstr & d(i) & "を視聴"" onClick=""location.href='ViewTV" & d(i).ToString & ".html'"">" & vbCrLf
End If
'html &= "<form action=""ViewTV" & d(i).ToString & ".html"">" & vbCrLf
'html &= " <input type=""submit"" value=""ストリーム" & d(i).ToString & "を視聴"" />" & vbCrLf
'html &= "</form>" & vbCrLf
bst = atag(2)
End If
Next
End If
If html.Length > 0 Then
html = atag(1) & html & atag(3) & vbCrLf
End If
Return html
End Function
'HTML内置換用 BonDriverセレクトボックスを作成
Public Function WEB_make_select_Bondriver_html(ByVal atag() As String) As String
's=BonDriverセレクトと番組セレクトの間に入れるhtmlタグ <br>とか
Dim html As String = ""
Dim bons() As String = Nothing
Dim bons_n As Integer = 0
If html_selectbonsidch_a.Length = 0 And html_selectbonsidch_b.Length = 0 Then
'初めの1回 まだhtmlができていない
Dim bondriver_path As String = Me._BonDriverPath.ToString
If bondriver_path.Length = 0 Then
'指定が無い場合はUDPAPPと同じフォルダにあると見なす
bondriver_path = filepath2path(Me._udpApp.ToString)
End If
Try
For Each stFilePath As String In System.IO.Directory.GetFiles(bondriver_path, "*.dll")
Dim s As String = stFilePath & System.Environment.NewLine
'フルパスファイル名がsに入る
Dim fpf As String = trim8(s)
If s.IndexOf("\") >= 0 Then
'ファイル名だけを取り出す
Dim k As Integer = s.LastIndexOf("\")
s = trim8(s.Substring(k + 1))
End If
Dim sl As String = s.ToLower() '小文字に変換
'表示しないBonDriverかをチェック
If Me._BonDriver_NGword IsNot Nothing Then
For j As Integer = 0 To Me._BonDriver_NGword.Length - 1
If sl.IndexOf(Me._BonDriver_NGword(j)) >= 0 Then
sl = ""
End If
Next
End If
If sl.IndexOf("bondriver") = 0 Then
'セレクトボックス用にBonDriverを記録しておく
ReDim Preserve bons(bons_n)
bons(bons_n) = sl
bons_n += 1
End If
Next
Catch ex As Exception
End Try
Dim i As Integer = 0
If bons IsNot Nothing Then
If bons.Length > 0 Then
'BonDriver一覧
html_selectbonsidch_a &= "<script type=""text/javascript"" src=""ConnectedSelect.js""></script>" & vbCrLf
html_selectbonsidch_a &= "<select id=""SEL1"" name=""BonDriver"">" & vbCrLf
html_selectbonsidch_a &= "<option value="""">---</option>" & vbCrLf
For i = 0 To bons.Length - 1
html_selectbonsidch_a &= "<option value=""" & bons(i) & """>" & bons(i) & "</option>" & vbCrLf
Next
html_selectbonsidch_a &= "</select>" & vbCrLf
'各BonDriverに対応したチャンネルを書き込む
html_selectbonsidch_b &= "<select id=""SEL2"" name=""Bon_Sid_Ch"" onChange=""changeSelect()"">" & vbCrLf
html_selectbonsidch_b &= "<option value="""">---</option>" & vbCrLf
For i = 0 To bons.Length - 1
html_selectbonsidch_b &= "<optgroup label=""" & bons(i) & """>" & vbCrLf
'局名を書き込む
html_selectbonsidch_b &= WEB_search_ServiceID(bondriver_path, bons(i), 0)
html_selectbonsidch_b &= "</optgroup>" & vbCrLf
Next
html_selectbonsidch_b &= "</select>" & vbCrLf
html_selectbonsidch_b &= "<script type=""text/javascript"">" & vbCrLf
html_selectbonsidch_b &= "ConnectedSelect(['SEL1','SEL2']);" & vbCrLf
html_selectbonsidch_b &= "</script>" & vbCrLf
End If
End If
End If
html &= atag(1)
html &= html_selectbonsidch_a
html &= atag(2)
html &= html_selectbonsidch_b
html &= atag(3)
Return html
End Function
'HTML内置換用 番組選局セレクトボックスを作成(WEB_make_select_Bondriver_html補助)
Private Function WEB_search_ServiceID(ByVal bondriver_path As String, ByVal bondriver As String, ByVal BonDriverWrite As Integer, Optional ByVal num As Integer = 0) As String
Dim html As String = ""
If bondriver.Length > 0 Then
Dim k As Integer = -1
If BonDriver_select_html IsNot Nothing Then
If BonDriver_select_html.Length > 0 Then
k = Array.IndexOf(BonDriver_select_html, bondriver)
End If
End If
If k >= 0 Then
html = BonDriver_select_html(k).html
Else
'追加
Dim j As Integer = 0
If BonDriver_select_html IsNot Nothing Then
j = BonDriver_select_html.Length
End If
ReDim Preserve BonDriver_select_html(j)
'サービスIDと放送局名用
Dim si As Integer = 0
If ch_list IsNot Nothing Then
si = ch_list.Length
End If
Dim filename As String
If bondriver_path.Length > 0 Then
filename = bondriver_path & "\" & bondriver.Replace(".dll", ".ch2")
Else
filename = bondriver.Replace(".dll", ".ch2")
End If
Dim line() As String = file2line(filename)
If line IsNot Nothing Then
For i As Integer = 0 To line.Length - 1
If line(i).IndexOf(";") < 0 Then
Dim s() As String = line(i).Split(",")
If s.Length = 9 Then
'If BonDriverWrite = 1 Then
html &= "<option value=""" & bondriver & "," & s(5) & "," & s(1) & """>" & s(0) & "</option>" & vbCrLf
'Else
''Bondriverはすでに設定済みなので字数節約のため空白
'html &= "<option value="" ," & s(5) & "," & s(1) & """>" & s(0) & "</option>" & vbCrLf
'End If
'serviceIDと放送局名を記録しておく
If ch_list IsNot Nothing Then
Dim chk As Integer = 0