예제 #1
0
        public async Task DownloadLatest()
        {
            // This will download the new version and add it to "Versions" map
            log.LogInformation("Checking for new youtube-dl version...");
            await ytdlManager.DownloadLatestVersion();

            // Critical section - replace ytdl when nobody uses it
            var latest = ytdlManager.Versions.Keys.Max();

            if (CurrentVersion != latest)
            {
                log.LogInformation("New version found {0}!", CurrentVersion);
                using (var @lock = await ytdlLock.WriterLockAsync())
                {
                    // replace ytdl
                    CurrentVersion = ytdlManager.Versions.Keys.Max();
                    ytdl           = ytdlManager.Versions[CurrentVersion];
                    log.LogInformation("Update to {0} completed.", CurrentVersion);
                }
            }
            else
            {
                log.LogInformation("No new version found!");
            }

            // Delete old versions which are no longer required
            log.LogInformation("Cleaning up old youtube-dl versions...");
            await ytdlManager.CleanupOldVersions(2);
        }
예제 #2
0
        public async Task DownloadTest()
        {
            var manager = new YoutubeDLManager(loggerFactory)
            {
                StorePath = TestContext.TestDir
            };

            await manager.Initialize();

            Assert.AreEqual(0, manager.Versions.Count);

            // Download latest version, we don't have any version
            Assert.AreEqual(true, await manager.DownloadLatestVersion());
            Assert.AreEqual(1, manager.Versions.Count);

            // We already have the latest version, this should not do anything
            Assert.AreEqual(false, await manager.DownloadLatestVersion());
            Assert.AreEqual(1, manager.Versions.Count);

            await manager.CleanupOldVersions();

            Assert.AreEqual(1, manager.Versions.Count);
        }
예제 #3
0
        public async Task MultipleVersionsTest()
        {
            TestUtils.DeployEmbeddedResource("youtube-dl-2000", TestContext.TestRunDirectory);
            TestUtils.DeployEmbeddedResource("youtube-dl-2001", TestContext.TestRunDirectory);
            TestUtils.DeployEmbeddedResource("youtube-dl-2002", TestContext.TestRunDirectory);

            var manager = new YoutubeDLManager(loggerFactory)
            {
                StorePath = TestContext.TestRunDirectory
            };

            await manager.Initialize();

            Assert.AreEqual(3, manager.Versions.Count);

            Assert.AreEqual(true, await manager.DownloadLatestVersion());
            Assert.AreEqual(4, manager.Versions.Count);

            await manager.CleanupOldVersions();

            Assert.AreEqual(1, manager.Versions.Count);
            Assert.IsTrue(manager.Versions.First().Key.Major > 2002);
        }