Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using Newtonsoft.Json;
- namespace SkyboxVR_Sorter
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("This program will sort all videos in SkyboxVR by download / file creation date.");
- Console.WriteLine("Optional: Use argument to supply the SkyboxVR cache file:\nSkyboxVRSorter.exe \"file_path_to_SkyboxVR_media.json\"");
- Console.WriteLine("press any key to continue...");
- Console.ReadLine();
- //string skyboxVrCacheFileLocation = @"C:\Users\tino\AppData\Roaming\SKYBOX\data\cache.dat";
- string skyboxVrCacheFileLocation = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SKYBOX\data\media.json";
- if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
- {
- Console.WriteLine("Found provided argument.");
- skyboxVrCacheFileLocation = args[0];
- }
- Console.WriteLine("");
- Console.WriteLine("Using Skybox VR cache: " + skyboxVrCacheFileLocation);
- Console.WriteLine("");
- if (!File.Exists(skyboxVrCacheFileLocation))
- {
- Console.WriteLine("File does not exist: " + skyboxVrCacheFileLocation);
- Environment.Exit(0);
- }
- File.SetAttributes(skyboxVrCacheFileLocation, FileAttributes.Normal);
- string cache = File.ReadAllText(skyboxVrCacheFileLocation);
- Root vrCache = JsonConvert.DeserializeObject<Root>(cache);
- Console.WriteLine("DeserializeObject cache successfull. Number of videos: " + vrCache.children.Count);
- Console.WriteLine("Checking file attributes and changing json in memory ...");
- Console.WriteLine("0 %");
- int countVids = 0;
- List<Child> children = FixTimeAddedForVideos(vrCache.children);
- vrCache.children = children;
- Console.WriteLine("");
- Console.WriteLine("Ready to write Skybox VR cache back to file.\n!!! CLOSE SKYBOX VR !!! and press Enter");
- Console.ReadLine();
- string newJsonCache = JsonConvert.SerializeObject(vrCache);
- File.WriteAllText(skyboxVrCacheFileLocation, newJsonCache);
- Console.WriteLine("Wrote json file.");
- Console.WriteLine("All done - have fun wanking!");
- Console.ReadLine();
- }
- public static int countVids = 0;
- public static List<Child> FixTimeAddedForVideos(List<Child> children)
- {
- for (int i = 0; i < children.Count; i++)
- {
- Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
- Console.WriteLine(countVids+" videos done");
- if (children[i].type == "Folder")
- {
- List<Child> folderChildren = FixTimeAddedForVideos(children[i].children);
- children[i].children = folderChildren;
- }
- else if (children[i].type == "Video")
- {
- long timeForFile = GetUnixTimeForFile(children[i].path);
- if(timeForFile > 0)
- {
- children[i].added_time = timeForFile;
- countVids++;
- }
- }
- else
- {
- Console.WriteLine("Error! Dont know the type " + children[i].type);
- }
- }
- return children;
- }
- public static long GetUnixTimeForFile(string filePath)
- {
- try
- {
- string videoFilePath = filePath;
- if (!File.Exists(videoFilePath))
- {
- Console.WriteLine("Couldn't find/access video: " + videoFilePath);
- return -1;
- }
- DateTime creationTime = File.GetCreationTime(videoFilePath);
- long creationTimeUnix = Convert.ToInt64(DateTimeToUnixTimestamp(creationTime));
- return creationTimeUnix;
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- return -1;
- }
- }
- public static DateTime UnixTimestampToDateTime(double unixTime)
- {
- DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
- long unixTimeStampInTicks = (long) (unixTime * TimeSpan.TicksPerSecond);
- return new DateTime(unixStart.Ticks + unixTimeStampInTicks, System.DateTimeKind.Utc);
- }
- public static double DateTimeToUnixTimestamp(DateTime dateTime)
- {
- DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
- long unixTimeStampInTicks = (dateTime.ToUniversalTime() - unixStart).Ticks;
- return (double) unixTimeStampInTicks / TimeSpan.TicksPerSecond;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement