Exemple #1
0
        public void OnUploadInit(string response)
        {
            m_vimeoUploader.OnRequestComplete -= OnUploadInit;
            m_vimeoUploader.OnRequestComplete += OnVideoUpdated;

            JSONNode jsonResponse = JSONNode.Parse(response);

            video = new VimeoVideo(jsonResponse);

#if UNITY_2018_1_OR_NEWER
            if (recorder.defaultVideoInput == VideoInputType.Camera360)
            {
                m_vimeoUploader.SetVideoSpatialMode("equirectangular", recorder.defaultRenderMode360 == RenderMode360.Stereo ? "top-bottom" : "mono");
            }
#endif

            m_vimeoUploader.SetVideoDescription("Recorded and uploaded with the Vimeo Unity SDK: https://github.com/vimeo/vimeo-unity-sdk");
            if (recorder.enableDownloads == false)
            {
                m_vimeoUploader.SetVideoDownload(recorder.enableDownloads);
            }
            m_vimeoUploader.SetVideoComments(recorder.commentMode);
            m_vimeoUploader.SetVideoReviewPage(recorder.enableReviewPage);
            SetVideoName(recorder.GetVideoName());

            if (recorder.privacyMode == VimeoApi.PrivacyModeDisplay.OnlyPeopleWithAPassword)
            {
                m_vimeoUploader.SetVideoPassword(recorder.videoPassword);
            }
            SetVideoPrivacyMode(recorder.privacyMode);
        }
        private void UploadComplete(string video_uri)
        {
            UploadProgress("SavingInfo", .999f);

            video = new VimeoVideo("", video_uri);

#if UNITY_2018_1_OR_NEWER
            if (recorder.defaultVideoInput == VideoInputType.Camera360)
            {
                vimeoApi.SetVideoSpatialMode("equirectangular", recorder.defaultRenderMode360 == RenderMode360.Stereo ? "top-bottom" : "mono");
            }
#endif

            vimeoApi.SetVideoDescription("Recorded and uploaded with the Vimeo Unity SDK: https://github.com/vimeo/vimeo-unity-sdk");
            if (recorder.enableDownloads == false)
            {
                vimeoApi.SetVideoDownload(recorder.enableDownloads);
            }
            vimeoApi.SetVideoComments(recorder.commentMode);
            // vimeoApi.SetVideoReviewPage(recorder.enableReviewPage);
            SetVideoName(recorder.GetVideoName());

            if (recorder.privacyMode == VimeoApi.PrivacyModeDisplay.OnlyPeopleWithAPassword)
            {
                vimeoApi.SetVideoPassword(recorder.videoPassword);
            }
            SetVideoPrivacyMode(recorder.privacyMode);
        }
        private async Task <List <IVideoLink> > GetVimeoLinks(string videoUrl)
        {
            try
            {
                int    index = videoUrl.IndexOf("/video/");
                string id    = videoUrl.Substring(index + 7).Split('?')[0];

                var vimeo  = new VimeoVideo(id);
                var videos = (await vimeo.ExtractAsync()).Where(v => v.VideoType == VideoType.Mp4 || v.VideoType == VideoType.Mobile);
                var links  = new List <IVideoLink>();

                foreach (var video in videos)
                {
                    links.Add(new CommonVideoLink
                    {
                        Name   = $"{video.VideoType.ToString().ToUpper()} {video.Resolution}p",
                        Source = video.VideoUri.ToString()
                    });
                }

                return(links);
            }
            catch (Exception)
            {
                throw new LinksExtractionFailedException("Vimeo", videoUrl);
            }
        }
    public void GetVideoFileByResolution_Uses_Selected_Resolution_For_Files_Response()
    {
        UnityEngine.TestTools.LogAssert.NoUnexpectedReceived();
        video = new VimeoVideo(JSONNode.Parse(mockProductionJson));
        JSONNode file = video.GetVideoFileByResolution(Vimeo.Player.StreamingResolution.x720p_HD);

        Assert.AreEqual(file["height"].Value, "720");
    }
    public void UploadInit(string response)
    {
        VimeoVideo video = new VimeoVideo(JSONNode.Parse(response));

        uploader.SetVideoViewPrivacy(VimeoApi.PrivacyModeDisplay.OnlyPeopleWithPrivateLink);
        uploader.SetVideoName("Large file test (" + Application.platform + " " + Application.unityVersion + ")");
        uploader.SaveVideo(video);
    }
        public static VimeoChannelVideosResponse Parse(JsonArray array)
        {
            VimeoChannelVideosResponse response = new VimeoChannelVideosResponse {
                Videos = VimeoVideo.ParseMultiple(array) ?? new VimeoVideo[0]
            };

            return(response);
        }
        public static VimeoChannelVideosResponse Parse(XElement xVideos)
        {
            if (xVideos == null || xVideos.Name != "videos")
            {
                return(null);
            }
            VimeoChannelVideosResponse response = new VimeoChannelVideosResponse {
                Videos = VimeoVideo.ParseMultiple(xVideos) ?? new VimeoVideo[0]
            };

            return(response);
        }
