Esempio n. 1
0
        public async Task <IActionResult> MediaList(MediaFilter filter)
        {
            filter.UserId = User.Identity.GetNameIdGuid();
            MediaListViewModel mediaList = await _mediaListViewModelService.CreateViewModel(filter);

            return(View(mediaList));
        }
Esempio n. 2
0
 /// <summary>
 /// Asynchronously gets a media library by Media Filter
 /// </summary>
 /// <param name="filter">Media Filter</param>
 /// <returns>Media Item Array</returns>
 public async Task <MediaItem[]> GetMediaItemsAsync(MediaFilter filter)
 {
     return(await Task.Factory.FromAsync
            (
                WordPressService.BeginGetMediaLibrary(WordPressSiteConfig.BlogId, WordPressSiteConfig.Username,
                                                      WordPressSiteConfig.Password, filter),
                WordPressService.EndGetMediaLibrary
            ));
 }
Esempio n. 3
0
 public PhysicalMediaMovieSpecification(MediaFilter filter)
     : base(r => r.AppUserId == filter.UserId &&
            (filter.FilteredDiscTypeId.Count == 0 || filter.FilteredDiscTypeId.Contains(r.DiscTypeId)) &&
            (string.IsNullOrEmpty(filter.SearchTerm) || r.Title.ToLower().Contains(filter.SearchTerm.ToLower())) &&
            ((!filter.DigitalCopy && !filter.NoDigitalCopy) || (filter.DigitalCopy && filter.NoDigitalCopy) || r.DigitalCopy == filter.DigitalCopy) &&
            ((!filter.Watched && !filter.NotWatched) || (filter.Watched && filter.NotWatched) || r.Watched == filter.Watched))
 {
     if (filter.OrderBy == 1)
     {
         ApplyOrderBy(r => r.ReleaseDate);
         AddThenBy(r => r.Title);
     }
     else
     {
         ApplyOrderBy(r => r.Title);
         AddThenBy(r => r.ReleaseDate);
     }
 }
Esempio n. 4
0
        public async Task <MediaListViewModel> CreateViewModel(MediaFilter filter)
        {
            var media = await _physicalMediaRepository.ListAsync(new PhysicalMediaMovieSpecification(filter));

            var discTypes = await _discTypeRepository.ListAllAsync();

            var watched = await _watchedRepository.ListAllAsync();

            var genres = await _genreRepository.ListAllAsync();

            var viewModel = new MediaListViewModel
            {
                MediaType     = filter.MediaType,
                Filter        = filter,
                Genres        = genres.ToList(),
                DiscTypes     = discTypes.ToList(),
                PhysicalMedia = media.ToList()
            };

            //foreach (var item in viewModel.Media)
            //{
            //    item.DiscType = discTypes.SingleOrDefault(d => d.DiscTypeId == item.DiscTypeId);
            //    item.WatchedList = watched.Where(w => w.ImdbId == item.ImdbId).ToList();
            //}

            if (filter.FilteredGenreId != null && filter.FilteredGenreId.Count > 0)
            {
                var mediaGenres = await _mediaGenreRepository.ListAsync(new MediaGenreSpecification(filter.FilteredGenreId));

                var extraGenres = await _extraGenreRepository.ListAsync(new ExtraGenreSpecification(filter.FilteredGenreId));

                viewModel.PhysicalMedia = viewModel.PhysicalMedia.Where(m => (mediaGenres.Select(mg => mg.MediaId)).Contains(m.MediaId) ||
                                                                        (extraGenres.Select(mg => mg.PhysicalMediaId)).Contains(m.PhysicalMediaId)).ToList();
            }

            return(viewModel);
        }
Esempio n. 5
0
        public static bool ValidateFilters(MediaFilter mediaFilter)
        {
            if (mediaFilter.SkipMediaIfDescriptionContans && !(mediaFilter.DescriptionStrings.Count > 0))
            {
                return(false);
            }

            if (mediaFilter.SkipMediaLikes && !(mediaFilter.SkipMediaLikesCount > 0))
            {
                return(false);
            }

            if (mediaFilter.SkipMediaComments && !(mediaFilter.SkipMediaCommentsCount > 0))
            {
                return(false);
            }

            if (mediaFilter.SkipMediaVideoViews && !(mediaFilter.SkipMediaVideoViewsCount > 0))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public TenorClient(
            string apiKey,
            Locale locale               = null,
            AspectRatio arRange         = AspectRatio.all,
            ContentFilter contentFilter = ContentFilter.off,
            MediaFilter mediaFilter0    = MediaFilter.off,
            string anonId               = null,
            RestClient testClient       = null
            )
        {
            _locale = locale ?? DefaultLocale;
            _client = testClient ?? new RestClient(BaseUri);

            _arRange       = arRange;
            _contentFilter = contentFilter;
            _mediaFilter   = mediaFilter0;
            _apiKey        = apiKey;

            _anonId = anonId;

            _client = (RestClient)_client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);

            UpdateGeneralParams();
        }
