Ejemplo n.º 1
0
        /// <summary>
        ///     Prepare a downloadable object
        /// </summary>
        /// <param name="yubeItem"></param>
        /// <param name="videoCategory"></param>
        /// <returns></returns>
        public static YFileDownloadItem GetDownloadableItem(this VideoWrapper yubeItem, VideoCategory videoCategory)
        {
            var v = new YFileDownloadItem();

            v.Playlist    = videoCategory.Name;
            v.VideoId     = yubeItem.Id;
            v.Title       = yubeItem.Title;
            v.category_Id = videoCategory.EntityId;
            v.ThumpUrl    = yubeItem.DefaultThumbnailUrl;
            return(v);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Prepare a downloadable object
        /// </summary>
        /// <param name="ytubeItem"></param>
        /// <param name="videoCategory"></param>
        /// <returns></returns>
        public static YFileDownloadItem GetDownloadableItem(this VideoData ytubeItem)
        {
            var videoCategory = ControllerRepository.Db(x => x.GetVideoCategory(UserData.CurrentUser.EntityId, ytubeItem.Category_Id)).FirstOrDefault();

            if (ytubeItem.Video_Id.ToLower().Contains("youtube"))
            {
                ytubeItem.Video_Id = ytubeItem.Video_Id.Split('=').Last();
            }
            var v = new YFileDownloadItem();

            v.Playlist    = videoCategory?.Name;
            v.VideoId     = ytubeItem.Video_Id;
            v.Title       = ytubeItem.Title;
            v.category_Id = videoCategory?.EntityId;
            v.ThumpUrl    = ytubeItem.ThumpUrl;
            return(v);
        }
Ejemplo n.º 3
0
        public void DownloadVideo(YFileDownloadItem video)
        {
            if (!UserData.CanDownload())
            {
                Toast.MakeText(_context, "You dont have enough coins.", ToastLength.Long).Show();
            }

            var videos = ControllerRepository.Y(x => x.GetVideoAsync(video.VideoId, 18)).Await();

            if (!(videos?.Any() ?? false))
            {
                Toast.MakeText(_context, "Download unavailable", ToastLength.Long).Show();
                Logger?.Error($"Video [{video.VideoId}] unavailable");
                return;
            }

            if (!ObjectCacher.DownloadingFiles.ContainsKey(video.VideoId))
            {
                video.Auther      = videos.First().Auther;
                video.Duration    = videos.First().Duration;
                video.Description = videos.First().Description;
                video.Resolution  = videos.First().Resolution;
                video.Size        = videos.First().Size;
                video.FormatCode  = videos.First().FormatCode;
                video.Quality     = videos.First().Quality;
                ObjectCacher.DownloadingFiles.Add(video.VideoId, video);
                var intent = new Intent(_context, typeof(FileService));
                intent.PutExtra(FileService.URL, videos.FirstOrDefault()?.Url);
                intent.PutExtra(FileService.Title, video.Title);
                intent.PutExtra(FileService.DirectoryName, UserData.DirectoryManager.Folder(video.Playlist).Create().DirectoryPath);
                intent.PutExtra(FileService.FileName, video.GenerateLocalPath(videos.FirstOrDefault()));

                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    _context.StartForegroundService(intent);
                }
                else
                {
                    _context.StartService(intent);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Parse local path
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static YFileDownloadItem ParseLocalVideoPath(string url)
        {
            YFileDownloadItem res = null;
            var reg     = new Regex(@"\[(.*?)\]");
            var matches = reg.Matches(url);

            if (matches.Count >= 3) // [I=][F=18][P=]
            {
                res = new YFileDownloadItem
                {
                    VideoId = matches.Cast <Match>().FirstOrDefault()?.Value?.Replace("I=", "").Replace("[", "")
                              .Replace("]", ""),
                    category_Id = Convert.ToInt64(matches.Cast <Match>().LastOrDefault().Value?.Replace("P=", "")
                                                  .Replace("[", "").Replace("]", ""))
                };

                res.Title = url.Substring(url.LastIndexOf('/') + 1);
            }

            return(res);
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Generate localPath from YFileDownloadItem
 /// </summary>
 /// <param name="video"></param>
 /// <returns></returns>
 public static string GenerateLocalPath(this YFileDownloadItem video, YVideoInfo youtubeVideoInfo)
 {
     return
         ($"{video.Title.Replace("[", "{").Replace("]", "}")}[I={video.VideoId}][F={youtubeVideoInfo?.FormatCode ?? 18}][P={video.category_Id}].mp4");
 }