video_tools.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. include("connectSQL_Component.php");
  3. require '../../vendor/autoload.php';
  4. $ffmpeg = FFMpeg\FFMpeg::create([
  5. 'ffmpeg.binaries' => 'C:\FFmpeg\bin\ffmpeg.exe',
  6. 'ffprobe.binaries' => 'C:\FFmpeg\bin\ffprobe.exe',
  7. ]);
  8. $GLOBALS["ffmpeg"] = $ffmpeg;
  9. $GLOBALS["conn"] = $conn;
  10. $root = '../../assets';
  11. $folder = 'videos';
  12. FindPath($root, $folder, $ffmpeg);
  13. sqlsrv_close($conn);
  14. function FindPath($root, $folder, $ffmpeg)
  15. {
  16. $rootPath = $root . '/' . $folder;
  17. $paths = array_diff(scandir($root . '/' . $folder), array('.', '..', 'Thumbs.db'));
  18. natsort($paths);
  19. echo ("<ul>");
  20. foreach ($paths as $path) {
  21. if (str_contains($path, '.')) {
  22. if (str_contains(strtolower($path), '.m3u8')) {
  23. if (!str_contains(strtolower($path), '_1080p.m3u8')) {
  24. echo ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
  25. $title = explode(".", $path)[0];
  26. $file_path = substr($rootPath, 4) . "/" . $path;
  27. $path = "title:" . $title . "path:" . $file_path . " dir_id:" . $folder;
  28. echo ($path);
  29. echo ("</li>");
  30. $sql = "BEGIN
  31. IF NOT EXISTS (SELECT * FROM [BIMComponents].[dbo].[Video_Table] WHERE [file_path] = '" . $file_path . "')
  32. BEGIN
  33. INSERT INTO [BIMComponents].[dbo].[Video_Table] ([title],[file_path],[file_name],[dir_name]) VALUES ('" . $title . "','" . $file_path . "','" . $title . "','" . $folder . "')
  34. END
  35. END";
  36. $fetchResult = sqlsrv_query($GLOBALS["conn"], $sql);
  37. }
  38. } else if (!str_contains(strtolower($path), '.gif') && !str_contains(strtolower($path), '.jpg') && !str_contains(strtolower($path), '.ts') && !str_contains(strtolower($path), '.mp4') && !str_contains(strtolower($path), '.wmv')) {
  39. echo ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
  40. $title = explode(".", $path)[0];
  41. $type = explode(".", $path)[1];
  42. $file_path = substr($rootPath, 4) . "/" . $path;
  43. $path = "title:" . $title . "path:" . $file_path . " dir_id:" . $folder;
  44. echo ($path);
  45. echo ("</li>");
  46. $sql = "BEGIN
  47. IF NOT EXISTS (SELECT * FROM [BIMComponents].[dbo].[file_Table] WHERE [file_path] = '" . $file_path . "')
  48. BEGIN
  49. INSERT INTO [BIMComponents].[dbo].[file_Table] ([title],[file_path],[file_name],[type],[dir_name]) VALUES ('" . $title . "','" . $file_path . "','" . $title . "','" . $type . "','" . $folder . "')
  50. END
  51. END";
  52. $fetchResult = sqlsrv_query($GLOBALS["conn"], $sql);
  53. }
  54. } else {
  55. echo ("<li>");
  56. echo ("dir_name: " . $path . "parent: " . $folder);
  57. $sql = "BEGIN
  58. IF NOT EXISTS (SELECT * FROM [BIMComponents].[dbo].[Video_Node] WHERE [dir_name] = 'videos')
  59. BEGIN
  60. INSERT INTO [BIMComponents].[dbo].[Video_Node] ([dir_name],[parent]) VALUES ('videos','.')
  61. END
  62. END";
  63. $fetchResult = sqlsrv_query($GLOBALS["conn"], $sql);
  64. $sql = "BEGIN
  65. IF NOT EXISTS (SELECT * FROM [BIMComponents].[dbo].[Video_Node] WHERE [dir_name] = '" . $path . "')
  66. BEGIN
  67. INSERT INTO [BIMComponents].[dbo].[Video_Node] ([dir_name],[parent]) VALUES ('" . $path . "','" . $folder . "')
  68. END
  69. END";
  70. $fetchResult = sqlsrv_query($GLOBALS["conn"], $sql);
  71. FindPath($rootPath, $path, $ffmpeg);
  72. echo ("</li>");
  73. }
  74. }
  75. echo ("</ul>");
  76. }