Пример #1
0
 public void SaveDownloadLists(DownloadLists lists)
 {
     try {
         var listsEntry = new DownloadEntry {Title = lists.Title, ThumbnailUrl = lists.ThumbnailUrl, ExecutionStatus = lists.ExecutionStatus };
         foreach (DownloadList list in lists.Entries) {
             if (list.DownloadState == DownloadState.AllFinished || list.Entries.Count <= 0) continue;
             var entry = new DownloadEntry {
                 Title = list.Title,
                 ThumbnailUrl = list.ThumbnailUrl,
                 MediaType = list.MediaType,
                 ExecutionStatus = list.ExecutionStatus,
                 Url = ""
             };
             var firstEntry = list.Entries[0] as YoutubeEntry;
             if (firstEntry == null) continue;
             if (firstEntry.Parent != null) {
                 entry.Url = String.Format("{0}", firstEntry.Parent.Uri);
                 entry.Title = firstEntry.Parent.Title;
             }
             foreach (YoutubeEntry youtubeEntry in list.Entries)
                 entry.List.Add(new DownloadEntry {
                     Title = youtubeEntry.Title,
                     Url = youtubeEntry.Uri.ToString(),
                     MediaType = youtubeEntry.MediaType,
                     ThumbnailUrl = youtubeEntry.ThumbnailUrl,
                     ExecutionStatus = youtubeEntry.ExecutionStatus
                 });
             listsEntry.List.Add(entry);
         }
         using (var file = new StreamWriter(_downloadsFile)) file.Write(JsonConvert.SerializeObject(listsEntry));
     }
     catch {}
 }
 public MainWindow()
 {
     InitializeComponent();
     _settings = new LocalService();
     Title = "MS.Video.Downloader ver. " + _settings.Version;
     Lists = new DownloadLists(_settings, OnDownloadStatusChange);
     Loading(false);
 }
Пример #3
0
 public bool FillDownloadLists(DownloadLists lists)
 {
     try {
         lists.Entries.Clear();
         DownloadEntry listsEntry;
         if (!File.Exists(_downloadsFile))
             listsEntry = new DownloadEntry();
         else
             using (var file = new StreamReader(_downloadsFile))
                 listsEntry = JsonConvert.DeserializeObject<DownloadEntry>(file.ReadToEnd());
         if (listsEntry.List != null && listsEntry.List.Count > 0) {
             foreach (var itemList in listsEntry.List) {
                 var youtubeEntries = new List<YoutubeEntry>();
                 var mediaType = itemList.MediaType;
                 Uri uri;
                 var youtubeListEntry =
                     YoutubeEntry.Create(Uri.TryCreate(itemList.Url, UriKind.Absolute, out uri) ? uri : null);
                 youtubeListEntry.Title = itemList.Title;
                 SetExecutionStatus(youtubeListEntry, itemList);
                 youtubeListEntry.ThumbnailUrl = itemList.ThumbnailUrl;
                 foreach (var item in itemList.List) {
                     var youtubeEntry = YoutubeEntry.Create(new Uri(item.Url), youtubeListEntry);
                     youtubeEntry.ThumbnailUrl = item.ThumbnailUrl;
                     youtubeEntry.Title = item.Title;
                     SetExecutionStatus(youtubeEntry, item);
                     youtubeEntries.Add(youtubeEntry);
                 }
                 if (youtubeEntries.Count > 0)
                     lists.SoftAdd(youtubeEntries, mediaType);
             }
         }
         return true;
     }
     catch {
         return false;
     }
 }