简体   繁体   English

如何使用C#获取.mp4视频的直接URL?

[英]How do I get direct URL of the .mp4 video using C#?

I need some sort of algorythm that would extract the link from mp4engine. 我需要一些能从mp4engine中提取链接的algorythm。

Here is the example of a page I want to scrap. 这是我要废弃的页面示例。

Desired output in this case would be: http://mp4engine.com:182/d/a2chmyndcqqgkpskitclvbgu5pgwxve2vmlrdsctpwbte2flb4i4hrz6/.hack_Roots (Dub) Episode 001-360p.mp4 在这种情况下,期望的输出将是: http ://mp4engine.com:182 / d / a2chmyndcqqgkpskitclvbgu5pgwxve2vmlrdsctpwbte2flb4i4hrz6 / .hack_Roots(Dub)Episode 001-360p.mp4

I tried to use HtmlAgilityPack to get the player code, but it's p,a,c,k,e,d , and I'm unable to execute it inside my C# Windows Phone 8.1 project. 我试图使用HtmlAgilityPack来获取播放器代码,但是它是p,a,c,k,e,d ,我无法在我的C#Windows Phone 8.1项目中执行它。 I thought about using Jurassic package to execute the JS, but it doesn't seem to work with WinPhone8.1 我想过使用Jurassic包来执行JS,但它似乎不适用于WinPhone8.1

Here is the script I get using HAP: 这是我使用HAP获得的脚本:

<script type='text/javascript'>eval(function(p,a,c,k,e,d){while(c--    )if(k[c])p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c]);return p} ('15("14").13({f:"0://2.1:e/d/c/.b (a) 9 8- 7.6",12:"0://2.1/4/h.g",11:"0://2.1/i/10/z.y",x:"w",v:u,t:s,5:"0",r:"0://2.1/4/q /p",o:[{3:"n",m:"0://2.1/4/h.g"},{3:"l",k:{f:\'0://2.1:e/d/c/.b (a) 9 8- 7.6\',\'5\':\'0\'}},{3:"j"}],});',36,42,'http|com|mp4engine|type|player|provider|mp4|360p|001|Episode|Dub|hack_Roots|a2chmyndcqqgkpskitclvbgu5pgwxve2vmlrdsctpwbte2flb4i4hrz6||182|file|swf|jw6||download|config|html5|src|flash|modes|six|skins|skin|420|height|722|width|1484|duration|jpg|hahgl235zwv2|00000|image|flashplayer|setup|flvplayer|jwplayer'.split('|')))

I have also tried to use built-in WebView Control: 我也尝试使用内置的WebView控件:

WebView wv = new WebView();
//... navigation to string and all that
var res = await wv.InvokeScriptAsync("eval", null);

Unfortunately, the function returns empty string ( res = "" ) 不幸的是,该函数返回空字符串( res = ""

I have also searched for base64 string that I could decode, but the page doesn't seem to have one. 我也搜索了我可以解码的base64字符串,但页面似乎没有。

What can I do to get the video URL? 我该怎么做才能获得视频网址?

Inside the <div id="player_code" ... , the last <script> tag contain the obfuscated javascript code where the video URL is. <div id="player_code" ... ,最后一个<script>标记包含视频网址所在的模糊javascript代码。 This site can unobfuscate this code and the result will look like this: 站点可以对此代码进行取消混淆,结果将如下所示:

jwplayer("flvplayer").setup({
    file: "http://mp4engine.com:182/d/a2chmyndcqqgkpskitclvbgu5pgwxve2vmlrdsctpwbsg7asjwghgk4p/.hack_Roots (Dub) Episode 001-360p.mp4",
    flashplayer: "http://mp4engine.com/player/jw6.swf",
    image: "http://mp4engine.com/i/00000/hahgl235zwv2.jpg",
    duration: "1484",
    width: 722,
    height: 420,
    provider: "http",
    skin: "http://mp4engine.com/player/skins/six",
    modes: [{
        type: "flash",
        src: "http://mp4engine.com/player/jw6.swf"
    }, {
        type: "html5",
        config: {
            file: 'http://mp4engine.com:182/d/a2chmyndcqqgkpskitclvbgu5pgwxve2vmlrdsctpwbsg7asjwghgk4p/.hack_Roots (Dub) Episode 001-360p.mp4',
            'provider': 'http'
        }
    }, {
        type: "download"
    }],
});

As you can see, file: contains the video URL. 如您所见, file:包含视频URL。 So, in your C# code, you can download the HTML code of the page, look for the last <script> tag inside the <div id="player_code" ... and unobfuscate it using the C# port listed on same site. 因此,在您的C#代码中,您可以下载页面的HTML代码,在<div id="player_code" ...查找最后一个<script>标记<div id="player_code" ...并使用同一站点上列出的C#端口对其进行<div id="player_code" ...

HtmlAgilityPack only take the static HTML code, you need to execute the dynamic content (javascript) to take the data. HtmlAgilityPack只接受静态HTML代码,需要执行动态内容(javascript)来获取数据。

You have three ways: 你有三种方式:

1 - Implement a beautifier code for javascript in your c# (here you can see an example: http://jsbeautifier.org/ ). 1 - 在你的c#中为javascript实现一个美化代码(这里你可以看到一个例子: http//jsbeautifier.org/ )。 In this case and only for you case, you can extract the video url because is on it, but this is not common. 在这种情况下,仅适用于您的情况,您可以提取视频网址,因为它在上面,但这并不常见。

2 - Using the .net web browser to connect to the page and execute the javascript code to scrape the data, in this case you application must be a Windows Form application. 2 - 使用.net Web浏览器连接到页面并执行javascript代码来刮取数据,在这种情况下,您的应用程序必须是Windows窗体应用程序。

3 - Using a headless-browser to connect to the page and execute the javascript code to scrape the data. 3 - 使用无头浏览器连接到页面并执行javascript代码来刮取数据。 You could use the famous phatomjs. 你可以使用着名的phatomjs。 Example here: C# example of using PhantomJS webdriver ExecutePhantomJS to filter out images 此处的示例:使用PhantomJS webdriver ExecutePhantomJS过滤掉图像的C#示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM