コード例 #1
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
        public bool RevokeAccess()
        {
            var result = AccountCommunication.RevokeAccess(ActiveAccount);

            ActiveAccount = null;

            if (File.Exists(accountJsonPath))
            {
                File.Delete(accountJsonPath);
            }

            DeleteLastJobFile();

            return(result);
        }
コード例 #2
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
        private void TryConnectAccount()
        {
            // Es muss sichergestellt sein, dass ein Account verbunden ist.
            for (int i = 0; i < 3 && ActiveAccount.Access?.AccessToken == null; i++)
            {
                for (int j = 0; j < 30 && i > 0; j++)
                {
                    Message = $"Verbindung zum Youtube-Account konnte nicht hergestellt werden. Erneuter Versuch in {30 - j} Sekunden...";
                    Thread.Sleep(1000);
                }

                Message       = $"Stelle Verbindung zum Youtube-Account her - Versuch {i + 1} von 3...";
                ActiveAccount = AccountCommunication.RefreshAccess(ActiveAccount);
            }
        }
コード例 #3
0
        public void GetVideoIdsForPlaylist(string rToken, string playlistId)
        {
            var acc = AccountCommunication.RefreshAccess(new Account()
            {
                Access = new Authentification()
                {
                    RefreshToken = rToken
                }
            });
            var videoIdList = WebService.GetPlaylistItems(acc.Access.AccessToken, playlistId);

            foreach (var videoId in videoIdList)
            {
                Trace.WriteLine(videoId);
            }
        }
コード例 #4
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
        public bool ConnectToAccount(string authToken, bool useLocalHostRedirect = true)
        {
            ActiveAccount = AccountCommunication.LoadAccountDetails(AccountCommunication.ConnectAccount(authToken, useLocalHostRedirect));

            if (!string.IsNullOrWhiteSpace(ActiveAccount.Access.RefreshToken))
            {
                // Account wurde erfolgreich verbunden -> Kategorien laden.
                ActiveAccount = AccountCommunication.FillAccountWithAvailableVideoCategories(ActiveAccount);
                WriteAccount();

                Languages = AccountCommunication.LoadYoutubeLanguages(ActiveAccount.Access.AccessToken).ToList();
                WriteLanguages();
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
        private void UploadJob(Job job)
        {
            if (!File.Exists(job.SelectedVideo.Path))
            {
                DeleteLastJobFile();
                return;
            }

            SaveCurrentJob(job);

            UploadCommunication.ProgressChanged += ReactToProgressChanged;
            while (!UploadCommunication.Upload(ref job, ref shouldCancel))
            {
                job.UploadingAccount = AccountCommunication.RefreshAccess(job.UploadingAccount);
            }

            UploadCommunication.ProgressChanged -= ReactToProgressChanged;

            if (!shouldCancel)
            {
                OnUploadFinished(job.SelectedVideo.Title);
                DeleteLastJobFile();

                // Datei umbenennen, damit der Uploader nicht erneut versucht, sie hochzuladen.
                var movedPath = Path.GetDirectoryName(job.SelectedVideo.Path)
                                + "\\_" + Path.GetFileNameWithoutExtension(job.SelectedVideo.Path).Remove(0, 1)
                                + Path.GetExtension(job.SelectedVideo.Path);

                try
                {
                    File.Move(job.SelectedVideo.Path, movedPath);
                }
                catch (IOException)
                {
                }
            }
        }
コード例 #6
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
 public string GetAuthLoginScreenUrl(bool showAuthToken, bool logout = false)
 {
     return(AccountCommunication.GetLogoffAndAuthUrl(showAuthToken, logout));
 }
コード例 #7
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
 private void RefreshAccess()
 {
     ActiveAccount = AccountCommunication.RefreshAccess(ActiveAccount);
 }
コード例 #8
0
ファイル: AutomationUploader.cs プロジェクト: StrohiZock/STFU
        public AutomationUploader()
        {
            if (!Directory.Exists("settings"))
            {
                Directory.CreateDirectory("settings");
            }

            if (File.Exists(templatesPath))
            {
                ReadTemplates();
                EnsureTemplateIdsAreUnique();
                EnsureTemplatesHaveCategory();
                EnsureTemplatesHaveLanguage();
            }

            EnsureStandardTemplateExists();

            if (File.Exists(accountJsonPath))
            {
                using (StreamReader reader = new StreamReader(accountJsonPath))
                {
                    string savedAccountJson = reader.ReadToEnd();
                    var    savedAccount     = JsonConvert.DeserializeObject <AccountJson>(savedAccountJson);

                    var categories = savedAccount.categories?.Select(c => new Category(c.id, c.title)).ToArray();
                    if (categories == null)
                    {
                        categories = new[] { Category.Default };
                    }

                    var region = savedAccount.region;
                    if (region == null)
                    {
                        region = "DE";
                    }

                    ActiveAccount = new Account()
                    {
                        Id = savedAccount.id, Title = savedAccount.title, Access = new Authentification()
                        {
                            RefreshToken = savedAccount.refreshToken
                        }, Region = savedAccount.region, AvailableCategories = categories
                    };

                    if (string.IsNullOrWhiteSpace(ActiveAccount?.Access?.AccessToken))
                    {
                        RefreshAccess();
                    }
                }
            }

            if (File.Exists(selectedPathsJsonPath))
            {
                try
                {
                    ReadPaths();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);

                    Paths = new PathSettings();
                    File.Delete(selectedPathsJsonPath);
                }
            }

            if (File.Exists(languagesPath))
            {
                try
                {
                    ReadLanguages();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);

                    Languages = new List <Language>(new Language[] { Language.Default });
                    File.Delete(languagesPath);
                }
            }
            else if (ActiveAccount != null && ActiveAccount.Access != null && ActiveAccount.Access.AccessToken != null)
            {
                Languages = AccountCommunication.LoadYoutubeLanguages(ActiveAccount.Access.AccessToken).ToList();

                WriteLanguages();
            }

            foreach (var path in Paths)
            {
                if (!Templates.Any(t => t.Id == path.SelectedTemplateId))
                {
                    path.SelectedTemplateId = 0;
                }
            }

            UnfinishedJob = LoadLastJob();
        }