ASP.NET下开发MP3小偷程序

分类: asp.net技巧   出处:iocblog整理  更新时间:2009-06-27   添加到收藏  

 [www.iocblog.net 来源]

  mp3资源都在互联网上,有时听不了也是正常,但大多数不好用,真是用处不大了。仔细分析了一下它的源码,原来是读取目录下的1.xml,2.xml..4.xml文件。我经常在番茄花园听歌,也就是http://www.tomatolei.com,就想能不能把番茄的mp3资源放到这里来放呢?这不就是大家常说的mp3小偷的功能吗?说干就干!

  1、分析一下番茄花园的歌来源: pageurl = "http://tomatolei.com/bbs/t_playlist.asx";

  2、目标地址:1.xml

  3、用程序转换格式:

  前台:

<%@ page language="c#" codebehind="readandwritexml.aspx.cs" autoeventwireup="false" inherits="读取番茄花园的mp3.readandwritexml" validaterequest=false%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>读取番茄花园mp3列表</title>
<meta content="microsoft visual studio .net 7.1" name="generator">
<meta content="c#" name="code_language">
<meta content="javascript" name="vs_defaultclientscript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetschema">
</head>
<body ms_positioning="gridlayout">
<form id="form1" method="post" runat="server">
<font face="宋体">
<asp:textbox id="textbox1" style="z-index: 101; left: 56px; position: absolute; top: 32px" runat="server"
width="312px" height="240px" textmode="multiline"></asp:textbox>
<asp:button id="button1" style="z-index: 102; left: 160px; position: absolute; top: 288px" runat="server"
width="96px" text="修正~"></asp:button></font></form>
</body>
</html>

  后台:

using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.io;
using system.net;
using system.text;
using system.text.regularexpressions;
namespace 读取番茄花园的mp3
{
  /// <summary>
  /// webform1 的摘要说明。
  /// </summary>
  public class readandwritexml : system.web.ui.page
  {
   protected system.web.ui.webcontrols.textbox textbox1;
   protected system.web.ui.webcontrols.button button1;
   private string pageurl = "";

   private void page_load(object sender, system.eventargs e)
   {
    // 在此处放置用户代码以初始化页面
    if(!ispostback)
    {[www.iocblog.net 来源]
     ///首先读取番茄花园的acx文件(http://tomatolei.com/bbs/t_playlist.asx)
     ///
     pageurl = "http://tomatolei.com/bbs/t_playlist.asx";
     webclient wc = new webclient();
     wc.credentials = credentialcache.defaultcredentials;
     byte[] pagedata = wc.downloaddata(pageurl);
     string result = encoding.default.getstring(pagedata);
     textbox1.text=result;

    }
   }

   #region web 窗体设计器生成的代码
   override protected void oninit(eventargs e)
   {
    //
    // codegen: 该调用是 asp.net web 窗体设计器所必需的。
    //
    initializecomponent();
    base.oninit(e);
   }

   /// <summary>
   /// 设计器支持所需的方法 - 不要使用代码编辑器修改
   /// 此方法的内容。
   /// </summary>
   private void initializecomponent()
   {
    this.button1.click += new system.eventhandler(this.button1_click);
    this.load += new system.eventhandler(this.page_load);
   }
   #endregion

   private void button1_click(object sender, system.eventargs e)
   {
    string temp=textbox1.text;
    textbox1.text="<musics firstrun="1">";
    textbox1.text+=temp;

    textbox1.text=textbox1.text.replace("<asx version=3.0>","");
    textbox1.text=textbox1.text.replace("<param name="allowshuffle" value="yes"/> ","");
    textbox1.text=textbox1.text.replace("</asx>","");

    textbox1.text=textbox1.text.replace("</entry>","");
    textbox1.text=textbox1.text.replace("<entry>","");

    textbox1.text=textbox1.text.replace("<title>","<music name="");
    textbox1.text=textbox1.text.replace("</title>",""");
 
    textbox1.text=textbox1.text.replace("<ref href=","addres=");

    textbox1.text+="</musics>";

    //textbox1.text=textbox1.text.replace(" ","");
    /// 下面开始生成 1.xml文件
    ///
    streamwriter swfromfilestreamutf8buffer=new streamwriter(server.mappath("./")+"1.xml",false,system.text.encoding.utf8,512);
    swfromfilestreamutf8buffer.write(textbox1.text);
    swfromfilestreamutf8buffer.flush();
    swfromfilestreamutf8buffer.close();
   }
  }
}



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。