一个可能对你有用的垃圾东东

qidizi 2005-11-06 12:41:18
因为朋友机是公司的垃圾机10G,98M内存,所以帮他做了个自动查找播放东东,

有兴趣的朋友可以瞧下
实现办法:
人工添加歌曲信息(歌曲名称或及歌手)做成列表,随机选择一个,打开网页查找可用的链接并进行播放
功能:
加歌曲:可复制网上的歌曲排行的列表格式成可用的列表或自己一行一个歌曲办法添加列表;
重复播放,
显示歌词
指定忍耐上限(找到可用链接到播放时间长,超过,更换快的)
可双击选择播放
暂时这么多,
其它的功能改进可以自己考虑添加

----------------
主文件:自动网上搜索播放音乐程序.hta(因为要跨域操作,必须用HTA)
------------------

<html APPLICATION=yes><HEAD>

<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>自动网上搜索播放音乐程序</title>

<HTA:APPLICATION ID="autoplayer"
APPLICATIONNAME="autoplayer"
ICON="图标.ico"
NAVIGABLE="yes"
SINGLEINSTANCE="yes"
></HTA:APPLICATION>

</head>

<script language ='javascript'>
<!--

var current = 0; //指示当前使用的列表变量
var listindex0 = -1; //列表变量0;
var listindex1 = -1; //列表变量1
var urlindex0 = 0; //列表0的使用链接下标
var urlindex1 = 0; //列表1的使用链接下标
var stop2nexttimer; //防止短时的停止事件频繁调用下首函数
var buffertimer; //等待时间
var playtimer; //播放定时器

function window.onload()
{
if( isNaN ( listwin.document.body.buffertime * 1 ) )
listwin.document.body.buffertime = 30 ; //当缓冲时间未声明或非数字时,设置为默认值
buffertime.value = listwin.document.body.buffertime; //读取缓冲时间
setlistwin();
setlistindex( current ); //开始播放处理
}

function setlistwin()
{
listwindiv.style.height = document.body.clientHeight - listwindiv.offsetTop;
if( showtxt.checked )
txtdiv.style.height = listwindiv.style.height;
}

window.onresize = setlistwin;

