【问题标题】:Fliter out live videos from youtube search api从 youtube 搜索 api 中过滤掉实时视频
【发布时间】:2020-11-28 13:05:15
【问题描述】:

我正在尝试使用带有 youtube v3 api Search: list 的搜索查询来获取视频。

我的查询正文如下所示:

  request = youtube.search().list(
            part="snippet",
            maxResults=40,
            q="Cat work york"
        )

但问题是,它会在其他常规视频中返回实时视频。我不想退回直播视频,我该怎么做?请在这里帮助我。

谢谢

【问题讨论】:

    标签: python youtube youtube-api


    【解决方案1】:

    我认为你应该尝试传递这个参数:

    broadcastStatus="completed"

    这是参考:

    https://developers-dot-devsite-v2-prod.appspot.com/youtube/v3/live/docs/liveBroadcasts/list#parameters

    【讨论】:

    • 您好,感谢您的回复。我也不想要任何广播或流媒体视频。只是常规上传的视频。如何查询这些?
    • 也许你可以试试broadcastType='persistent'broadcastStatus='completed'
    【解决方案2】:

    我尝试了这个请求,但没有收到实时视频 - 不需要额外的过滤器:

    网址:

    https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=Cat%20work%20york&type=video&key=[YOUR_API_KEY]
    

    这些是第一页的结果:

    {
      "kind": "youtube#searchListResponse",
      "etag": "-KMpLk38ZnJHhWd5fPfmwou7bX4",
      "nextPageToken": "CAoQAA",
      "regionCode": "CO",
      "pageInfo": {
        "totalResults": 1000000,
        "resultsPerPage": 10
      },
      "items": [
        {
          "kind": "youtube#searchResult",
          "etag": "fe7kdo2hrlF2OjEpk8Nd1kbStFw",
          "id": {
            "kind": "youtube#video",
            "videoId": "jDoVckC6NhA"
          },
          "snippet": {
            "publishedAt": "2015-07-30T21:25:54Z",
            "channelId": "UC9k-yiEpRHMNVOnOi_aQK8w",
            "title": "Woman Endures Cat Calls Walking in Street: 'It Makes You Feel Like A Fool'",
            "description": "Cosmopolitan magazine is getting a lot of attention for a video they posted to their website of women facing a barrage of cat calls just by walking down the streets ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/jDoVckC6NhA/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/jDoVckC6NhA/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/jDoVckC6NhA/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "Inside Edition",
            "liveBroadcastContent": "none",
            "publishTime": "2015-07-30T21:25:54Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "k0tqw-tDAsnJZ5HJjBmHXZyiaiY",
          "id": {
            "kind": "youtube#video",
            "videoId": "aAxx1EZwDIY"
          },
          "snippet": {
            "publishedAt": "2016-02-13T05:35:16Z",
            "channelId": "UC-2ePlhDlfJyzU7vypHFgBQ",
            "title": "2 night races in traffic (cat & mouse)!!",
            "description": "what i normally encounter on my way home !!",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/aAxx1EZwDIY/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/aAxx1EZwDIY/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/aAxx1EZwDIY/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "Daily Street Racing",
            "liveBroadcastContent": "none",
            "publishTime": "2016-02-13T05:35:16Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "grZqq0QA-Z1xxcNDM4Iukhqx3GI",
          "id": {
            "kind": "youtube#video",
            "videoId": "nMlJJKNWQZY"
          },
          "snippet": {
            "publishedAt": "2018-06-24T13:00:04Z",
            "channelId": "UCINb0wqPz-A0dV9nARjJlOQ",
            "title": "Cat Runs A Real Estate Office In Brooklyn | The Dodo City Pets",
            "description": "This Cat Runs A Real Estate Office In Brooklyn | Valentino's dad found him as a stray and brought him to work at his real estate office in Carroll Gardens, ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/nMlJJKNWQZY/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/nMlJJKNWQZY/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/nMlJJKNWQZY/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "The Dodo",
            "liveBroadcastContent": "none",
            "publishTime": "2018-06-24T13:00:04Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "SzycZTHAXxzRnxJH7pl1H-3AHhc",
          "id": {
            "kind": "youtube#video",
            "videoId": "ZUO9ijDjXTg"
          },
          "snippet": {
            "publishedAt": "2020-08-14T03:04:14Z",
            "channelId": "UCcl8P4rYjdbxbFTXxkNXuZQ",
            "title": "Mega Hits 2020 ? Best Of Vocal Deep House Summer Music Mix ? Deep Feeling By ChilledVibes Live #7",
            "description": "Mega Hits 2020 Best Of Vocal Deep House Summer Music Mix Deep Feeling By ChilledVibes Live #7 #SummerMusicMix #BestOfDeepHouse ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/ZUO9ijDjXTg/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/ZUO9ijDjXTg/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/ZUO9ijDjXTg/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "ChilledVibes",
            "liveBroadcastContent": "none",
            "publishTime": "2020-08-14T03:04:14Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "nNSPJNKlYZWYA5FDN96Jv9nFygk",
          "id": {
            "kind": "youtube#video",
            "videoId": "-JOy1nM6UoA"
          },
          "snippet": {
            "publishedAt": "2008-04-21T03:37:32Z",
            "channelId": "UCmSOMw225KDZwqOsLFe9GSw",
            "title": "CAT POWER - New York",
            "description": "Snail is sad but determined to make things work in NYC, with music by Cat Power.",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/-JOy1nM6UoA/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/-JOy1nM6UoA/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/-JOy1nM6UoA/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "puppetbully",
            "liveBroadcastContent": "none",
            "publishTime": "2008-04-21T03:37:32Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "HUmDdgYk1jz3lv6cNhiZLyqek8c",
          "id": {
            "kind": "youtube#video",
            "videoId": "XcAH4OMPlDs"
          },
          "snippet": {
            "publishedAt": "2020-04-17T15:53:42Z",
            "channelId": "UCUw3KEvEX49JlnYhlneD-CA",
            "title": "Running the York Cat Trail During Lockdown April 2020",
            "description": "For anyone who would like to experience the York Cat Trail but who can't get to York. Come with me on a 12 minute whistle stop tour of the cats on buildings in ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/XcAH4OMPlDs/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/XcAH4OMPlDs/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/XcAH4OMPlDs/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "The Cat Gallery",
            "liveBroadcastContent": "none",
            "publishTime": "2020-04-17T15:53:42Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "B6Mx6RpMg8UXlABqaFPgJd_EOqk",
          "id": {
            "kind": "youtube#video",
            "videoId": "df7g19GzFkg"
          },
          "snippet": {
            "publishedAt": "2019-11-05T02:24:12Z",
            "channelId": "UCDVYQ4Zhbm3S2dlz7P1GBDg",
            "title": "Cat on the Field Scores 50-Yd TD Run! ?",
            "description": "A fluffy feline makes its way onto the field and somehow gets to the end zone for a touchdown! The Dallas Cowboys take on the New York Giants during Week 9 ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/df7g19GzFkg/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/df7g19GzFkg/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/df7g19GzFkg/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "NFL",
            "liveBroadcastContent": "none",
            "publishTime": "2019-11-05T02:24:12Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "k5CXKp3kDIqnyqT03Vxj9_tMdKg",
          "id": {
            "kind": "youtube#video",
            "videoId": "j0RgF_AL5vk"
          },
          "snippet": {
            "publishedAt": "2018-08-31T02:11:05Z",
            "channelId": "UC4L0b4TTnV_dK67pWxPxPXA",
            "title": "FAT CAT PUT ALL THAT WORK IN AND TURNED ON PAPPY MASON HE IS NOW IN ADX SUFFERING ??‍♂️?",
            "description": "Fat cat TRIPLE DOUBLE CROSSER.",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/j0RgF_AL5vk/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/j0RgF_AL5vk/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/j0RgF_AL5vk/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "KING EARNER",
            "liveBroadcastContent": "none",
            "publishTime": "2018-08-31T02:11:05Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "QM6IfM0553SCG8Lb21omcpVmZ2k",
          "id": {
            "kind": "youtube#video",
            "videoId": "4cb1YIsyty4"
          },
          "snippet": {
            "publishedAt": "2016-09-12T14:18:43Z",
            "channelId": "UCEcDA5zAfZTVr93HoUzYf_w",
            "title": "Cat® Power Box Rake Attachment Operating Tips",
            "description": "http://www.cat.com/en_US/products/new/attachments/rakes.html | Learn operating tips for the Power Box Rake work tool attachment for Skid Steer Loaders, ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/4cb1YIsyty4/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/4cb1YIsyty4/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/4cb1YIsyty4/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "Cat Landscaping and Construction",
            "liveBroadcastContent": "none",
            "publishTime": "2016-09-12T14:18:43Z"
          }
        },
        {
          "kind": "youtube#searchResult",
          "etag": "gXii2GJAAanIFjYjqeIZvsctnHI",
          "id": {
            "kind": "youtube#video",
            "videoId": "4pq9N8qrTT0"
          },
          "snippet": {
            "publishedAt": "2020-07-14T14:23:32Z",
            "channelId": "UChLtXXpo4Ge1ReTEboVvTDg",
            "title": "''Rocco, put your tail down": Cat interrupts virtual UK parliamentary meeting",
            "description": "A member of the UK parliament's cat interrupted a live virtual committee meeting on Tuesday, prompting laughter from others on the call. John Nicolson was ...",
            "thumbnails": {
              "default": {
                "url": "https://i.ytimg.com/vi/4pq9N8qrTT0/default.jpg",
                "width": 120,
                "height": 90
              },
              "medium": {
                "url": "https://i.ytimg.com/vi/4pq9N8qrTT0/mqdefault.jpg",
                "width": 320,
                "height": 180
              },
              "high": {
                "url": "https://i.ytimg.com/vi/4pq9N8qrTT0/hqdefault.jpg",
                "width": 480,
                "height": 360
              }
            },
            "channelTitle": "Global News",
            "liveBroadcastContent": "none",
            "publishTime": "2020-07-14T14:23:32Z"
          }
        }
      ]
    }
    

    如果您仍然有“直播视频”,请在 URL 请求中添加 videoDuration=medium 过滤器。

    【讨论】:

      【解决方案3】:

      使用以下过滤器试试这个https://developers.google.com/youtube/v3/docs/search/list

      part="snippet", 
      q="/-Live",
      safeSearch="strict",
      type="video
      

      【讨论】:

        猜你喜欢
        • 2012-02-23
        • 2013-12-14
        • 2020-05-18
        • 2019-02-28
        • 2015-03-03
        • 2018-10-03
        • 2015-10-19
        • 1970-01-01
        • 2015-11-06
        相关资源
        最近更新 更多