Advertisement
Guest User

Untitled

a guest
Dec 26th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using Newtonsoft.Json;
  7.  
  8. namespace SkyboxVR_Sorter
  9. {
  10. internal class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. Console.WriteLine("This program will sort all videos in SkyboxVR by download / file creation date.");
  15. Console.WriteLine("Optional: Use argument to supply the SkyboxVR cache file:\nSkyboxVRSorter.exe \"file_path_to_SkyboxVR_media.json\"");
  16. Console.WriteLine("press any key to continue...");
  17.  
  18. Console.ReadLine();
  19.  
  20. //string skyboxVrCacheFileLocation = @"C:\Users\tino\AppData\Roaming\SKYBOX\data\cache.dat";
  21. string skyboxVrCacheFileLocation = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SKYBOX\data\media.json";
  22.  
  23. if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
  24. {
  25. Console.WriteLine("Found provided argument.");
  26. skyboxVrCacheFileLocation = args[0];
  27. }
  28.  
  29. Console.WriteLine("");
  30. Console.WriteLine("Using Skybox VR cache: " + skyboxVrCacheFileLocation);
  31. Console.WriteLine("");
  32.  
  33. if (!File.Exists(skyboxVrCacheFileLocation))
  34. {
  35. Console.WriteLine("File does not exist: " + skyboxVrCacheFileLocation);
  36. Environment.Exit(0);
  37. }
  38.  
  39. File.SetAttributes(skyboxVrCacheFileLocation, FileAttributes.Normal);
  40. string cache = File.ReadAllText(skyboxVrCacheFileLocation);
  41. Root vrCache = JsonConvert.DeserializeObject<Root>(cache);
  42. Console.WriteLine("DeserializeObject cache successfull. Number of videos: " + vrCache.children.Count);
  43.  
  44. Console.WriteLine("Checking file attributes and changing json in memory ...");
  45. Console.WriteLine("0 %");
  46. int countVids = 0;
  47.  
  48. List<Child> children = FixTimeAddedForVideos(vrCache.children);
  49. vrCache.children = children;
  50.  
  51. Console.WriteLine("");
  52.  
  53. Console.WriteLine("Ready to write Skybox VR cache back to file.\n!!! CLOSE SKYBOX VR !!! and press Enter");
  54. Console.ReadLine();
  55. string newJsonCache = JsonConvert.SerializeObject(vrCache);
  56. File.WriteAllText(skyboxVrCacheFileLocation, newJsonCache);
  57. Console.WriteLine("Wrote json file.");
  58. Console.WriteLine("All done - have fun wanking!");
  59.  
  60. Console.ReadLine();
  61. }
  62.  
  63. public static int countVids = 0;
  64.  
  65. public static List<Child> FixTimeAddedForVideos(List<Child> children)
  66. {
  67. for (int i = 0; i < children.Count; i++)
  68. {
  69. Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
  70. Console.WriteLine(countVids+" videos done");
  71.  
  72. if (children[i].type == "Folder")
  73. {
  74. List<Child> folderChildren = FixTimeAddedForVideos(children[i].children);
  75. children[i].children = folderChildren;
  76. }
  77. else if (children[i].type == "Video")
  78. {
  79. long timeForFile = GetUnixTimeForFile(children[i].path);
  80. if(timeForFile > 0)
  81. {
  82. children[i].added_time = timeForFile;
  83. countVids++;
  84. }
  85. }
  86. else
  87. {
  88. Console.WriteLine("Error! Dont know the type " + children[i].type);
  89. }
  90. }
  91. return children;
  92. }
  93.  
  94. public static long GetUnixTimeForFile(string filePath)
  95. {
  96. try
  97. {
  98. string videoFilePath = filePath;
  99. if (!File.Exists(videoFilePath))
  100. {
  101. Console.WriteLine("Couldn't find/access video: " + videoFilePath);
  102. return -1;
  103. }
  104. DateTime creationTime = File.GetCreationTime(videoFilePath);
  105. long creationTimeUnix = Convert.ToInt64(DateTimeToUnixTimestamp(creationTime));
  106. return creationTimeUnix;
  107. }
  108. catch (Exception e)
  109. {
  110. Console.WriteLine(e);
  111. return -1;
  112. }
  113. }
  114.  
  115. public static DateTime UnixTimestampToDateTime(double unixTime)
  116. {
  117. DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
  118. long unixTimeStampInTicks = (long) (unixTime * TimeSpan.TicksPerSecond);
  119. return new DateTime(unixStart.Ticks + unixTimeStampInTicks, System.DateTimeKind.Utc);
  120. }
  121.  
  122. public static double DateTimeToUnixTimestamp(DateTime dateTime)
  123. {
  124. DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
  125. long unixTimeStampInTicks = (dateTime.ToUniversalTime() - unixStart).Ticks;
  126. return (double) unixTimeStampInTicks / TimeSpan.TicksPerSecond;
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement