Exemplo n.º 1
0
        public async Task <IEnumerable <RecordedVideo> > GetAllVideosListAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            var loginResponse = await this.LoginAsync();

            var client  = GetHttpClient(loginResponse);
            var urlBase = GetUrlBase(loginResponse);
            var page    = 1;
            var videos  = new List <RecordedVideo>();

            while (true)
            {
                using (var response =
                           await client.GetAsync(
                               $"{urlBase}/api/v2/videos/changed?since=2016-01-01T23:11:21+0000&page={page++}", cancelToken))
                {
                    response.EnsureSuccessStatusCode();
                    var responseContents = await response.Content.ReadAsStringAsync();

                    var videosList = RecordedVideo.GetVideoList(responseContents).ToList();
                    this.logger.LogInformation($"Found {videosList.Count} videos.");
                    if (!videosList.Any())
                    {
                        break;
                    }

                    videos.AddRange(videosList);
                }
            }
            this.logger.LogInformation($"Found a total of {videos.Count} videos.");
            return(videos);
        }
        private void SendVideo(RecordedVideo recorderVideo)
        {
            if (recorderVideo == null)
            {
                return;
            }

            long size = 0;

            using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = storage.OpenFile(recorderVideo.FileName, FileMode.Open, FileAccess.Read))
                {
                    size = file.Length;
                }
            }

            long photoSize = 0;

            using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = storage.OpenFile(recorderVideo.FileName + ".jpg", FileMode.Open, FileAccess.Read))
                {
                    photoSize = file.Length;
                }
            }

            var volumeId = TLLong.Random();
            var localId  = TLInt.Random();
            var secret   = TLLong.Random();

            var thumbLocation = new TLFileLocation //TODO: replace with TLFileLocationUnavailable
            {
                DCId     = new TLInt(0),
                VolumeId = volumeId,
                LocalId  = localId,
                Secret   = secret,
            };

            var fileName = String.Format("{0}_{1}_{2}.jpg",
                                         thumbLocation.VolumeId,
                                         thumbLocation.LocalId,
                                         thumbLocation.Secret);

            // заменяем имя на стандартное для всех каритинок
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                store.CopyFile(recorderVideo.FileName + ".jpg", fileName, true);
                store.DeleteFile(recorderVideo.FileName + ".jpg");
            }

            var thumbSize = new TLPhotoSize
            {
                W        = new TLInt(640),
                H        = new TLInt(480),
                Size     = new TLInt((int)photoSize),
                Type     = new TLString(""),
                Location = thumbLocation,
            };

            var documentAttributeVideo = new TLDocumentAttributeVideo
            {
                Duration = new TLInt((int)recorderVideo.Duration),
                W        = new TLInt(640),
                H        = new TLInt(480)
            };

            var document = new TLDocument54
            {
                Id         = new TLLong(0),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                MimeType   = new TLString("video/mp4"),
                Size       = new TLInt((int)size),
                Thumb      = thumbSize,
                DCId       = new TLInt(0),
                Version    = new TLInt(0),
                Attributes = new TLVector <TLDocumentAttributeBase> {
                    documentAttributeVideo
                }
            };

            var media = new TLMessageMediaDocument75
            {
                Flags       = new TLInt(0),
                FileId      = recorderVideo.FileId ?? TLLong.Random(),
                Document    = document,
                IsoFileName = recorderVideo.FileName,
                Caption     = TLString.Empty
            };

            var message = GetMessage(TLString.Empty, media);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && (_messages == null || _messages.Count == 0) && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      m => SendVideoInternal(message, null)));
            });
        }