Пример #1
0
        /// <summary>
        /// Get information about a single video.
        /// </summary>
        /// <param name="id">ID of the video to get information for.</param>
        public Database.Types.Video Single(string id)
        {
            try {
                // https://developers.google.com/youtube/v3/docs/videos/list
                API.VideosResource.ListRequest videoSearch = APIService.Videos.List("id,snippet,contentDetails.duration");
                videoSearch.Id          = id;
                videoSearch.MaxResults  = 1;
                videoSearch.PrettyPrint = false;

                API.Data.Video response = videoSearch.Execute().Items[0];

                Database.Types.Video video = new Database.Types.Video {
                    ID           = response.Id,
                    ChannelID    = response.Snippet.ChannelId,
                    Title        = response.Snippet.Title,
                    Description  = response.Snippet.Description,
                    Duration     = TimeSpanUtils.ConvertDuration(response.ContentDetails.Duration),
                    Posted       = DateTime.Parse(response.Snippet.PublishedAt),
                    ThumbnailURL = GetBestThumbnail(response.Snippet.Thumbnails),
                    WatchStatus  = WatchStatus.Unwatched
                };

                LoggingManager.Log.Info($"Information processed for '{video.ID}' posted by '{video.ChannelID}'.");
                return(video);
            } catch (Exception ex) {
                LoggingManager.Log.Error(ex, $"Failed to get information for '{id}'.");
                return(null);
            }
        }
Пример #2
0
        public int splitByChapter(FileInfo file, Google.Apis.YouTube.v3.Data.Video video)
        {
            Search.Youtube yt       = new Search.Youtube();
            List <string>  chapters = yt.getChapters(video).Result;
            var            stamps   = yt.chapterStamps;

            var outputFolder = Path.GetDirectoryName(file.FullName) + $"\\{Path.GetFileNameWithoutExtension(file.FullName)}";

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            for (int i = 1; i <= stamps.Count; i++)
            {
                string outputFile = outputFolder + $"\\{i} - {chapters[i - 1].Replace(chapters[i - 1].Split(' ')[0], "").Replace(".", "-").Replace(":", "").Trim()}.mp3";
                outputFile = outputFile.Replace("- - ", "- ");

                if (i == stamps.Count)
                {
                    try
                    {
                        split(file.FullName, stamps[i - 1], outputFile);
                    }
                    catch { }
                }
                else
                {
                    split(file.FullName, stamps[i - 1], stamps[i], outputFile);
                }
            }


            return(0);
        }
Пример #3
0
 public VideoDownload(Google.Apis.YouTube.v3.Data.Video vid, string videoTitle, bool autoCrop = false, bool splitByChapter = false)
 {
     video         = vid;
     title         = videoTitle;
     acrop         = autoCrop;
     splitChapters = splitByChapter;
 }
Пример #4
0
 public Video(YouTubeSession session, Google.Apis.YouTube.v3.Data.Video original = null)
 {
     youTubeSession = new WeakReference <YouTubeSession> (session);
     this.Original  = original ?? new Google.Apis.YouTube.v3.Data.Video()
     {
         Snippet = new Google.Apis.YouTube.v3.Data.VideoSnippet(),
         Status  = new Google.Apis.YouTube.v3.Data.VideoStatus()
     };
 }
Пример #5
0
        /// <summary>
        /// Processes the found metadata into the Movie entity.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="result"></param>
        /// <param name="preferredLanguage"></param>
        public void ProcessResult(Video item, Google.Apis.YouTube.v3.Data.Video result)
        {
            item.Name     = result.Snippet.Title;
            item.Overview = result.Snippet.Description;
            var date = DateTime.Parse(result.Snippet.PublishedAtRaw);

            item.ProductionYear = date.Year;
            item.PremiereDate   = date;
        }
Пример #6
0
        internal YouTubeUploadRequest(string FileName,
                                      YouTubeService YouTubeService,
                                      VideoYT Video)
        {
            _dataStream         = new FileStream(FileName, FileMode.Open);
            _videoInsertRequest = YouTubeService.Videos.Insert(Video, "snippet,status", _dataStream, "video/*");

            _videoInsertRequest.ProgressChanged  += VideosInsertRequest_ProgressChanged;
            _videoInsertRequest.ResponseReceived += VideosInsertRequest_ResponseReceived;
        }
