Exemple #1
0
 private async void FillEntriesUser(EntriesReady onEntriesReady, MSYoutubeLoading onYoutubeLoading)
 {
     var youtubeUrl = YoutubeUrl;
     var request = new MSYoutubeRequest(_settings);
     var uri = new Uri(String.Format("https://gdata.youtube.com/feeds/api/users/{0}/playlists?v=2", youtubeUrl.UserId));
     var items = await request.GetAsync(YoutubeUrl, uri, onYoutubeLoading);
     if (items == null) return;
     Entries = new ObservableCollection<Feed>();
     try {
         if (!String.IsNullOrEmpty(items.AuthorId)) {
             var favoritesEntry = new YoutubeEntry(this) {
                 Title = "Favorite Videos",
                 Uri = new Uri("http://www.youtube.com/playlist?list=FL" + items.AuthorId),
             };
             Entries.Add(favoritesEntry);
         }
         foreach (var member in items.Entries) {
             var entry = new YoutubeEntry(this) {
                 Title = member.Title,
                 Uri = member.Uri,
                 Description = member.Description
             };
             Entries.Add(entry);
         }
     } catch {
         Entries.Clear();
     }
     if (onEntriesReady != null) onEntriesReady(Entries);
 }
Exemple #2
0
 private YoutubeEntry(YoutubeEntry parent = null)
 {
     Parent = parent;
     _settings = new MSYoutubeSettings( "MS.Youtube.Downloader", "AI39si76x-DO4bui7H1o0P6x8iLHPBvQ24exnPiM8McsJhVW_pnCWXOXAa1D8-ymj0Bm07XrtRqxBC7veH6flVIYM7krs36kQg" ) {AutoPaging = true, PageSize = 50};
 }
Exemple #3
0
 public YoutubeEntry Clone()
 {
     var entry = new YoutubeEntry {
         Title = Title,
         BaseFolder = BaseFolder,
         Parent = Parent,
         Description = Description,
         DownloadFolder = DownloadFolder,
         ProviderFolder = ProviderFolder,
         MediaType = MediaType,
         ThumbnailUrl = ThumbnailUrl,
         Uri = Uri,
         VideoExtension = VideoExtension,
         VideoFolder = VideoFolder,
         ExecutionStatus = ExecutionStatus
     };
     if (entry.ExecutionStatus == ExecutionStatus.Deleted) entry.DownloadState = DownloadState.Deleted;
     if (ThumbnailUrls != null && ThumbnailUrls.Length > 0) {
         entry.ThumbnailUrls = new string[ThumbnailUrls.Length];
         for (var i = 0; i < ThumbnailUrls.Length; i++)
             entry.ThumbnailUrls[i] = ThumbnailUrls[i];
     }
     return entry;
 }
Exemple #4
0
 public static YoutubeEntry Create(Uri uri, YoutubeEntry parent = null)
 {
     var entry = new YoutubeEntry(parent);
     if (uri != null) 
         entry.Uri = uri;
     return entry;
 }
Exemple #5
0
 private static async Task AddToFile(YoutubeEntry entry, Uri uri, Stream destinationStream, long? start, long? stop, MSYoutubeLoading onYoutubeLoading)
 {
     if (entry.ExecutionStatus != ExecutionStatus.Normal) return;
     var response = await DownloadToStreamAsync(uri, start, stop);
     if (response.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable) return;
     var range = GetRange(response);
     var total =  range.Length; // (response.Headers.ContentRange.Length ?? 0);
     var to = range.To; // (response.Headers.ContentRange.To ?? 0);
     using (var stream = response.GetResponseStream()) {
         if (stream == null) return;
         await stream.CopyToAsync(destinationStream);
         await destinationStream.FlushAsync();
         if (onYoutubeLoading != null && entry.ExecutionStatus == ExecutionStatus.Normal) onYoutubeLoading(to, total);
         if (total > to + 1)
             await AddToFile(entry, uri, destinationStream, to + 1, to + BlockSize, onYoutubeLoading);
     }
 }
Exemple #6
0
 public static async Task DownloadToFileAsync(YoutubeEntry entry, Uri uri, StorageFolder folder, string fileName, MSYoutubeLoading onYoutubeLoading)
 {
     if (entry.ExecutionStatus != ExecutionStatus.Normal) return;
     var storageFile = GetFile(folder, fileName);
     using (var destinationStream = storageFile.OpenStreamForWriteAsync()) {
         if (destinationStream == null) return;
         //var properties = await storageFile.GetBasicPropertiesAsync();
         var start = destinationStream.Length; // (long)properties.Size;
         destinationStream.Position = destinationStream.Length;
         await AddToFile(entry, uri, destinationStream, start, start + BlockSize - 1, onYoutubeLoading);
     }
 }
Exemple #7
0
 public AudioConverter(YoutubeEntry youtubeEntry, EntryDownloadStatusEventHandler onEntryDownloadStatusChange)
 {
     _youtubeEntry = youtubeEntry;
     _onEntryDownloadStatusChange = onEntryDownloadStatusChange;
     _applicationPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
 }
 private void GetItems(SelectionMode mode = SelectionMode.Multiple)
 {
     _playlist = YoutubeEntry.Create(_youtubeUrl.Uri);
     _playlist.GetEntries(OnEntriesReady, OnYoutubeLoading);
 }
Exemple #9
0
 private void UpdateStatus(DownloadState state, YoutubeEntry entry, double percentage)
 {
     DownloadState = state;
     Percentage = percentage;
     if (OnListDownloadStatusChange != null) OnListDownloadStatusChange(this, entry, DownloadState, Percentage);
 }