Esempio n. 7
0
 /// <summary>
 /// Gets a media library by Media Filter
 /// </summary>
 /// <param name="filter">Media Filter</param>
 /// <returns>Media Item Array</returns>
 public MediaItem[] GetMediaItems(MediaFilter filter)
 {
     return(WordPressService.GetMediaLibrary(WordPressSiteConfig.BlogId, WordPressSiteConfig.Username,
                                             WordPressSiteConfig.Password, filter));
 }
Esempio n. 8
0
        /// <summary>
        /// Starts the download process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnStartDownloading_Click(object sender, EventArgs e)
        {
            // Input validation
            if (!InputValidation.ValidateWebSettings(txtUserAgent.Text, txtRequestTimeout.Text, txtProxy.Text, ':', txtThreads.Text))
            {
                return;
            }
            if (!InputValidation.ValidateDownloadSettings(txtDownloadFolder.Text, cbSaveStats.Checked, txtDelimiter.Text))
            {
                return;
            }

            if (lvInput.Items.Count == 0)
            {
                Log("No input found to download. Please enter at least one and try again.", nameof(LogType.Error));
                return;
            }

            if (!InputValidation.IsInt(txtThreads.Text))
            {
                Log("Invalid threads input. Fix your threads input and try again.", nameof(LogType.Error));
                return;
            }

            // Proxy initialization
            _proxy = new ProxyObject(txtProxy.Text, ':');

            // Filters initialization
            var descriptionStrings = new List <string>();

            descriptionStrings.AddRange(txtSkipDescriptionStrings.Lines);

            var mediaFilter = new MediaFilter
            {
                SkipTopPosts                  = cbSkipTopPosts.Checked,
                SkipMediaIfVideo              = cbSkipVideos.Checked,
                SkipMediaIfPhoto              = cbSkipPhotos.Checked,
                SkipMediaComments             = cbSkipMediaComments.Checked,
                SkipMediaCommentsMore         = cbSkipMediaCommentsMoreLess.Text == @"more",
                SkipMediaCommentsCount        = !String.IsNullOrEmpty(txtSkipMediaCommentsCount.Text) ? int.Parse(txtSkipMediaCommentsCount.Text) : 0,
                SkipMediaLikes                = cbSkipMediaLikes.Checked,
                SkipMediaLikesMore            = cbSkipMediaLikesMoreLess.Text == @"more",
                SkipMediaLikesCount           = !String.IsNullOrEmpty(txtSkipMediaLikesCount.Text) ? int.Parse(txtSkipMediaLikesCount.Text) : 0,
                SkipMediaIfDescriptionContans = cbSkipMediaDescription.Checked,
                DescriptionStrings            = descriptionStrings,
                SkipMediaUploadDateEnabled    = cbSkipMediaUploadDate.Checked,
                SkipMediaUploadDateNewer      = cbSkipMediaUploadDateMoreLess.Text == @"newer",
                SkipMediaUploadDate           = dtUploadTime.Value,
                //SkipMediaUploadDate = ((DateTimeOffset)dtUpladTime.Value).ToUnixTimeSeconds(),
                SkipMediaVideoViews      = cbSkipVideoViews.Checked,
                SkipMediaVideoViewsMore  = cbSkipVideoViewsMoreLess.Text == @"more",
                SkipMediaVideoViewsCount = !String.IsNullOrEmpty(txtSkipVideoViewsCount.Text) ? int.Parse(txtSkipVideoViewsCount.Text) : 0,
                CustomFolder             = cbCreateNewFolder.Checked,
                SaveStatsInCsvFile       = cbSaveStats.Checked
            };

            if (!InputValidation.ValidateFilters(mediaFilter))
            {
                Log("Error detected in the filters. Please check your filter settings and try again.", nameof(LogType.Error));
                return;
            }

            // Download process
            if (!InputValidation.IsDouble(txtRequestTimeout.Text))
            {
                return;
            }

            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken       = _cancellationTokenSource.Token;
            var requestTimeout = double.Parse(txtRequestTimeout.Text);

            // Initialize downloader object
            var downloader = new InstagramDownload(_instaApi, mediaFilter, txtUserAgent.Text, _proxy.GetWebProxy(), requestTimeout,
                                                   txtDownloadFolder.Text, _cancellationToken, txtDelimiter.Text)
            {
                IsTotalDownloadsEnabled = cbTotalDownloads.Checked
            };

            // Set downloader properties
            if (!string.IsNullOrEmpty(txtTotalDownloads.Text))
            {
                downloader.TotalDownloads = int.Parse(txtTotalDownloads.Text);
            }
            downloader.CustomFolder = cbCreateNewFolder.Checked;

            // Update form controls
            btnStartDownloading.Enabled = false;
            btnStopDownloading.Enabled  = true;

            // Upload logs
            Log(@"Started downloading...", nameof(LogType.Success));

            foreach (ListViewItem item in lvInput.Items)
            {
                try
                {
                    switch (item.SubItems[0].Text)
                    {
                    case "Url":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.Url, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;

                    case "MediaId":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.MediaId, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;

                    case "Username":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.Username, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;

                    case "UserId":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.UserId, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;

                    case "Hashtag":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.Hashtag, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;

                    case "Location":
                        try
                        {
                            await downloader.Download(item.SubItems[1].Text, InputType.Location, item.SubItems[2].Text);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Log(ex.Message, nameof(LogType.Error));
                        }

                        break;
                    }
                }
                catch (OperationCanceledException ex)
                {
                    Log(ex.Message, nameof(LogType.Error));
                }
            }

            btnStartDownloading.Enabled = true;
            btnStopDownloading.Enabled  = false;

            Log(@"Finished downloading...", nameof(LogType.Success));

            // Start all tasks
            //using (var semaphore = new SemaphoreSlim(int.Parse(txtThreads.Text)))
            //{
            //    var tasks = new List<Task>();
            //    foreach (ListViewItem item in lvInput.Items)
            //    {
            //        await semaphore.WaitAsync();

            //        try
            //        {
            //            tasks.Add(
            //                Task.Run(async () =>
            //                {
            //                    switch (item.SubItems[0].Text)
            //                    {
            //                        case "Url":
            //                            try
            //                            {
            //                                await downloader.Download(item.SubItems[1].Text, InputType.Url,
            //                                    mediaFilter);
            //                            }
            //                            catch (OperationCanceledException ex)
            //                            {
            //                                Log(ex.Message, nameof(LogType.Error));
            //                            }

            //                            break;
            //                        case "Username":
            //                            try
            //                            {
            //                                await downloader.Download(item.SubItems[1].Text, InputType.Username,
            //                                    mediaFilter, item.SubItems[2].Text);
            //                            }
            //                            catch (OperationCanceledException ex)
            //                            {
            //                                Log(ex.Message, nameof(LogType.Error));
            //                            }

            //                            break;
            //                        case "Hashtag":
            //                            try
            //                            {
            //                                await downloader.Download(item.SubItems[1].Text, InputType.Hashtag,
            //                                    mediaFilter, item.SubItems[2].Text);
            //                            }
            //                            catch (OperationCanceledException ex)
            //                            {
            //                                Log(ex.Message, nameof(LogType.Error));
            //                            }

            //                            break;
            //                        case "Location":
            //                            try
            //                            {
            //                                await downloader.Download(item.SubItems[1].Text, InputType.Location,
            //                                    mediaFilter, item.SubItems[2].Text);
            //                            }
            //                            catch (OperationCanceledException ex)
            //                            {
            //                                Log(ex.Message, nameof(LogType.Error));
            //                            }

            //                            break;
            //                    }
            //                }, _cancellationToken)
            //            );
            //        }
            //        catch (Exception ex)
            //        {
            //            Log(ex.Message, nameof(LogType.Error));
            //        }
            //        finally
            //        {
            //            semaphore.Release();
            //        }
            //    }

            //    // Wait for tasks to finish
            //    try
            //    {
            //        await Task.WhenAll(tasks); // might throw an exception if something goes wrong during tasks
            //    }
            //    catch (Exception ex)
            //    {
            //        Console.WriteLine(ex.StackTrace);
            //    }

            //    Log(@"Finished downloading.", nameof(LogType.Success));

            //    // Update form controls when tasks are finished
            //    btnStartDownloading.Enabled = true;
            //    btnStopDownloading.Enabled = false;
            //}
        }
Esempio n. 9
0
 public void SetMediaFilter(MediaFilter filter)
 {
     _mediaFilter = filter;
     UpdateGeneralParams();
 }