function setlistindex( which )
{
if( which == current )document.title = "请稍等!正在处理!";
if ( eval( "listindex" + which ) < 0 )
{ //变量未有可用值
if ( ( eval( "listindex" + which + " = getlistindex()" ) ) < 0 ) return -1; //列表变量得到的是不可用值时,停止
}
if ( listwin.document.all[ eval( "listindex" + which ) ].url == null || listwin.document.all[ eval( "listindex" + which ) ].url == "" )
{//列表变量值对象未有URL
eval( "urlindex" + which + " = 0" ); //未有URL,必须查找,先置URL指示变量为零
if( eval( "searchwin" + which ).location == "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ) )
{//已打开,直接查找即可
selecturl( which );
}else
{//未打开查找网页
eval( "searchwin" + which ).location = "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ); //打开查找网页,等待loaded状态事件
}
}else if( which == current )
{
playurl( which ); //已有URL,直接调用播放
setlistindex ( ( !which ) * 1 ); //准备后备列表
}
}

function changeurl()
{
listwin.document.all[ eval( "listindex" + current ) ].url = ""; //出错的地址不能要
setlistindex( current );
}

function playurl( which )
{
if ( player.url == listwin.document.all[ eval( "listindex" + current ) ].url )
{ //不是当前使用的的,而是准备列表不能播放
return -1;
}
player.url = listwin.document.all[ eval( "listindex" + current ) ].url; //设置播放器的地址为当前的列表的URL
clearTimeout( playtimer );
playtimer = setTimeout( "player.controls.play()" ,500 );
document.title = "歌曲: " + listwin.document.all[ eval( "listindex" + which ) ].innerText + " => " + listwin.document.all[ eval( "listindex" + which ) ].url; //在标题栏显示当前的歌曲信息
clearTimeout( buffertimer );
buffertimer = setTimeout( "selecturl( current )", buffertime.value * 1000 ); //设置等待时间
if( showtxt.checked ) play2showtxt(); //决定是否查找歌词
}

function getlistindex()
{
if( listwin.document.getElementsByTagName( "A" ).length < 1 )
{
alert( "\t出错!\n \n可能是列表框中不存在任何列表! \n\n请检查后添加歌曲再试!" );
return -1; //返回不存在的值
}
return listwin.document.getElementsByTagName( "A" )[ Math.ceil( listwin.document.getElementsByTagName( "A" ).length * Math.random() ) - 1 ].sourceIndex; //返回随机选择的列表下标
}


function selecturl( which )
{
if( which == current && eval( "searchwin" + which ).location.href.indexOf( "http://" ) > -1)document.title = "请稍等!正在处理!";
if( ( eval( "listindex" + which ) < 0 ) || ( eval( "searchwin" + which ).location.href.indexOf( "http://" ) < 0 ) ) return -1; //未完全载入,不能读取链接
var allurl = eval( "searchwin" + which ).document.links;

for( ; eval( "urlindex" + which ) < allurl.length; eval( "urlindex" + which + "++") )
{ //从上次搜索的下标处开始

if( allurl[ eval( "urlindex" + which ) ].href.match( /(\.mp3 *$)|(\.wma *$)/gi ) != null)
{ //只有是MP3或WMA文件的链接才要

if( allurl[ eval( "urlindex" + which ) ].href.match( /^ *http\:\/\/220\.181\.26\.88.+/gim ) != null )
{ //是搜狗的还要在后面加上?WXC
listwin.document.all[ eval( "listindex" + which ) ].url = allurl[ eval( "urlindex" + which ) ].href + "?wxc";
}else
{
listwin.document.all[ eval( "listindex" + which ) ].url = allurl[ eval( "urlindex" + which ) ].href; //普通的链接直接设置就行了,
}

if( ( listwin.document.all[ eval( "listindex" + which ) ].url == player.url ) && ( which == current ) )
{
listwin.document.all[ eval( "listindex" + which ) ].url = ""; //出错的地址不能要
continue;
}


eval( "urlindex" + which + "++" ); //为下次再查找时指示到下一个
if( which == current )
{
setlistindex ( ( !which ) * 1 ); // 处理准备列表:
return playurl( which ); //找到不必再执行找不到的指令
}else { return 1; }
}

}

listwin.document.all[ eval( "listindex" + which ) ].url = ""; //找不到了,移除URL属性

if( which == current )
{ //是当前的,所以假设后备的列表已准备好,直接调用它,而把当前的换成后备的,
nextlist();
}else{//不是当前的,所以直接重设就行了,
eval( "listindex" + which + " = -1" );//把此变量设为-1,以可以重新操作,
setlistindex( which ); //找不到了,重设;
}
}

function nextlist( )
{//下一首

eval( "listindex" + current + " = -1" ); //把此变量设为-1,以可以重新操作,
setlistindex ( ( current = ( !current ) * 1 ) ); // 处理准备列表:
}

function play2showtxt()
{
if( txtwin.location != "http://d.sogou.com/gecisearch.so?class=5&query=" + escape( listwin.document.all[ eval( "listindex" + current ) ].innerText ) )
txtwin.location = "http://d.sogou.com/gecisearch.so?class=5&query=" + escape( listwin.document.all[ eval( "listindex" + current ) ].innerText ); //查找歌词
}
...全文
316 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qidizi 2005-11-06
  • 打赏
  • 举报
回复
刚更改出现问题:地址有错时只在二个之间转来转去,

if ( listwin.document.all[ eval( "listindex" + which ) ].url == null || listwin.document.all[ eval( "listindex" + which ) ].url == "" )
{//列表变量值对象未有URL
eval( "urlindex" + which + " = 0" ); //未有URL,必须查找,先置URL指示变量为零
if( eval( "searchwin" + which ).location == "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ) )
{//已打开,直接查找即可
selecturl( which );
}else
{//未打开查找网页
eval( "searchwin" + which ).location = "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ); //打开查找网页,等待loaded状态事件
}


改成



if ( listwin.document.all[ eval( "listindex" + which ) ].url == null || listwin.document.all[ eval( "listindex" + which ) ].url == "" )
{//列表变量值对象未有URL
if( eval( "searchwin" + which ).location == "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ) )
{//已打开,直接查找即可
selecturl( which );
}else
{//未打开查找网页
eval( "urlindex" + which + " = 0" ); //未有URL,必须查找,先置URL指示变量为零
eval( "searchwin" + which ).location = "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ); //打开查找网页,等待loaded状态事件
}
qidizi 2005-11-06
  • 打赏
  • 举报
回复


function listwin.document.oncontextmenu()
{
var where = listwin.event.srcElement;
if( where.tagName == "A" && confirm( "确定要删除\n\n" + where.innerText + "\n\n?" ) )
{
listwin.document.body.removeChild( where );
}
}




var moveobj = null;
var xx = 0 ;
var yy = 0;
function movestart(o,n)
{
moveobj = o;
moveobj.setCapture();

xx = event.x - eval(n).offsetLeft;
yy = event.y - eval(n).offsetTop;
}

function moving(n)
{
if(moveobj != null){
eval(n).style.left = event.x - xx;
eval(n).style.top = event.y - yy;
}
}

function moveend()
{
moveobj.releaseCapture();
moveobj = null;
}

</script>


<iframe id="searchwin0" style="display:none; width:0px; height:0px;" onload = "selecturl(0)"></iframe>
<iframe id="searchwin1" style="display:none; width:0px; height:0px;" onload = "selecturl(1)"></iframe>
</body>
</html>


-------------
制作歌曲列表文件:listformat.html
--------------
<html APPLICATION=yes><HEAD>
<title>歌曲列表制作(提取歌曲名称或及歌手)窗口</title>
</head>
<body onload="textlist.value =window.clipboardData.getData('Text')" bgcolor=green style="color:#87D200">
<textarea id=textlist style="width:50%; height:70%" title="文本输入框:文本格式的歌曲信息,具有一定规律性的文本歌曲信息文本段,可自己按一行一条歌曲的形式编辑,也可以粘贴网站上的" wrap=off ></textarea><span id=htmllist style="overflow:auto; width:50%; height:70%; white-space: nowrap" title=播放器可使用的网页格式歌曲信息框,即歌曲列表 ></span>
尝试按照以下规律提取出歌曲信息:<BR><input type=radio name=format onclick='formatlist("song")' title=文本输入框中是一行一条歌曲信息的规律排列>一行一歌<input type=radio name=format onclick='formatlist("1 song")' title="文本歌曲信息框中是:纯数字编号+空格+歌曲信息+再空格+纯数字编号+空格+歌曲信息...的规律排列">编号+空格+歌曲信息<input type=radio name=format onclick='formatlist("1. song")' title="文本歌曲信息框中是:纯数字编号+圆点+空格+歌曲信息+再空格+纯数字编号+圆点+空格+歌曲信息...的规律排列">编号+圆点+空格+歌曲信息<input type=radio name=format onclick='formatlist("1.song")' title="文本歌曲信息框中是:纯数字编号+圆点+空格+歌曲信息+再空格+纯数字编号+圆点+歌曲信息...的规律排列">编号+圆点+歌曲信息
<input type=button value='正确提取,现加入播放列表' onclick="alert( window.dialogArguments.listwin.document.body.insertAdjacentHTML( 'beforeEnd', htmllist.innerHTML ) ? '添加新的歌曲列表出错' : '完成新的歌曲列表的添加' );" style="width:100%">

<script>

function formatlist( how )
{
switch( how )
{
case "song":
var music;
var reg = / *(.+) */g;
htmllist.innerHTML = "";
while( ( music = reg.exec(textlist.value) ) != null )
{
htmllist.innerHTML += "<A>" + music[1] + "<br></A>";
}
break;
case "1 song":
case "1. song":
var music;
var reg = /※([^※\n\r]+)/g;
htmllist.innerHTML = "";
while( ( music = reg.exec(textlist.value.replace( /(?:^ *\d+\.? +)|(?: +\d+\.? +)|(?:\n *\d+\.? +)/g, "※" ) ) ) != null )
{
htmllist.innerHTML += "<A>" + music[1] + "<br></A>";
}
break;
case "1.song":
var music;
var reg = /※([^※\n\r]+)/g;
htmllist.innerHTML = "";
while( ( music = reg.exec(textlist.value.replace( /(?:^ *\d+\.)|(?: +\d+\.)|(?:\n *\d+\.)/g, "※" ) ) ) != null )
{
htmllist.innerHTML += "<A>" + music[1] + "<br></A>";
}
break;
default:
var music;
var reg = /※([^※\n\r]+)/g;
htmllist.innerHTML = "";
while( ( music = reg.exec( eval( 'textlist.value.replace( /' + myformat.value + '/g, "※" )' ) ) ) != null )
{
htmllist.innerHTML += "<A>" + music[1] + "<br></A>";
}
}
}

</script>
</body></html>
-----------
列表文件:播放列表.html
-----------
<HTML><HEAD></HEAD>
<BODY title=" ①播放某条歌曲:双击它 ②删除某条歌曲:右键点它后选择确定 ③查找指定歌曲:点下播放列表任何地方,先按住CTRL键,再接着按下F键,全放开,输入你要的歌曲名部分或全部进行查找" style="COLOR: yellow" bgColor=green buffertime="60"><A url="http://218.3.207.15/source/upload/26152.mp3">两只蝴蝶<BR></A><A url="http://www.no4hospital-sz.com/qfmy/fun/flash/ricerat.mp3">老鼠爱大米<BR></A><A url="http://101560.iuni.com.cn/obb/01/bsnwsw.wma">别说我的眼泪你无所谓<BR></A><A url="http://www.digitalsoundplanet.com/Members/000132390_000010912_proj.mp3">欧若拉 <BR></A><A url="http://www.zujia.net/music/21你到底爱谁.mp3">你到底爱谁(刘嘉亮)<BR></A><A url="http://play8.tom.com/upload/14495.mp3">快乐崇拜<BR></A><A url="http://3our.com/top/mp3/7.mp3">丁香花<BR></A><A url="http://www.yueqi.com/forum/uploadImages/1125856500000.mp3">江南 <BR></A><A url="http://www.3our.com/top/mp3/9.mp3">我们的爱<BR></A><A url="http://220.181.26.88/Songs/Chinese/Male/张学友/1995-真爱新曲+真正精选/吻别.mp3?wxc">吻别<BR></A><A url="http://www.shanghaiboy.com/music/box/lyy.mp3">六月的雨<BR></A><A url="http://file.qyule.com/upload/2005-05-20/rlCVS5vxlvgEdcgN.mp3">孤单北半球 <BR></A><A url="http://www.dreammates.com.cn/uploads/videos/15821/20051019083307.mp3">童话(光良)<BR></A></BODY></HTML>
-----
还有一个图标文件:图标.ICO
可以自已找个
qidizi 2005-11-06
  • 打赏
  • 举报
回复


function openlistformatwin()
{
var addwin = showModelessDialog("listformat.html",window,'dialogWidth:630px;dialogHeight:300px;dialogLeft:0px;dialogTop:0px;center:no;help:no;resizable:yes;status:no;scroll:no');
}

function savelist()
{
var html = null;
try
{
html = listwin.document.documentElement.outerHTML;
}catch(e){ return 1 ;}
if( html == null ) return 1;
var fn = ( new ActiveXObject("Scripting.FileSystemObject") ).openTextFile( unescape( location.pathname ).replace(/\\/g,'/').replace( /\/[^\/]*$/g,"/") + "播放列表.html",2,true);
fn.write( html );
fn.close();
fn = null;
}

function window.onunload()
{
player.close();
listwin.document.body.buffertime = buffertime.value;
return savelist();
}

//-->
</script>

<body scroll=no TOPMARGIN="0" LEFTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" BottomMARGIN="0" rightMARGIN="0" bgcolor=black style="color:#87D200">

<input type=button value="加歌" title="把你刚才复制的文本或你自己在歌曲文本框输入一行一条歌曲,然后根据你指定的规律提取成播放能识别的歌曲列表,就可能查看下是否选择添加" onclick=openlistformatwin();>
<input type=button value="下首" onclick="nextlist()" title="随机选择下一首歌曲播放">
<input type=button value="换地址" title="更换一个不用缓冲的歌曲地址" onclick="changeurl();">
<input type=button value="显示歌曲" title="在列表框中的第一行处显示正在播放的歌曲,以便查看或删除" onclick="listwin.document.all[ eval( 'listindex' + current ) ].scrollIntoView(true) ">
<input type=checkbox title="打扣后就只是重复播放正在播放的歌曲" onclick="if(this.checked){ player.settings.playCount = 999; }else{ player.settings.playCount = 1; }">重复播放
<input id=showtxt type=checkbox title="打扣后一播放歌曲就自动搜索并显示歌词" onclick="if(this.checked){ play2showtxt(); txtdiv.style.display = ''; }else{ txtdiv.style.display = 'none'; }">显示歌词
<input id=buffertime title="只能输入大于0的数字; 你能够忍耐的一首歌曲从找到地址到播放的最长的时间(秒).超过这个时间的地址将被抛弃而再寻找此时间短的地址来播放" style="width:20px">秒忍耐上限

<OBJECT ID="player" classID="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="width:100%;height:65px;" title="免打扰请选择静音或在播放时选择暂停">
<PARAM name="autoStart" value="0">
<PARAM name="windowlessVideo" value="0">
<PARAM name="volume" value="100">
<PARAM name="uiMode" value="full">
<PARAM name="rate" value="1.0">
<PARAM name="playCount" value="1">
<PARAM name="mute" value="0">
<PARAM name="invokeURLs" value="0">
</OBJECT>

<div id=listwindiv style="width:100%">
<iframe id="listwin" src="播放列表.html" style="width:100%; height:100%;" ></iframe>
</div>

<div id=txtdiv name=txtdiv style="display:none; padding: 0px; margin: 0px; left:500px; top:58px; width:497px; height:635px; background-color:transparent; position:absolute;color: red" onmouseup="if(parseInt(this.style.left) < 0){this.style.left = 0;}if(parseInt(this.style.top) < 0){this.style.top = 0;}" title="按住可移动此框">
<div style="font-size: 50%;cursor:hand;background-color:#666666;border:1 solid #666666;width:100%;" align="center" onmousedown="movestart(this,'txtdiv')" onmousemove="moving('txtdiv')" onmouseup="moveend()"> </div>
<iframe id="txtwin" style="width:100%; height:100%; "></iframe>
</div>

<script language="javascript" for=player event=playstateChange(playstate)>
switch(playstate)
{
case 1: //stop
clearTimeout( stop2nexttimer );
stop2nexttimer = setTimeout( "nextlist( )", 300 );
break;
}
</script>

<script language="javascript" for=player event=error()> changeurl( ); </script>

<script language="javascript" for=player event=Buffering(Start)>

if( Start == 0 )
{
clearTimeout( buffertimer );
}

</script>

<script>

function listwin.document.ondblclick()
{
var where = listwin.event.srcElement;
if( where.tagName == "A")
{
eval( "searchwin" + current + ".location = 'about:blank'");
eval( "listindex" + current + " = where.sourceIndex" );
setlistindex( current );
}
}

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