下载

2下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 百度文库下载器源代码

百度文库下载器源代码.doc

百度文库下载器源代码

fanqiang2001
2011-06-24 0人阅读 举报 0 0 暂无简介

简介:本文档为《百度文库下载器源代码doc》,可适用于IT/计算机领域

百度文库下载器源代码文件结构Zlib用于豆丁文档的解压缩自己网上找开源代码我也网上下载的由于文件较多所以没有贴出来如果需要跟帖我可以给链接DOCINCS是支持豆丁网的下载类由于还不支持V版本所以暂时不公开GlobalcsusingSystemusingSystemTextusingSystemXmlusingSystemIOusingzlibnamespaceDocDown{publicclassGlobal{publicclassDATAREGEXS{publicstaticreadonlystringURL="^((http:wwwdocincompd{}html)|(http:wenkubaiducomviewaz{}html))$"publicstaticreadonlystringDOCINDOCINFO="^sS*playcontent=({*})sS*$"publicstaticreadonlystringBAIDUDOCINFO="^sS*DOCINFO=({*})sS*$"publicstaticreadonlystringBAIDUDATA="^({sS})sS*((CWS|FWS)tsS*)$"publicstaticreadonlystringBAIDUDATAHEADER="^({sS})(sS)$"publicstaticreadonlystringBAIDUDATASWF="(CWS|FWS)tsS*(=(CWS|FWS)t|$)"}publicclassDATAURLFROMAT{publicstaticreadonlystringBAIDUDATAURLTXT="http:wenkubaiducomplay{}pn={}rn={}"publicstaticreadonlystringBAIDUDATAURLNOTTXT="http:aiwenkubaiducomplay{}pn={}rn={}"publicstaticreadonlystringDOCINDATAURLONE="http:fileyimkcomdocin{}docin"publicstaticreadonlystringDOCINDATAURLNext="http:fileyimkcomdocin{}{}docin"}publicclassFILEPATH{publicstaticreadonlystringTEMPSMALLPATH="TEMP"publicstaticreadonlystringTEMPFULLPATH="{}TEMP"publicstaticreadonlystringSWFSMALLPATH="TEMP{}SWF"publicstaticreadonlystringSWFFULLPATH="{}TEMP{}SWF"publicstaticreadonlystringJPGSMALLPATH="TEMP{}JPG"publicstaticreadonlystringJPGFULLPATH="{}TEMP{}JPG"publicstaticreadonlystringPDFFULLPATH="{}{}PDF"publicstaticreadonlystringTXTFULLPATH="{}{}TXT"publicstaticreadonlystringDOCINPATH="TEMP{}DOCIN"publicstaticreadonlystringDOCINHEADER="TEMPHEADDATA"publicstaticreadonlystringDOCINSWF="TEMPSWFDATA"}publicclassFILEENCODING{publicstaticreadonlyEncodingEN=EncodingGetEncoding("Windows")publicstaticreadonlyEncodingCN=EncodingGetEncoding("GB")publicstaticreadonlyEncodingFTF=Encoding}publicclassJPGSIZE{publicstaticreadonlyintW=publicstaticreadonlyintH=}publicclassWORKSTATUSINFO{publicstaticreadonlystringSTARTWORK="正在下载文库资源文件。。。"publicstaticreadonlystringCREATESWF="正在生成SWF文件。。。"publicstaticreadonlystringCONVERTJPG="正在转换资源文件。。。"publicstaticreadonlystringCREATEPDF="正在生成PDF文件。。。"publicstaticreadonlystringDOWNERROR="下载资源失败请重新提交任务。"publicstaticreadonlystringSUCCESS="任务已完成。"publicstaticreadonlystringBUSY="处理中。。。"publicstaticreadonlystringSTART="开始"publicstaticreadonlystringURLERROR="文库地址解析错误请确认文库地址的正确性。"publicstaticreadonlystringDOCINDOWN="正在下载第{}个资源"publicstaticreadonlystringDOCINDOWNERROR="下载第{}个资源失败豆丁服务器异常请重新尝试下载。"}publicclassWEBDOMAIN{publicstaticreadonlystringBAIDU="BAIDU"publicstaticreadonlystringDOCIN="DOCIN"}publicenumDOCTYPE{DOC,PDF,PPT,XLS,TXT}publicstaticvoidClear(){if(DirectoryExists("temp"))DirectoryDelete("temp",true)}publicstaticvoidDecompress(stringinFile,stringoile){SystemIOFileStreamoileStream=newSystemIOFileStream(oile,SystemIOFileModeCreate)ZOutputStreamoutZStream=newZOutputStream(oileStream)SystemIOFileStreaminFileStream=newSystemIOFileStream(inFile,SystemIOFileModeOpen)try{bytebuffer=newbyteintlenwhile((len=inFileStreamRead(buffer,,))>){outZStreamWrite(buffer,,len)}outZStreamFlush()}finally{outZStreamClose()oileStreamClose()inFileStreamClose()}}publicstaticvoidDecompress(StreaminStream,longlength,stringoile){FileStreamoileStream=newFileStream(oile,FileModeCreate)ZOutputStreamoutZStream=newZOutputStream(oileStream)try{bytebuffer=newbytewhile(length>){if(length>=){inStreamRead(buffer,,)outZStreamWrite(buffer,,)length=}else{inStreamRead(buffer,,(int)length)outZStreamWrite(buffer,,(int)length)break}}outZStreamFlush()}finally{outZStreamClose()oileStreamClose()}}}}IworkcsusingSystemusingSystemCollectionsGenericusingSystemTextnamespaceDocDown{interfaceIwork{voidRun()}}WorkcsusingSystemusingSystemTextusingSWFToImageusingiTextSharptextusingiTextSharptextpdfusingSystemIOnamespaceDocDown{publicabstractclassWork:Iwork{protectedfrmMainfrmMainprotectedboolflag=falseprotectedinttotalPagepublicWork(frmMainfrmMain){thisfrmMain=frmMain}protectedvoidGetJPG(){frmMainChangelblMsgText(GlobalWORKSTATUSINFOCONVERTJPG)frmMainChangepbarMainState()SWFToImageObjectobj=newSWFToImageObject()objImageWidth=GlobalJPGSIZEWobjImageHeight=GlobalJPGSIZEHobjImageOutputType=SWFToImageTImageOutputTypeiotJPGfor(inti=i<=totalPagei){objInputSWFFileName=stringFormat(GlobalFILEPATHSWFFULLPATH,AppDomainCurrentDomainBaseDirectory,i)objExecute()objSaveToFile(stringFormat(GlobalFILEPATHJPGSMALLPATH,i))frmMainChangepbarMainState(*itotalPage)}}protectedvoidGetPDF(){frmMainChangelblMsgText(GlobalWORKSTATUSINFOCREATEPDF)Documentdoc=newDocument(PageSizeA,,,,)PdfWriterGetInstance(doc,newFileStream(stringFormat(GlobalFILEPATHPDFFULLPATH,frmMainDOCINFOPDFSAVEDIR,frmMainDOCINFODOCNAME),FileModeCreate))docOpen()StreamReadersr=for(inti=i<=totalPagei){sr=newStreamReader(stringFormat(GlobalFILEPATHJPGSMALLPATH,i))docAdd(iTextSharptextImageGetInstance(srBaseStream))srClose()}docClose()}publicabstractvoidRun()protectedvoidDownError(){DownError()}protectedvoidDownError(intpage){if(==page)frmMainChangelblMsgText(GlobalWORKSTATUSINFODOWNERROR)elsefrmMainChangelblMsgText(stringFormat(GlobalWORKSTATUSINFODOCINDOWNERROR,page))frmMainChangeBtnSubmitText(true)flag=trueGlobalClear()}}}UrlRequestcsusingSystemusingSystemNetusingSystemIOusingSystemTextusingSystemTextRegularExpressionsnamespaceDocDown{publicclassUrlRequest{publicstaticHttpWebResponseSend(stringurl){intx=HttpWebRequesthwrABC:try{hwr=(HttpWebRequest)WebRequestCreate(url)hwrMethod="GET"hwrKeepAlive=falsereturn(HttpWebResponse)hwrGetResponse()}catch{if(x!=){xgotoABC}elsereturn}}publicstaticstringGetText(stringurl,Encodingenc){stringstr=stringEmptyStreamReaderreader=Streamstream=try{WebResponseresponse=Send(url)if(==response)returnstringEmptystream=responseGetResponseStream()reader=newStreamReader(stream,enc)str=readerReadToEnd()}finally{if(!=stream){streamClose()readerClose()}}returnstr}publicstaticstringGetJson(stringvalue,stringkey){returnRegexReplace(value,stringFormat("{{*{}:"(*)"*}}",key),"$")}publicstaticstringGetJsons(stringvalue,stringkey){returnRegexReplace(value,stringFormat("{{*{}:(*)*}}",key),"$")}}}DOCINFOcsusingSystemusingSystemTextnamespaceDocDown{publicclassDOCINFO{publicstringDOCINFOpublicstringDOCIDpublicstringDOCNAMEpublicstringDOCTYPEpublicinttotalpagepublicintCONSUCpublicintPAGENUMBERpublicstringDATAURLpublicstringDATAREGEXpublicstringDATAPAGEREGEXpublicstringPDFSAVEDIRpublicstringDOMAINpublicstringRN}}frmMaincsusingSystemusingSystemTextusingSystemWindowsFormsusingSystemTextRegularExpressionsusingSystemIOusingSystemThreadingnamespaceDocDown{publicpartialclassfrmMain:Form{#regionDOCpublicDOCINFODOCINFO#endregion#region其他privateThreadGetPDF=#endregion#regiondelegatedelegatevoidbtnSubmitCallback(boolvalue)delegatevoidpbarMainCallback(intvalue)delegatevoidlblMsgCallback(stringvalue)publicvoidChangeBtnSubmitText(boolvalue){if(thisbtnSubmitInvokeRequired)thisbtnSubmitInvoke(newbtnSubmitCallback(ChangeBtnSubmitText),newobject{value})else{thisbtnSubmitEnabled=valuethisbtnSubmitText=value"开始":"处理中。。。"}}publicvoidChangepbarMainState(intvalue){if(thispbarMainInvokeRequired)thispbarMainInvoke(newpbarMainCallback(ChangepbarMainState),newobject{value})elsethispbarMainValue=value>:value}publicvoidChangelblMsgText(stringvalue){if(thislblMsgInvokeRequired)thislblMsgInvoke(newlblMsgCallback(ChangelblMsgText),newobject{value})elsethislblMsgText=value}#endregionpublicfrmMain(){InitializeComponent()}privatevoidbtnSubmitClick(objectsender,EventArgse){DOCINFO=newDOCINFO()Iworkwork=#region文件地址有效性判断if(!RegexIsMatch(txtUrlTextTrim(),GlobalDATAREGEXSURL,RegexOptionsIgnoreCase)){MessageBoxShow(GlobalWORKSTATUSINFOURLERROR)return}Matchmm=RegexMatch(UrlRequestGetText(txtUrlTextTrim(),GlobalFILEENCODINGCN),GlobalDATAREGEXSBAIDUDOCINFO)if(mmSuccess){DOCINFODOMAIN="BAIDU"gotoFLAG}mm=RegexMatch(UrlRequestGetText(txtUrlTextTrim(),Encoding),GlobalDATAREGEXSDOCINDOCINFO)if(mmSuccess){DOCINFODOMAIN="DOCIN"gotoFLAG}MessageBoxShow(GlobalWORKSTATUSINFOURLERROR)return#endregionFLAG:#region初始化信息初始化界面控件lblMsgText=stringEmptypbarMainValue=btnSubmitEnabled=falsefbdSaveDirShowDialog()btnSubmitText=GlobalWORKSTATUSINFOBUSY初始化文件信息if(GlobalWEBDOMAINBAIDU==DOCINFODOMAIN){DOCINFODOCINFO=mmGroupsValueDOCINFODOCID=UrlRequestGetJson(DOCINFODOCINFO,"docid")DOCINFODOCNAME=UrlRequestGetJson(DOCINFODOCINFO,"docname")DOCINFODOCTYPE=UrlRequestGetJson(DOCINFODOCINFO,"doctype")if(GlobalDOCTYPETXTToString()==DOCINFODOCTYPEToUpper()){DOCINFORN=""DOCINFODATAURL=GlobalDATAURLFROMATBAIDUDATAURLTXTDOCINFODATAREGEX=GlobalDATAREGEXSBAIDUDATAHEADER}else{DOCINFODATAURL=GlobalDATAURLFROMATBAIDUDATAURLNOTTXTDOCINFODATAREGEX=GlobalDATAREGEXSBAIDUDATADOCINFODATAPAGEREGEX=GlobalDATAREGEXSBAIDUDATASWFDOCINFORN=""}work=newBAIDU(this)}else{DOCINFODOCINFO=mmGroupsValueDOCINFODOCID=RegexReplace(txtUrlTextTrim()ToLower(),"http:wwwdocincomp(d)html","$")DOCINFODATAURL=GlobalDATAURLFROMADOCINFOPAGENUMBER=intParse(UrlRequestGetJsons(DOCINFODOCINFO,""pageNum""))DOCINFODOCNAME=UrlRequestGetJsons(DOCINFODOCINFO,""pdtTitle"")Trim('"')DOCINFODOCTYPE=UrlRequestGetJsons(DOCINFODOCINFO,""pdtType"")Trim('"')DOCINFOCONSUC=intParse(UrlRequestGetJsons(DOCINFODOCINFO,""converSuccess""))work=newDOCIN(this)}其他DOCINFOPDFSAVEDIR=fbdSaveDirSelectedPath初始化临时文件目录if(!DirectoryExists(GlobalFILEPATHTEMPSMALLPATH))DirectoryCreateDirectory(GlobalFILEPATHTEMPSMALLPATH)#endregion#region启动线程GetPDF=newThread(newThreadStart(workRun))GetPDFIsBackground=trueGetPDFStart()#endregion}privatevoidfrmMainFormClosing(objectsender,FormClosingEventArgse){GlobalClear()}}}BAIDUcsusingSystemusingSystemCollectionsGenericusingSystemTextusingSystemTextRegularExpressionsusingSWFToImageusingiTextSharptextusingiTextSharptextpdfusingSystemIOnamespaceDocDown{publicclassBAIDU:Work{publicBAIDU(frmMainfrmMain):base(frmMain){}publicoverridevoidRun(){if(frmMainDOCINFODOCTYPEToUpper()==GlobalDOCTYPETXTToString()){GetTXT()}else{GetSWF()if(flag)returnGetJPG()GetPDF()}GlobalClear()frmMainChangelblMsgText(GlobalWORKSTATUSINFOSUCCESS)frmMainChangeBtnSubmitText(true)}privatevoidGetSWF(intfromPage){if(fromPage==)frmMainChangelblMsgText(GlobalWORKSTATUSINFOSTARTWORK)inttoPage=stringvalue=UrlRequestGetText(stringFormat(frmMainDOCINFODATAURL,frmMainDOCINFODOCID,fromPage,frmMainDOCINFORN),GlobalFILEENCODINGEN)if(stringIsOrEmpty(value)){DownError()return}Matchmatch=RegexMatch(value,frmMainDOCINFODATAREGEX)if(matchSuccess){stringswfinfo=matchGroupsValuetoPage=intParse(UrlRequestGetJson(swfinfo,""toPage""))if(==fromPage)totalPage=intParse(UrlRequestGetJson(swfinfo,""totalPage""))}else{DownError()return}MatchCollectionMC=RegexMatches(value,frmMainDOCINFODATAPAGEREGEX)for(inti=fromPage,j=i<=toPagei,j){SystemIOFileWriteAllText(stringFormat(GlobalFILEPATHSWFSMALLPATH,i),MCjValue,GlobalFILEENCODINGEN)frmMainChangepbarMainState(*itotalPage)}if(toPage<totalPage)GetSWF(toPage)}privatevoidGetTXT(intfromPage){if(fromPage==)frmMainChangelblMsgText(GlobalWORKSTATUSINFOSTARTWORK)inttoPage=stringvalue=UrlRequestGetText(stringFormat(frmMainDOCINFODATAURL,frmMainDOCINFODOCID,fromPage,frmMainDOCINFORN),GlobalFILEENCODINGEN)if(stringIsOrEmpty(value)){DownError()return}Matchmatch=RegexMatch(value,frmMainDOCINFODATAREGEX)if(matchSuccess){stringswfinfo=matchGroupsValuetoPage=intParse(UrlRequestGetJson(swfinfo,""toPage""))if(==fromPage)totalPage=intParse(UrlRequestGetJson(swfinfo,""totalPage""))}else{DownError()return}SystemIOFileAppendAllText(stringFormat(GlobalFILEPATHTXTFULLPATH,frmMainDOCINFOPDFSAVEDIR,frmMainDOCINFODOCNAME),matchGroupsValue,GlobalFILEENCODINGEN)frmMainChangepbarMainState(*toPagetotalPage)if(toPage<totalPage)GetTXT(toPage)}}}frmMainDesignercsnamespaceDocDown{partialclassfrmMain{<summary>Requireddesignervariable<summary>privateSystemComponentModelIContainercomponents=<summary>Cleanupanyresourcesbeingused<summary><paramname="disposing">trueifmanagedresourcesshouldbedisposedotherwise,false<param>protectedoverridevoidDispose(booldisposing){if(disposing(components!=)){componentsDispose()}baseDispose(disposing)}#regionWindowsFormDesignergeneratedcode<summary>RequiredmethodforDesignersupportdonotmodifythecontentsofthismethodwiththecodeeditor<summary>privatevoidInitializeComponent(){thisgboxUrl=newSystemWindowsFormsGroupBox()thistxtUrl=newSystemWindowsFormsTextBox()thisbtnSubmit=newSystemWindowsFormsButton()thispbarMain=newSystemWindowsFormsProgressBar()thislblMsg=newSystemWindowsFormsLabel()thisfbdSaveDir=newSystemWindowsFormsFolderBrowserDialog()thisgboxUrlSuspendLayout()thisSuspendLayout()gboxUrlthisgboxUrlControlsAdd(thistxtUrl)thisgboxUrlLocation=newSystemDrawingPoint(,)thisgboxUrlName="gboxUrl"thisgboxUrlPadding=newSystemWindowsFormsPadding(,,,)thisgboxUrlSize=newSystemDrawingSize(,)thisgboxUrlTabIndex=thisgboxUrlTabStop=falsethisgboxUrlText="文库地址"txtUrlthistxtUrlDock=SystemWindowsFormsDockStyleTopthistxtUrlLocation=newSystemDrawingPoint(,)thistxtUrlName="txtUrl"thistxtUrlSize=newSystemDrawingSize(,)thistxtUrlTabIndex=btnSubmitthisbtnSubmitLocation=newSystemDrawingPoint(,)thisbtnSubmitName="btnSubmit"thisbtnSubmitSize=newSystemDrawingSize(,)thisbtnSubmitTabIndex=thisbtnSubmitText="开始"thisbtnSubmitClick=newSystemEventHandler(thisbtnSubmitClick)pbarMainthispbarMainDock=SystemWindowsFormsDockStyleBottomthispbarMainLocation=newSystemDrawingPoint(,)thispbarMainName="pbarMain"thispbarMainSize=newSystemDrawingSize(,)thispbarMainTabIndex=lblMsgthislblMsgAutoSize=truethislblMsgLocation=newSystemDrawingPoint(,)thislblMsgName="lblMsg"thislblMsgSize=newSystemDrawingSize(,)fbdSaveDirthisfbdSaveDirDescription="PDF文件保存路径"frmMainthisAutoScaleDimensions=newSystemDrawingSizeF(F,F)thisAutoScaleMode=SystemWindowsFormsAutoScaleModeFontthisClientSize=newSystemDrawingSize(,)thisControlsAdd(thislblMsg)thisControlsAdd(thispbarMain)thisControlsAdd(thisbtnSubmit)thisControlsAdd(thisgboxUrl)thisFormBorderStyle=SystemWindowsFormsFormBorderStyleFixedSinglethisMaximizeBox=falsethisName="frmMain"thisText="百度文库下载器"thisFormClosing=newSystemWindowsFormsFormClosingEventHandler(thisfrmMainFormClosing)thisgboxUrlResumeLayout(false)thisgboxUrlPerformLayout()thisResumeLayout(false)thisPerformLayout()}#endregionprivateSystemWindowsFormsGroupBoxgboxUrlprivateSystemWindowsFormsTextBoxtxtUrlprivateSystemWindowsFormsButtonbtnSubmitprivateSystemWindowsFormsProgressBarpbarMainprivateSystemWindowsFormsLabellblMsgprivateSystemWindowsFormsFolderBrowserDialogfbdSaveDir}}

VIP免券下载文档

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/23

百度文库下载器源代码

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利