Exemple #8
0
 public void LoadVideo(string vimeo_url)
 {
     if (!String.IsNullOrEmpty(vimeo_url))
     {
         vimeoVideo = null;
         vimeoId    = GetVimeoIdFromURL(vimeo_url);
         if (vimeoId > 0)
         {
             LoadVideo(vimeoId);
         }
     }
 }
        public void AppendVideo(int year, VimeoVideo video)
        {
            // Get or create the list of videos for "year"
            List <VimeoVideo> list;

            if (!_years.TryGetValue(year, out list))
            {
                _years.Add(year, list = new List <VimeoVideo>());
            }

            list.Add(video);
            _videos.Add(video);
        }
 public void LoadVideo(string vimeo_url)
 {
     if (vimeo_url != null && vimeo_url != "")
     {
         vimeoVideo = null;
         string[] matches = Regex.Split(vimeo_url, "(vimeo.com)?(/channels/[^/]+)?/?([0-9]+)"); // See https://regexr.com/3prh6
         if (matches[3] != null)
         {
             vimeoVideoId = matches[3];
             LoadVideo(int.Parse(vimeoVideoId));
         }
         else
         {
             Debug.LogError("[Vimeo] Invalid Vimeo URL");
         }
     }
 }
Exemple #11
0
        public void LoadVideo(string vimeo_url)
        {
            if (!String.IsNullOrEmpty(vimeo_url))
            {
                vimeoVideo = null;
                Match match = Regex.Match(vimeo_url, "(vimeo.com)?(/channels/[^/]+)?/?([0-9]+)");

                if (match.Success)
                {
                    vimeoVideoId = match.Groups[3].Value;
                    LoadVideo(int.Parse(vimeoVideoId));
                }
                else
                {
                    Debug.LogError("[Vimeo] Invalid Vimeo URL");
                }
            }
        }
        /// <summary>
        /// Gets the URL for a thumbnail with the specified size.
        /// </summary>
        /// <param name="vimeoId">The ID of the video.</param>
        /// <param name="size">The size of the desired thumbnail.</param>
        public static string GetVimeoThumbnail(this string vimeoId, VimeoThumbnail size)
        {
            VimeoVideo video = VimeoHelpers.GetCachedVideoById(vimeoId);

            if (video == null)
            {
                return(null);
            }
            switch (size)
            {
            case VimeoThumbnail.Small:
                return(video.ThumbnailSmall);

            case VimeoThumbnail.Medium:
                return(video.ThumbnailMedium);

            default:
                return(video.ThumbnailLarge);
            }
        }
        private void VideoMetadataLoad(string response)
        {
            loadingVideoMetadata = false;

            JSONNode json = JSON.Parse(response);

            api.OnRequestComplete -= VideoMetadataLoad;

            if (json["error"] == null)
            {
                if (json["user"]["account"].Value == "basic")
                {
                    Debug.LogError("[VimeoPlayer] You do not have permission to stream videos. You must be a Vimeo Pro or Business customer. https://vimeo.com/upgrade");
                }

                if ((json["play"] == null || json["play"]["progressive"] == null) && json["files"] == null)
                {
                    Debug.LogError("[VimeoPlayer] You do not have permission to access to this video. You must be a Vimeo Pro or Business customer and use videos from your own account. https://vimeo.com/upgrade");
                }

                vimeoVideo = new VimeoVideo(json);

                if (autoPlay || playVideoAfterLoad)
                {
                    Play();
                    playVideoAfterLoad = false;
                }

                if (OnVideoMetadataLoad != null)
                {
                    OnVideoMetadataLoad();
                }
            }
            else
            {
                Debug.LogError("Video could not be found");
            }
        }
 public void _Before()
 {
     video = new VimeoVideo(JSONNode.Parse(mockDevelopmentJson));
 }
 // TODO somehow test different application platforms
 // Note: this fails (correctly) when testing on Mac
 public void GetAdaptiveVideoFileURL_Defaults_To_Hls_For_Files_Response()
 {
     UnityEngine.TestTools.LogAssert.Expect(LogType.Warning, "[Vimeo] No DASH manfiest found. Defaulting to HLS.");
     video = new VimeoVideo(JSONNode.Parse(mockProductionJson));
     Assert.AreEqual(video.GetAdaptiveVideoFileURL(), video.getHlsUrl());
 }
 public void GetDashUrl_Returns_Null_For_Files_Response()
 {
     video = new VimeoVideo(JSONNode.Parse(mockProductionJson));
     Assert.AreEqual(video.getDashUrl(), null);
 }
 public void GetHlsUrl_Works_For_Files_Response()
 {
     UnityEngine.TestTools.LogAssert.NoUnexpectedReceived();
     video = new VimeoVideo(JSONNode.Parse(mockProductionJson));
     Assert.AreEqual(video.getHlsUrl(), "https://player.vimeo.com/external/xxx.m3u8?s=edab7a40157183128871d34b0794feb5f1534501&oauth2_token_id=...");
 }
        /// <summary>
        /// Gets the duration of the Vimeo video with the specified ID.
        /// </summary>
        /// <param name="vimeoId">The ID of the video.</param>
        /// <returns>Returns the duration in seconds if the video is found, otherwise <var>-1</var> will be returned.</returns>
        public static int GetVimeoDuration(this string vimeoId)
        {
            VimeoVideo video = VimeoHelpers.GetCachedVideoById(vimeoId);

            return(video == null ? -1 : (int)video.Duration.TotalSeconds);
        }
 public void PlayVideo(VimeoVideo _vimeoVideo, StreamingResolution resolution)
 {
     vimeoVideo = _vimeoVideo;
     PlayVideoByUrl(vimeoVideo.GetVideoFileUrlByResolution(resolution), vimeoVideo.is3D, vimeoVideo.stereoFormat);
 }
