Beispiel #1
0
        static void Main(string[] args)
        {
            if(args.Length < 1) return;
            string user = args[0];
            string broadcast = "";
            List<int> selectedVideos = new List<int>();
            bool downloadReplayOnly = false;
            bool isReverseOrder = false;

            var p = new OptionSet
            {
                {"b|broadcast=", "the name of broadcast.", v => broadcast = v},
                {"ds|downloadselected=", "only selected videos downloaded, seperate with comma (e.g. 1,2,7), start index is 0", v => selectedVideos = v.Split(',').Select(int.Parse).ToList()},
                {"ro|replayonly", "download only replay videos", v => downloadReplayOnly = v != null},
                {"r|reverse", "download reverse order", v => isReverseOrder = v != null}
            };

            p.Parse(args);
            if(string.IsNullOrEmpty(user)) return;
            bool downloadSingle = !string.IsNullOrEmpty(broadcast);
            bool downloadSelectedVideos = selectedVideos.Any();
            if(downloadSelectedVideos && downloadSingle) return;

            PDownload pDownload = new PDownload
            {
                User = user,
                Broadcast = broadcast,
                SelectedVideos = selectedVideos,
                DownloadLiveStream = !downloadReplayOnly,
                IsReverseOrder = isReverseOrder
            };
            using (VideoDownloader videoDownloader = new VideoDownloader())
            {
                if (downloadSingle)
                    videoDownloader.DownloadVideos(pDownload);
                else
                    videoDownloader.DownloadAllVideos(pDownload);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var periscopeApi = new PeriscopeApi();

            var loginTwitterRequest = new loginTwitterRequest
            {
            };
            var loginTwitter = periscopeApi.LoginTwitter(loginTwitterRequest);

            var userSearchRequest = new userSearchRequest
            {
                cookie = loginTwitter.cookie,
                search = args[0]
            };
            var userSearch = periscopeApi.UserSearch(userSearchRequest);

            var userBroadcastsRequest1 = new userBroadcastsRequest
            {
                cookie = loginTwitter.cookie,
                all = true,
                user_id = userSearch.First().id
            };
            var userBroadcasts = periscopeApi.UserBroadcasts(userBroadcastsRequest1);

            using (VideoDownloader videoDownloader = new VideoDownloader())
            {
                foreach (var userBroadcast in userBroadcasts)
                {
                    PDownload pDownload = new PDownload
                    {
                        User = userBroadcast.username,
                        Broadcast = userBroadcast.id,
                        DownloadLiveStream = true
                    };
                    videoDownloader.DownloadVideos(pDownload);
                }
            }
        }
        public void DownloadMultiple()
        {
            _localFileActions.CreateUserListFile();
            List<string> activeUsers = new List<string>();

            while (true)
            {
                try
                {
                    DateTime whileStart = DateTime.Now;
                    DateTime nextWhile = whileStart.AddMilliseconds(_settings.UserSettings.MultipleUserListCheckPeriod);

                    var users = _localFileActions.GetUsersFromFile();
                    var usersToCheck = users.Except(activeUsers);
                    Console.WriteLine("Total users: " + users.Count);

                    using (VideoDownloader videoDownloader = new VideoDownloader(_settings))
                    {
                        foreach (var userToCheck in usersToCheck)
                        {
                            var liveStreamBroadcasts = videoDownloader.GetBroadcasts(userToCheck).broadcasts.Where(b => b.IsLiveStream);
                            foreach (Broadcast liveStreamBroadcast in liveStreamBroadcasts)
                            {
                                _multipleUsersBroadcasts.Add(new MultipleUserBroadcast { Broadcast = liveStreamBroadcast });
                            }
                        }
                    }

                    var initialBroadcasts = _multipleUsersBroadcasts.Where(ub => ub.BroadcastStatus == EnumBroadcastStatus.Initial);
                    foreach (var initialBroadcast in initialBroadcasts)
                    {
                        initialBroadcast.BroadcastStatus = EnumBroadcastStatus.Downloading;
                        new Thread(() =>
                        {
                            using (VideoDownloader videoDownloader = new VideoDownloader(_settings))
                            {
                                videoDownloader.DownloadVideos(initialBroadcast.Broadcast);
                            }
                            initialBroadcast.BroadcastStatus = EnumBroadcastStatus.Finished;
                        }).Start();
                    }

                    activeUsers =
                     _multipleUsersBroadcasts.Where(ub => ub.BroadcastStatus == EnumBroadcastStatus.Downloading)
                         .Select(ub => ub.Broadcast.username)
                         .ToList();

                    Console.WriteLine("Active users: " + activeUsers.Count);

                    double totalTime = (DateTime.Now - whileStart).TotalMilliseconds;
                    Console.WriteLine("Total time: " + totalTime + " ms");

                    double waitTime = (nextWhile - DateTime.Now).TotalMilliseconds;
                    if (waitTime > 0)
                    {
                        Console.WriteLine("Wait time: " + waitTime + " ms");
                        Thread.Sleep((int)waitTime);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }