예제 #1
0
파일: Video.cs 프로젝트: srdev78/libvideo
 public async Task <Stream> HeadAsync()
 {
     using (var client = new VideoClient())
     {
         return(await client
                .StreamAsync(this)
                .ConfigureAwait(false));
     }
 }
예제 #2
0
파일: Video.cs 프로젝트: srdev78/libvideo
 public async Task <byte[]> GetBytesAsync()
 {
     using (var client = new VideoClient())
     {
         return(await client
                .GetBytesAsync(this)
                .ConfigureAwait(false));
     }
 }
예제 #3
0
파일: Video.cs 프로젝트: AIBrain/libvideo
 /// <summary>
 /// Streams the contents of the video as an asynchronous operation.
 /// </summary>
 /// <returns>A Task to a stream representing the binary contents of this video.</returns>
 public async Task<Stream> StreamAsync()
 {
     using (var client = new VideoClient())
     {
         return await client
             .StreamAsync(this)
             .ConfigureAwait(false);
     }
 }
예제 #4
0
파일: Video.cs 프로젝트: AIBrain/libvideo
 /// <summary>
 /// Gets the byte array representing the video's file as an asynchronous operation.
 /// </summary>
 /// <returns>A Task returning the bytes of the video, which are generally saved into a file.</returns>
 public async Task<byte[]> GetBytesAsync()
 {
     using (var client = new VideoClient())
     {
         return await client
             .GetBytesAsync(this)
             .ConfigureAwait(false);
     }
 }
예제 #5
0
 private async Task <long?> GetContentLength(Query query)
 {
     if (query.TryGetValue("clen", out string clen))
     {
         return(long.Parse(clen));
     }
     using (var client = new VideoClient())
     {
         return(await client.GetContentLengthAsync(uri));
     }
 }
        /// <summary>
        /// Creates a new named pipe from a Youtube video link.
        /// </summary>
        /// <param name="youtubeUri">Uri to Youtube video file.</param>
        /// <param name="fileExtension">Video-file extension.</param>
        /// <param name="namedPipeName">Named pipe.</param>
        /// <param name="onProgress">Function executed when progress changes. Return true to cancel the operation, false to continue.</param>
        /// <returns>Pipe name.</returns>
        public static string NamedPipeFromYoutubeUri(this Uri youtubeUri, out string fileExtension, string namedPipeName = "youtubeVideoPipe", Func<float, bool> onProgress = null)
        {
            if (youtubeUri.Host != "www.youtube.com")
                throw new ArgumentException("The provided URI is not valid Youtube URI.");

            var youtubeVideo = YouTube.Default.GetVideo(youtubeUri.AbsoluteUri); 
            fileExtension = youtubeVideo.FileExtension;

            VideoClient vc = new VideoClient();
            Stream source = vc.Stream(youtubeVideo);
            
            return NamedPipeFromStreamAsync(source, namedPipeName, onProgress, () =>
            {
                source.Dispose();
                vc.Dispose();
            });
        }