skydrive外链mp3方案

January 10th, 2010 Categories: 应用

使用合租空间的独立博客,例如本人,有时想在自己的空间上传mp3,又有版权(美国空间要求趋严)、流量(被迅雷爬到后果很严重)的担心。经过比较,觉得skydrive的空间挺不错的,25G空间,可支持外链。唯一不足之处是操作比较复杂,使用普通的方法不容易批量提取mp3的外链。今天下午做出一种简单易行的方法,可以直接抓取skydrive的公开文件夹里的mp3音乐文件绝对地址并生成Google Player播放代码(因此您就不需要再安装播放mp3的wordpress各种插件了)。所写的php源码一并贴出,有兴趣的自行研究。如果是正则表达式方面的讨论,欢迎跟贴;其它问题恕不回复,见谅。

最终效果如下图:

我爱正则表式|mp3+Skydrive+GooglePlayer

我爱正则表式|mp3+Skydrive+GooglePlayer

上传

使用您的liveID在这里登录,然后新建一个公开的文件夹。之所以要公开,是因为您的mp3是要放在博客上播放的,如果设为私密型,别人就无法欣赏到了。

修改权限的方法见贴图:
我爱正则表式|mp3+Skydrive+GooglePlayer

我爱正则表式|mp3+Skydrive+GooglePlayer
上传时,如果是在IE浏览器下,会有提示安装插件,建议安装。这样就可以将待上传的文件批量拖过来上传了。每个文件不超过50M。总文件的大小没有限制。

指定需要外链的文件地址

您可以指定为某个文件夹生成代码,也可以指定文件生成代码。无论哪种方式,都是一个文件对应一段代码,而不是将所有的播放文件生成一个播放列表。您需要先记下该文件的页面地址,然后根据该地址生成代码。

获得单个文件的地址:
我爱正则表式|mp3+Skydrive+GooglePlayer

获取文件夹的地址:
我爱正则表式|mp3+Skydrive+GooglePlayer

拷贝好页面地址备用。

生成播放代码

请移步到这里:
http://zh-en.org/livemp3/

我爱正则表式|mp3+Skydrive+GooglePlayer

输入上一步得到的页面地址,点击OK,大约2秒钟之后,就会看到这样的内容了:

 
我爱正则表式|mp3+Skydrive+GooglePlayer

将生成的源代码拷贝到wordpress中,就能看到播放器了。

源代码

程序很简单,获得页面地址,使用curl来下载页面,然后使用正则表达式来析取绝对地址,然后生成播放代码,如此而已。其中google player的代码,我是在google reader中读《白板报》的海盗电台时发现的。

如果您感兴趣,还可以将此方案扩展,做skydrive图床,原理一致。不赘述。

php代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
//use:  get mp3, wam, wmv direct links from skydrive's public folder, and generate google player code for that.
//author's email&gtalk:   rex [at] zhasm [dot] com
//last edit:    20100110 18:14

//get the curl handle
//
function init_curl()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_REFERER,"http://skydrive.live.com/");
    //curl_setopt($ch, CURLOPT_POST, 1);
   
    return $ch;
}
// extract mp3 from the given root page;
function get_list($ch,$url)
{
   
    extract_mp3($ch,$url);

    //echo $url;
    curl_setopt($ch, CURLOPT_URL, $url);
    $output = curl_exec($ch);
    //trim the unnecessary parts, for safety

    $links = preg_replace('/^.*?(?=<div id=[\'"]tileView[\'"] class=[\'"]tvContainer[\'"]>)|<div class="bpViewPermissionsLink".*$/si', '', $output);
        //you can add your own music filter
    preg_match_all('/(?<=<a class="tvLink")[^<>]+href="([^"]+)(?<=mp3|wav|wmv)"/si', $links, $result, PREG_PATTERN_ORDER);
    $result = $result[1];
    foreach ($result as $r)
    {
        extract_mp3($ch,$r);
    }
}
 
// extract mp3 from the given sub page, generate output code.
function extract_mp3($ch,$link)
{
    curl_setopt($ch, CURLOPT_URL, $link);
    $output = curl_exec($ch);
//  <a id="spPreviewLink" href=
    preg_match_all('%(?<=<title>)[^><]+(?= - Windows Live</title>)%', $output, $result, PREG_PATTERN_ORDER);
    $title = $result[0];
   
   
    preg_match_all('/(?<=<a\sid="spPreviewLink"\shref=")[^"]+(?=&#63;download")/', $output, $result, PREG_PATTERN_ORDER);
    $result = $result[0];
    foreach($result as $r)
    {
        $demo= "    <div class=\"audio-player-placeholder\">
    <embed classname=\"audio-player-embed\" type=\"application/x-shockwave-flash\" src=\"https://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl="
.$r."\" allowscriptaccess=\"never\" allowfullscreen=\"true\" quality=\"best\" bgcolor=\"#ffffff\" wmode=\"transparent\" flashvars=\"playerMode=embedded\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" height=\"27px\" width=\"400px\">
    </div>"
;
        echo "文件:",$title[0],"<br />\n";
        echo "效果:<br />\n";
        echo $demo,"<br />\n";
        echo "代码:<br />\n";
        echo '<textarea cols="50" rows="10">',$demo,'</textarea>',"<br />\n<br />\n";
    }
}
 
//get user input
$url=@$_GET["url"];

if (!$url){
    exit();
}
 
 
$ch=init_curl();
echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';

$info=get_list($ch,$url);
 
?>
Tags: , , ,

5 Responses to “skydrive外链mp3方案”

  1. 阿里
    January 11th, 2010 at 15:34
    1

    播放没声音啊

    [Reply]

  2. 阿里
    January 11th, 2010 at 15:36
    2

    你那个测试页面需要把 播放栏 显示大点 否则你那不是自动播放 使得无法看到开始按钮。

    [Reply]

  3. January 26th, 2010 at 11:10
    3

    好复杂哦

    [Reply]

  4. March 21st, 2010 at 19:04
    4

    使用了下,效果不好,得到的链接一个晚上过去就失效了……

    [Reply]

  5. June 22nd, 2010 at 21:01
    5

Leave a Comment