public override async Task<MediaInfo[]> GetMediaInfosAsync(Uri Url) { if (!this.IsMatch(Url)) throw new NotSupportedException("不正確的網址"); string EmbedUrl = $"http://www.dailymotion.com/embed/video/{GetMediaId(Url.OriginalString)}";//取得外連播放器連結 JObject MediaJObject = await GetMediaJson(EmbedUrl); OnProcess?.Invoke(this, 0.2); var p = MediaJObject["metadata"]?["qualities"]?["240"]?[0].Value<JObject>(); JObject Qualities = MediaJObject["metadata"]?["qualities"]?.Value<JObject>(); MediaInfo Templet = new MediaInfo();//資料樣板 Templet.ExtractorType = typeof(DailymotionExtractor); Templet.SourceUrl = Url; Templet.Name = MediaJObject["metadata"]?["title"].Value<string>(); Templet.Attributes["author"] = MediaJObject["metadata"]?["owner"]?["username"].Value<string>(); Templet.Duration = MediaJObject["metadata"]?["duration"].Value<int>() ?? 0; Templet.Thumbnail = new Uri(MediaJObject["metadata"]?["poster_url"].Value<string>()); List<MediaInfo> result = new List<MediaInfo>(); double Process = 0.2; foreach (var i in Qualities) { int temp = 0; if (!int.TryParse(i.Key, out temp)) { continue; } JObject VideoData = i.Value[0].Value<JObject>(); MediaInfo t = Templet.Clone(); t.Type = MediaTypes.Video; t.RealUrl = new Uri(VideoData?["url"].Value<string>()); t.Attributes["quality"] = i.Key; t.Attributes["size"] = GetSize(VideoData?["url"].Value<string>()); t.Attributes["mime"] = "video/mp4"; result.Add(t); Process += 0.8 / Qualities.Count; OnProcess?.Invoke(this, Process); } MediaInfo[] output = result.ToArray(); OnCompleted?.Invoke(this, output); return output; }
public override async Task<MediaInfo[]> GetMediaInfosAsync(Uri Url) { if (!this.IsMatch(Url)) throw new NotSupportedException("不正確的網址"); string mediaId = this.GetMediaId(Url); Dictionary<string, string> apiData = await this.GetMediaApiData(mediaId); OnProcess?.Invoke(this, 0.1); List<MediaInfo> result = new List<MediaInfo>(); MediaInfo baseInfo = new MediaInfo(); baseInfo.SourceUrl = Url; baseInfo.Name = apiData["title"]; baseInfo.Duration = (int)double.Parse(apiData["duration"]); string description; apiData.TryGetValue("description",out description); baseInfo.Description = description; baseInfo.Thumbnail = new Uri(apiData["thumb"]); baseInfo.ExtractorType = this.GetType(); baseInfo.Type = (MediaTypes)Enum.Parse(typeof(MediaTypes), apiData["type"], true); baseInfo.Attributes["author"] = apiData["author_name"]; OnProcess?.Invoke(this, 0.3); if (apiData.ContainsKey("src")) {//360 MediaInfo def_src = baseInfo.Clone(); def_src.RealUrl = new Uri(apiData["src"]); if (baseInfo.Type == MediaTypes.Video) { def_src.Attributes["size"] = "480x360"; def_src.Attributes["quality"] = "default"; def_src.Attributes["mime"] = "video/mp4"; } else { def_src.Attributes["mime"] = "audio/mp3"; } result.Add(def_src); } OnProcess?.Invoke(this, 0.5); if (apiData.ContainsKey("flv_src")) {//360 flv MediaInfo flv_src = baseInfo.Clone(); flv_src.RealUrl = new Uri(apiData["flv_src"]); if (baseInfo.Type == MediaTypes.Video) { flv_src.Attributes["size"] = "480x360"; flv_src.Attributes["quality"] = "default"; flv_src.Attributes["mime"] = "video/x-flv"; } else { flv_src.Attributes["mime"] = "audio/x-flv"; } result.Add(flv_src); } OnProcess?.Invoke(this, 0.7); if (apiData.ContainsKey("hq_src")) {//720 MediaInfo hq_src = baseInfo.Clone(); hq_src.RealUrl = new Uri(apiData["hq_src"]); if (baseInfo.Type == MediaTypes.Video) { hq_src.Attributes["size"] = "1280x720"; hq_src.Attributes["quality"] = "hq"; } hq_src.Attributes["mime"] = "video/mp4"; result.Add(hq_src); } OnProcess?.Invoke(this, 0.9); if (apiData.ContainsKey("hd1080_src")) {//1080 MediaInfo hd1080_src = baseInfo.Clone(); hd1080_src.RealUrl = new Uri(apiData["hd1080_src"]); if (baseInfo.Type == MediaTypes.Video) { hd1080_src.Attributes["size"] = "1920x1080"; hd1080_src.Attributes["quality"] = "hd"; } hd1080_src.Attributes["mime"] = "video/mp4"; result.Add(hd1080_src); } MediaInfo[] output = result.ToArray(); OnProcess?.Invoke(this, 1); OnCompleted?.Invoke(this, output); return output; }