Exemple #20
0
 public void _Before()
 {
     string json = "{\"uri\":\"/videos/279300468\",\"name\":\"Video Test\",\"description\":\"Original 360 version https://vimeo.com/266948610\",\"duration\":306,\"width\":3456,\"height\":2160,\"play\":{\"progressive\":[{\"type\":\"video/mp4\",\"width\":2304,\"height\":1440,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140246.mp4?token=1538089139-0x9a526defb049337f2f4a2bf35f7b27b2cf3c8219\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":432584522,\"md5\":\"af068c26beebc314e5a0074e144d299b\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140246/1538078339/dc9caec747a0eb1db906c280b50d9867b9f773c0\"},{\"type\":\"video/mp4\",\"width\":3456,\"height\":2160,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140239.mp4?token=1538089139-0x51b793ee8a26df3e5441dc2c98d107501cd354f1\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":839989600,\"md5\":\"a58de4bbdab6e16794228d2907438eaf\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140239/1538078339/6f9a254433115037f0c748a8ab7ca7675b1bdb7f\"},{\"type\":\"video/mp4\",\"width\":864,\"height\":540,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140237.mp4?token=1538089139-0x6a94f2a69755cd7f3ba48a8ec047b1f8e05cafaf\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":55626502,\"md5\":\"bdf87cbc8509efd44fd61979c5554813\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140237/1538078339/4994c74d313423eece5bf6aa018fa33b83da1c88\"},{\"type\":\"video/mp4\",\"width\":1728,\"height\":1080,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140236.mp4?token=1538089139-0x08bafb7ae0a43c6b7cc76c9f6693140908a81ec6\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":190693968,\"md5\":\"392a27653f3c8f9849be84bb9269cb48\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140236/1538078339/606b1d862a599281112a61db03a1fe309366f80c\"},{\"type\":\"video/mp4\",\"width\":576,\"height\":400,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140235.mp4?token=1538089139-0x15438ac28abac2cd7c8636d21de7640c639d6cd9\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":19100125,\"md5\":\"d3a0f86dcaa6f2d7b7ee79277dbbb29b\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140235/1538078339/7713097c65f01ab1ca7971625d132395e44e9a73\"},{\"type\":\"video/mp4\",\"width\":1152,\"height\":720,\"link_expiration_time\":\"2018-09-27T22:58:59+00:00\",\"link\":\"https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/860/11/279300468/1046140233.mp4?token=1538089139-0x1f1a8e206bdbe112e5ac1bc61b1cf716dd799816\",\"created_time\":\"2018-07-10T16:17:06+00:00\",\"fps\":30,\"size\":95464913,\"md5\":\"628bacb9124df721b0b0332fbf8f2b74\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/1046140233/1538078339/74f68f53f41f291edc76087cad0f41c5e0d6a79f\"}],\"hls\":{\"link_expiration_time\":\"2018-09-27T21:58:59+00:00\",\"link\":\"https://player.vimeo.com/play/1046140246,1046140239,1046140237,1046140236,1046140235,1046140233/hls?s=279300468_1538085539_2e78157d9c236cc773328a5685b4dc65&context=Vimeo%5CController%5CApi%5CResources%5CVideoController.&logging=false\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/hls/1538078339/ed60f756f0982358980263f34b3c0ed4acd85697\"},\"dash\":{\"link_expiration_time\":\"2018-09-27T21:58:59+00:00\",\"link\":\"https://player.vimeo.com/play/1046140246,1046140239,1046140237,1046140236,1046140235,1046140233/dash?s=279300468_1538085539_2e78157d9c236cc773328a5685b4dc65&context=Vimeo%5CController%5CApi%5CResources%5CVideoController.&logging=false\",\"log\":\"https://api.vimeo.com/videos/279300468:5ad7cb7854/log/dash/1538078339/df1645640bf16272a3f4c386b9eb8dcde3c31c95\"},\"status\":\"playable\"}}";
     video = new VimeoVideo(SimpleJSON.JSON.Parse(json));
 }
        public object GetVideoFromUrl(string url)
        {
            // Validate that we have an URL
            if (String.IsNullOrWhiteSpace(url))
            {
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.BadRequest, "No URL specified")));
            }

            Match m1 = Regex.Match(url, "vimeo.com/([0-9]+)$");
            Match m2 = Regex.Match(url, @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)", RegexOptions.IgnoreCase);

            if (m1.Success)
            {
                string videoId = m1.Groups[1].Value;

                if (String.IsNullOrWhiteSpace(Config.VimeoConsumerKey))
                {
                    return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Vimeo is not configured")));
                }
                if (String.IsNullOrWhiteSpace(Config.VimeoConsumerSecret))
                {
                    return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Vimeo is not configured")));
                }

                VimeoService vimeo = VimeoService.CreateFromConsumerKey(Config.VimeoConsumerKey, Config.VimeoConsumerSecret);

                try {
                    VimeoVideoResponse response = vimeo.Videos.GetInfo(Int32.Parse(videoId));

                    VimeoVideo video = response.Video;

                    return(new {
                        url = "https://vimeo.com/" + videoId,
                        type = "vimeo",
                        details = new {
                            id = videoId,
                            published = TimeUtils.GetUnixTimeFromDateTime(video.UploadDate),
                            title = video.Title,
                            description = video.Description,
                            duration = (int)video.Duration.TotalSeconds,
                            thumbnails = (
                                from thumbnail in video.Thumbnails
                                select new {
                                url = thumbnail.Url,
                                width = thumbnail.Width,
                                height = thumbnail.Height
                            }
                                )
                        }
                    });
                } catch (VimeoException ex) {
                    return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Something went wrong: " + ex.Message)));
                }
            }

            if (m2.Success)
            {
                if (String.IsNullOrWhiteSpace(Config.GoogleServerKey))
                {
                    return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "YouTube is not configured")));
                }

                string videoId = m2.Groups[1].Value;

                GoogleService service = GoogleService.CreateFromServerKey(Config.GoogleServerKey);

                YouTubeVideoListResponse response = service.YouTube.Videos.GetVideos(new YouTubeVideoListOptions {
                    Part = YouTubeVideoPart.Snippet + YouTubeVideoPart.ContentDetails,
                    Ids  = new[] { videoId }
                });

                if (response.Body.Items.Length == 0)
                {
                    return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.BadRequest, "Video not found")));
                }

                YouTubeVideo video = response.Body.Items[0];

                return(new {
                    url = "https://www.youtube.com/watch?v=" + videoId,
                    type = "youtube",
                    details = new {
                        id = videoId,
                        published = TimeUtils.GetUnixTimeFromDateTime(video.Snippet.PublishedAt),
                        title = video.Snippet.Title,
                        description = video.Snippet.Description,
                        duration = (int)video.ContentDetails.Duration.Value.TotalSeconds,
                        thumbnails = new[] {
                            GetThumbnail("default", video.Snippet.Thumbnails.Default),
                            GetThumbnail("medium", video.Snippet.Thumbnails.Medium),
                            GetThumbnail("high", video.Snippet.Thumbnails.High),
                            GetThumbnail("standard", video.Snippet.Thumbnails.Standard)
                        }.WhereNotNull()
                    }
                });
            }

            return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.BadRequest, "Unknown URL syntax")));
        }