Пример #7
0
        public async void Dl_StandardOutputEvent(object sender, string e)
        {
            logs.Add(e);

            if (e.Contains("Downloading webpage") && e.Contains("[youtube]"))
            {
                string id = e.Split(':')[0].Split(' ')[1];
                impLogs.Add(id);
                Google.Apis.YouTube.v3.Data.Video vid = await youtube.byId(id);

                bool acrop = (vid != null && await youtube.isMusic(vid));
                bool split = await youtube.hasChapters(vid);

                downloadedMusic.Add(new VideoDownload(vid, vid.Snippet.Title + ".mp3", acrop, split));
            }
            if (e.Contains("[ffmpeg] Destination: "))
            {
                impLogs.Add(e.Split(":".ToCharArray(), count: 2)[1].Trim());
            }
        }
Пример #8
0
 void VideosInsertRequest_ResponseReceived(VideoYT Video)
 {
     Uploaded?.Invoke($"https://youtube.com/watch?v={Video.Id}");
 }
Пример #9
0
        private Video ParseVideo(Google.Apis.YouTube.v3.Data.Video item, int number, int count)
        {
            DateTime time = DateTime.Parse(item.Snippet.PublishedAt, null, System.Globalization.DateTimeStyles.RoundtripKind);

            Video newVideo = new Video()
            {
                Id = item.Id,

                PublishedAt = time,

                PublishedAtString = time.Day + "." + time.Month + "." + time.Year + " " + time.Hour + ":" + ((time.Minute < 10) ? ("0" + time.Minute) : (time.Minute + "")),

                ChannelId = item.Snippet.ChannelId,

                ChannelName = "",

                ChannelTitle = item.Snippet.ChannelTitle,

                ChannelPicUrl = "",

                Title = item.Snippet.Title,

                ThumbnailUrl = item.Snippet.Thumbnails.Medium.Url,

                New = true,

                List = number,

                Index = count,

                Description = item.Snippet.Description
            };

            if (number == 0)
            {
                using (AppDbContext context = new AppDbContext())
                {
                    Channel ch = context.Channels.Where(c => c.Id == item.Snippet.ChannelId).FirstOrDefault();

                    if (ch != null)
                    {
                        newVideo.ChannelName = ch.Username;

                        newVideo.ChannelPicUrl = ch.ThumbnailUrl;
                    }
                }
            }

            string hour, min;

            if (item.ContentDetails.Duration.Contains('H'))
            {
                hour = Regex.Match(item.ContentDetails.Duration.Split('H')[0], @"(.{2})\s*$").Value;
            }
            else
            {
                hour = "";
            }

            if (item.ContentDetails.Duration.Contains('M'))
            {
                min = Regex.Match(item.ContentDetails.Duration.Split('M')[0], @"(.{2})\s*$").Value;
            }
            else
            {
                min = "";
            }

            string sec = Regex.Match(item.ContentDetails.Duration.Split('S')[0], @"(.{2})\s*$").Value;

            hour = new string(hour.Where(c => Enumerable.Range('0', 10).Contains(c)).ToArray());

            min = new string(min.Where(c => Enumerable.Range('0', 10).Contains(c)).ToArray());

            sec = new string(sec.Where(c => Enumerable.Range('0', 10).Contains(c)).ToArray());

            if ((hour != "") && (min.Length == 1))
            {
                min = "0" + min;
            }
            else if ((hour != "") && (min == ""))
            {
                min = "00";
            }
            else if (min == "")
            {
                min = "0";
            }

            if (sec.Length == 1)
            {
                sec = "0" + sec;
            }
            else if (sec == "")
            {
                sec = "00";
            }

            if (hour != "")
            {
                hour += ":";
            }

            min += ":";

            newVideo.Duration = hour + min + sec;

            return(newVideo);
        }