npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

video-url-parser

v0.1.2

Published

解析Youtube,Youku,Tudou,iQiyi,Souhu,QQ,Sina,LeTV等视频网站的url,得到视频的id等源信息;同时可以根据得到的源信息创建不同格式的播放链接。

Downloads

22

Readme

video-url-parser

解析Youtube,Youku,Tudou,iQiyi,Souhu,QQ,Sina,LeTV等视频网站的url,得到视频的id等源信息;同时可以根据得到的源信息创建不同格式的播放链接。

Build Status

目前解析服务对视频网站的支持情况:

安装

npm install video-url-parser

使用

使用可以解析中国区视频网站的解析器

var cnVideoUrlParser = require("video-url-parser").cnVideoUrlParser;

//解析一个url
cnVideoUrlParser.parser("http://v.youku.com/v_show/id_XMTg4ODE3NDYwOA==.html");
//[ { "id":"XMTg4ODE3NDYwOA==", "provider":{ "host":"youku.com", ...} } ]

//解析一段字符串中包含的视频信息
var str='播放 <a href="http://v.youku.com/v_show/id_XMTg4ODE3NDYwOA==.html">放弃我,抓紧我</a><br />
播放 <a href="http://v.youku.com/v_show/id_XMTg3OTgwODE0NA==.html">飞到又见飞刀</a><br />';

cnVideoUrlParser.parser(str);
/*[
    { "id":"XMTg4ODE3NDYwOA==", "provider":{ "host":"youku.com", ...} }, 
    { "id":"XMTg3OTgwODE0NA==", "provider":{ "host":"youku.com", ...} } 
]*/

//根据视频源信息创建播放URL
cnVideoUrlParser.create({
    provider: "youku.com",
    id: "XMTg4ODE3NDYwOA==",
    params: {
        from: "github"
    }
});// http://player.youku.com/embed/XMTg4ODE3NDYwOA==?from=github

自定义解析器

下面的示例演示了如何创建一个自定义解析器并使用它,这会让你了解video-url-parser包的运行机制。

var vup = require("video-url-parser"),
    VideoUrlParser = vup.VideoUrlParser,
    VideoProvider = vup.VideoProvider,
    util = vup.util;

//创建一个解析器
var parser = new VideoUrlParser("我的视频URL解析器");
//像解析器中添加一个VideoProvider实例,负责对特定URL的解析
parser.addProvider(new VideoProvider({
    host: "xxx.com", //唯一
    hostMatch: function(source) {
        if (/xxx.com/.test(source)) {
            return this.host;
        }
    },
    parser: function(source) {
        source = source + "";
        var provider = JSON.parse(JSON.stringify(this));
        return [{
            provider: provider,
            id: "1"
        }];
    },
    create: function(videoInfo) {
        return "http://" + this.host + "/play/" + videoInfo.id + ".html";
    }
}));

var videoInfo = parser.parser("http://xxx.com/123");
console.log(videoInfo); //[ { provider: { host: 'xxx.com' }, id: '1' } ]

var url = parser.create(videoInfo[0]);
console.log(url); //http://xxx.com/play/1.html

文件说明

  • src/video-url-parser.js提供核心功能:VideoUrlParser(URL解析器类),VideoProvider(视频供应商类)和util(工具函数),VideoUrlParser实例可以包括多个VideoProvider实例;
  • src/cn-video-url-parser.js提供中国区的视频网站URL解析。