Exemplo n.º 1
0
        public static void RegisterStorageServices(this IAbstractDependencyInjector di, IHostingEnvironment env)
        {
            // Configure service types.
            di.AddPerThread <ILocalStorage>(provider => {
                var config     = provider.Resolve <IConfiguration>();
                var mlpath     = config["MediaStorage:Local:MediaLibraryPath"];
                var tempMlPath = config["MediaStorage:Local:TempLibraryPath"];

                if (mlpath.StartsWith("~"))
                {
                    mlpath = env.ContentRootPath + mlpath.Substring(1);
                }
                if (tempMlPath.StartsWith("~"))
                {
                    tempMlPath = env.ContentRootPath + tempMlPath.Substring(1);
                }
                return(new LocalStorage(mlpath));
            });

            di.AddPerThread <IStorage>(provider => {
                var config = provider.Resolve <IConfiguration>();
                return(GoogleDriveStorageFactory.Create(
                           config["MediaStorage:GoogleDrive:AppName"],
                           config["MediaStorage:GoogleDrive:ClientId"],
                           config["MediaStorage:GoogleDrive:ClientSecret"]));
            });
        }
Exemplo n.º 2
0
        public static void RegisterStorageServices(this IAbstractDependencyInjector di, IHostingEnvironment env)
        {
            // Configure service types.
            di.AddSingletone <IOuth2CodeSynchronizer, InProcessOuth2CodeSynchronizer>();

            di.AddPerThread <ILocalStorage>(provider => {
                var config     = provider.Resolve <IConfiguration>();
                var mlpath     = config["MediaStorage:Local:MediaLibraryPath"];
                var tempMlPath = config["MediaStorage:Local:TempLibraryPath"];

                if (mlpath.StartsWith("~"))
                {
                    mlpath = env.ContentRootPath + mlpath.Substring(1);
                }
                if (tempMlPath.StartsWith("~"))
                {
                    tempMlPath = env.ContentRootPath + tempMlPath.Substring(1);
                }
                return(new LocalStorage(mlpath));
            });

            di.AddPerThread <IStorage>(provider => {
                var config        = provider.Resolve <IConfiguration>();
                var accessToken   = config["MediaStorage:GoogleDrive:AccessToken"];
                var refreshoken   = config["MediaStorage:GoogleDrive:RefreshToken"];
                var appName       = config["MediaStorage:GoogleDrive:AppName"];
                var clientId      = config["MediaStorage:GoogleDrive:ClientId"];
                var clientSecret  = config["MediaStorage:GoogleDrive:ClientSecret"];
                string folderPath = config.GetValue <string>("MediaStorage:GoogleDrive:DataStoreFolder", string.Empty);
                bool isFullPath   = config.GetValue <bool>("DataStoreFolderIsFullPath", true);

                if (string.IsNullOrEmpty(accessToken))
                {
                    var gdriveStorage = GoogleDriveStorageFactory.Create(appName, clientId, clientSecret);
                    if (!string.IsNullOrEmpty(folderPath))
                    {
                        gdriveStorage.DataStoreFolder = folderPath;
                        gdriveStorage.IsFullPath      = isFullPath;
                    }

                    //gdriveStorage.AuthorizeRedirectUrl = config.GetValue<string>("MediaStorage:GoogleDrive:CodeReceiverUrl", string.Empty);
                    return(gdriveStorage);
                }
                else
                {
                    var gdriveStorage = GoogleDriveStorageFactory.CreateUsingAccessToken(appName, clientId, clientSecret, accessToken, refreshoken);
                    if (!string.IsNullOrEmpty(folderPath))
                    {
                        gdriveStorage.DataStoreFolder = folderPath;
                        gdriveStorage.IsFullPath      = isFullPath;
                    }
                    return(gdriveStorage);
                }
            });
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string mp3FilePath = args[0];

            var sw = new Stopwatch();

            sw.Start();

            string stateJsonInit = string.Empty;

            // Read json state.
            using (var fs = File.OpenRead($"{mp3FilePath}.json"))
            {
                byte[] arrJson = new byte[fs.Length];
                fs.Read(arrJson, 0, arrJson.Length);
                stateJsonInit = System.Text.ASCIIEncoding.UTF8.GetString(arrJson, 0, arrJson.Length);
            }

            using (IStorage storage = GoogleDriveStorageFactory.Create("", "", ""))
            //using(IStorage storage = new LocalStorage(""))
            {
                using (var file = storage.Open("/Wovenwar/Honor is Dead/World on Fire.mp3"))
                //using(var file = storage.Open("World on Fire.mp3"))
                {
                    using (var encoder = MediaEncoderExtension.EncoderByMediaType("mp3"))
                    {
                        if (encoder.Init(file, false, stateJsonInit))
                        {
                            var packets = encoder.ReadPackets(100, 50);

                            // // Save state json
                            // string stateJson;
                            // encoder.SaveStateIntoJson(true, out stateJson);

                            // // Save json state.
                            // using(var fs = File.OpenWrite($"{mp3FilePath}.json"))
                            // {
                            //     byte[] arrJson = System.Text.ASCIIEncoding.UTF8.GetBytes(stateJson);
                            //     fs.Write(arrJson, 0, arrJson.Length);
                            // }

                            sw.Stop();

                            Console.WriteLine($"Elapsed {sw.ElapsedMilliseconds}ms");
                        }
                    }
                }
            }
        }