【问题标题】:Extract number of video or audio files from Wikipedia article从维基百科文章中提取视频或音频文件的数量
【发布时间】:2014-12-08 21:00:37
【问题描述】:

我正在尝试提取 Wikipedia 文章中存在的视频或音频文件的数量,我搜索了 API,但没有找到相应的 API。

我确实注意到,当使用 API 提取特定页面的图像时,带有 .ogg 扩展名的音频文件会出现在带有图像的列表中。

http://ar.wikipedia.org/w/api.php?format=xml&action=parse&page=%D8%AD%D9%88%D8%AB%D9%8A%D9%88%D9%86&prop=images&redirects=

不知道这个案例能不能泛化,能不能用它来统计视频和音频文件?有没有人有其他方法可以做到这一点?

【问题讨论】:

    标签: mediawiki mediawiki-api


    【解决方案1】:

    基本上所有文件类型都被 API 平等对待,但您可以获取每个文件的 mediatype,并使用它来过滤掉视频和音频文件。

    要获取文件的媒体类型,您可以为每个文件使用prop=imageinfo(这个will be changed 到更准确的prop=fileinfo 在未来的版本中)。由于prop=images 可以用作生成器,因此您可以在一个 API 调用中获取文件列表及其媒体类型,例如 this

    https://ar.wikipedia.org/w/api.php?action=query&generator=images&titles=%D8%AD%D9%88%D8%AB%D9%8A%D9%88%D9%86&redirects=&prop=imageinfo&iiprop=mediatype&continue=&format=xml
    

    这里images 用作生成器,返回文件列表,而文件列表又被提供给imageinfo 调用。

    对于每个文件,您将得到如下内容:

    "2014232": {
      "pageid": 2014232,
      "ns": 6,
      "title": "\u0645\u0644\u0641:06-Salame-Al Aadm 001.ogg",
      "imagerepository": "local",
      "imageinfo": [
        {
          "mediatype": "AUDIO"
        }
      ]
    }
    

    mediatype 可以是以下任何一种(从manual 复制并粘贴):

    UNKNOWN     // unknown format
    BITMAP      // some bitmap image or image source (like psd, etc). Can't scale up.
    DRAWING     // some vector drawing (SVG, WMF, PS, ...) or image source (oo-draw, etc). Can scale up.
    AUDIO       // simple audio file (ogg, mp3, wav, midi, whatever)
    VIDEO       // simple video file (ogg, mpg, etc; no not include formats here that may contain executable sections or scripts!)
    MULTIMEDIA  // Scriptable Multimedia (flash, advanced video container formats, etc)
    OFFICE      // Office Documents, Spreadsheets (office formats possibly containing apples, scripts, etc)
    TEXT        // Plain text (possibly containing program code or scripts)
    EXECUTABLE  // binary executable
    ARCHIVE     // archive file (zip, tar, etc)
    

    mimetype mediatype 的默认映射在 here 可用,但可以为单个 wiki 覆盖它。

    【讨论】:

      猜你喜欢
      • 2018-03-22
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 2012-12-07
      相关资源
      最近更新 更多