【问题标题】:What is the best way to call channel9 api for getting video?调用channel9 api获取视频的最佳方法是什么?
【发布时间】:2017-01-31 13:40:13
【问题描述】:

假设我有 channel9 电影的 URL;

例如:https://channel9.msdn.com/Series/Office-365-Tips--Tricks/01-Wprowadzenie

我想在我的网站上展示这部电影,并为它展示一些信息。期间。

我所知道的是,我可以通过调用获取电影列表

https://channel9.msdn.com/odata/Entries 并跳过 +25 以显示接下来的 25 个结果。

我现在的实现是这样的:

  1. 从 api 获取前 25 个元素

  2. 遍历它们

  3. 比较我的 url 和 elementFromApi[i].url 它的工作,但我不喜欢这个解决方案,它不优雅而且慢得要命。我对api一无所知,所以我不知道如何重构这个^。

也许你们中的某个人可以帮助我。

PS。我需要来自 api 的信息,用给定的 url 嵌入 iframe 不是这里的解决方案:) PS2。对不起我的英语不好。

【问题讨论】:

    标签: msdn


    【解决方案1】:

    我通过我的客户得到了这个要求,最终我使用 RSS 完成了它!在您的用例中,URL 是 https://channel9.msdn.com/Series/Office-365-Tips--Tricks/01-Wprowadzenie - 我们可以使用链接 https://s.ch9.ms/Series/Office-365-Tips--Tricks/rss/mp4 读取 rss - 在 PowerShell 中,我们可以使用以下代码探索内容

    $Sessions = Invoke-Restmethod -Uri 'https://s.ch9.ms/Series/Office-365-Tips--Tricks/rss/mp4' -UseDefaultCredentials
    foreach($Session in $Sessions) {
        $Duration = [timespan]::FromSeconds($Session.duration)
        [pscustomobject]@{
            Title = $Session.title
            Duration = ("{0:0}:{1:00}:{2:00}" -f ($Duration.Hours , $Duration.Minutes , $Duration.Seconds))
            Creator = $Session.creator
            "URl(MP3)" = $Session.group.content.url[0]
            "URl(MP4)" = $Session.group.content.url[1]
            "URl(webm)" = $Session.group.content.url[2]
            "URl(MP4High)" = $Session.group.content.url[3]
        }
    }
    

    注意:代码需要即兴创作! 使用 C# 也可以实现相同的功能 - 但我不是经过认证的开发人员 - 所以,我使用 PowerShell 来满足客户的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-22
      • 2011-08-05
      • 2015-12-20
      • 2020-12-02
      • 1970-01-01
      • 2021-07-13
      • 2014-11-20
      • 2012-11-06
      相关资源
      最近更新 更多