|=qX#Bq,v 9CSbappPath-C:\Program Files\BitTorrent\btdownloadgui.exe flEnabledhourToStartScanhourToStopScan maxPerDay pp?;qRTp torrentDownloads? b so.q,p  $ 1prefs<statsF torrentQueueysVq,p  $= I  p  author Andrew Grumet authorEmailaegrumet@alum.mit.edu descriptionVAutomates launch of the BitTorrent client for .torrent files downloaded as enclosures. homePageUrl;http://grumet.net/rssBitTorrentIntegration/radioClient.htmlnamebitTorrentIntegration releaseDateversion0.3Arial q,q,}LANDwinThis script runs every hour. XT Arial q,qg#k5LANDwinThis script runs every minute. Changes 3/7/04; 7:51:52 PM by AG Created. if not tcp.isOffline () if user.bitTorrentIntegration.prefs.flEnabled if not defined (system.temp.radio.misc.flScanningForBitTorrents) system.temp.radio.misc.flScanningForBitTorrents = false if not system.temp.radio.misc.flScanningForBitTorrents local (day, month, year, hour, minute, second) date.get (clock.now (), @day, @month, @year, @hour, @minute, @second) if hour >= user.bitTorrentIntegration.prefs.hourToStartScan if hour < user.bitTorrentIntegration.prefs.hourToStopScan thread.callScript (@bitTorrentIntegrationSuite.downloadTorrents, {}) XArial q,q,LANDwinThis script runs every night. {w.q,q`  ". 9 everyHour everyMinutet everyNight{ q, e-TArial qLpn;]LANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. local (url = string.urldecode (adrstory^.enclosure.url)) if string.hasSuffix(".torrent",url) if not defined (bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)]) new (tabletype, @bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)]) bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].filepath = f bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].flLaunched = false bundle //test code downloadEnclosure(@aggregatorData.stories.["00074106"],"ignore") 9 39-O e@<q,m downloadEnclosure@ q, nj.q,q`  ' ,fileMenu radio user n~Arial =v2?IALANDwinChanges 3/8/04; 9:12:07 AM by AG Cribbed from DW's myWeblogOutliner code. 10/23/02; 4:43:35 PM by DW Created. bitTorrentIntegrationInfo.releaseDate = clock.now () delete(@bitTorrentIntegrationData.stats.torrentDownloads) new (tabletype, @bitTorrentIntegrationData.stats.torrentDownloads) delete(@bitTorrentIntegrationData.torrentQueue) new (tabletype, @bitTorrentIntegrationData.torrentQueue) local (folder = "C:\\Program Files\\Radio UserLand\\www\\userland\\publicTools\\bitTorrentIntegration\\") f = folder + "bitTorrentIntegration.root" file.surefilepath(f) target.set (this) fileMenu.saveCopy (f) radio.thread.wake () dialog.alert (file.filefrompath (f) + " is " + string.megabytestring (file.size (f))) =9q謼q releaseNewCode=Arial q5GLANDwinon downloadTorrents () Changes: 3/7/04; 8:26:54 PM by AG Created. Scans the queue, bitTorrentIntegrationData.torrentQueue looking for not yet downloaded torrents. 3/11/04; 3:15:27 PM by AG Added a check to make sure the enclosure file exists before launching BitTorrent. Pushed the launch call into a bitTorrentIntegrationSuite.os.launchBT, which can be extended to handle OS X. system.temp.radio.misc.flScanningForBitTorrents = true on bmopathFromFilePath(s) return string.delete(s,sizeof(s)-7,infinity) //strip .torrent extension and call that the filename. local (day, month, year, hour, minute, second) date.get (clock.now (), @day, @month, @year, @hour, @minute, @second) local (logtable = string(year) + string.padwithzeros (month, 2) + string.padwithzeros (day, 2)) if not defined (bitTorrentIntegrationData.stats.torrentDownloads.[logtable]) new (tabletype, @bitTorrentIntegrationData.stats.torrentDownloads.[logtable]) local (adrtorrent, adrlogtable = @bitTorrentIntegrationData.stats.torrentDownloads.[logtable]) for adrtorrent in @bitTorrentIntegrationData.torrentQueue if not (adrtorrent^.flLaunched) && (sizeOf(adrlogtable^) < user.bitTorrentIntegration.prefs.maxPerDay) bmopath = bmopathFromFilePath(adrtorrent^.filepath) if file.exists (adrtorrent^.filepath) bitTorrentIntegrationSuite.osspecific.launchBT(adrtorrent^.filepath, bmopath) adrtorrent^.flLaunched = true adrtorrent^.bmopath = bmopath bundle //add it to the table of already-downloaded torrents adrlogtable^.[nameOf(adrtorrent^)] = adrtorrent^ system.temp.radio.misc.flScanningForBitTorrents = false bundle //test code downloadTorrents() [8xkArial q2#8B"MLANDwinChanges: 3/7/04; 8:13:20 PM by AG Created. 5/6/04; 10:42:40 PM by AG Removed callback installation code, which was broken and unnecessary. if not defined (user.bitTorrentIntegration) new (tabletype, @user.bitTorrentIntegration) bundle //prefs if not defined (user.bitTorrentIntegration.prefs) new (tabletype, @user.bitTorrentIntegration.prefs) if not defined (user.bitTorrentIntegration.prefs.flEnabled) user.bitTorrentIntegration.prefs.flEnabled = bitTorrentIntegrationData.prefs.flEnabled if not defined (user.bitTorrentIntegration.prefs.appPath) user.bitTorrentIntegration.prefs.appPath = bitTorrentIntegrationData.prefs.appPath if not defined (user.bitTorrentIntegration.prefs.hourToStartScan) user.bitTorrentIntegration.prefs.hourToStartScan = bitTorrentIntegrationData.prefs.hourToStartScan if not defined (user.bitTorrentIntegration.prefs.hourToStopScan) user.bitTorrentIntegration.prefs.hourToStopScan = bitTorrentIntegrationData.prefs.hourToStopScan if not defined (user.bitTorrentIntegration.prefs.maxPerDay) user.bitTorrentIntegration.prefs.maxPerDay = bitTorrentIntegrationData.prefs.maxPerDay 8}8N@h 3e-OX[0Arial q,qLANDwinbitTorrentIntegrationSuite.menuCommands.setup() Arial q,qSlLANDwinBitTorrentIntegration Set Up p BVArial 6p |Arial q㭼q^&LANDwinon setup () bitTorrentIntegrationSuite.init() edit(@user.bitTorrentIntegration) window.zoom(@user.bitTorrentIntegration)  40q㦼q setup!4$Arial v/Lv0(i@LANDwinon launchBT (filepath,bmopath) Changes: 3/11/04; 3:01:46 PM by AG Added Windows support. if (sys.os() == "WinNT") launch.appWithDocument(user.bitTorrentIntegration.prefs.appPath,"\"" + filepath + "\" --saveas \"" + bmopath + "\"") 73v.ov/Z launchBT#*7 }Arial q,q,tLANDwinThis script returns a string which appears in the Status Center on the Radio UserLand home page. return ("I'm a cool Tool!") HDjq,v0n  !- ;G Xd iu z background callbacks codeFreshenergdownloadTorrentsinitUmenu!V menuCommands" osspecific$statusCenterMessage%HArial q,q,wLANDwinThis script runs in its own thread. loop //loop until the application quits Add your code here. thread.sleepFor (10) //sleep for ten seconds TP.q,q, ctenabledscript'fTtArial FF2LANDwinon finalFilter (pta) pta^.renderedText = string.replace (pta^.renderedText, "[[title]]", "") return (true) ����������������������������� ���-���� MS Sans Serif��������������������� ��������������Eu`Q�������2LAND�������win������������on firstFilter (adrPageTable) return (true) �����������������������*��[���� MS Sans Serif��������������������� ��������������Eu7a���m���L�3*lLAND�������win������������on pageFilter (pta) if typeOf (pta^.template) == outlineType or typeOf (pta^.template) == wpTextType table.assign (@pta^.template, string (pta^.template)) if typeOf (pta^.template) == stringType and not pta^.indirectTemplate pta^.template = string.replace (pta^.template, "<title>", "[[title]]") html.addPageToGlossary (pta) return (true) �����������������������������������������������y���.���EF�������� ���� ��� ����$���0 ����; finalFilter�������( firstFilter�������) pagefilter�������*��V MS Sans Serif��������������������� �����������P�E��$����������������������������Q�������M������7q,�������� ����url���'http://127.0.0.1/bitTorrentIntegration/���Q��O�������X���$����������� ���� ��� ������+���������-���+����� ����������O����������/����������c�������� ����Home�������?��VArial����������������������������� ����������������������������������������������������������W����������������������space���/GIFfGIF89a�������!����,�������D�;��VArial����������������������������� ������������������������������������������������������������V��������������� ������� �������"�������+ ����0���: ����C���L ����Q���[ ����aalink���008000bgcolor���FFFFFFflRenderlink���0000FFspaceGif���spacetext���000000vlink���800080��VArial����������������������������� �������������������������������������������������d��������<��������Arial����������������������������� ��������������FF�������LAND�������win������������<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>{title} {metaTags ()} {bodyTag ()} {bodytext} dn8>VArial nFFFF000000060001001777AA00000000005A0000000010017101904900218000006000600329200-1032921FFFFF010E0000100000031000000010E84032921FE048E000163293000020000001200000000E,#title "Home" 000400000009000000020100000500000009000000020100000600000032000000010F310FFFF0C00000 20 000700000019000000010201E00008000000A90000000140,Geneva40,10A0304E44000101000090000001500000002096177096177000A000000150000000232921F32921F000B00000005000000020000C0000001200000001E369AF10000F0000005200000000400 10 4,appn4,send4,84,&4,84,34,800130000007E00000000DA91F8CE1C1D1E1F7F1B044,-..'"FFFF0FFFF0FFFE000000060001001777AAPĵ7}5#``7F  * 4@ HT [g q} #filters,#ftpSite- #glossary.X#images.#prefs/ #template0#tools2Eindex2VVerdana ??8`N 3Bq,o & @L gs bitTorrentIntegrationDatabitTorrentIntegrationInfo<bitTorrentIntegrationSuite&bitTorrentIntegrationThread(bitTorrentIntegrationWebsite7OVE Arial q,pDLANDwinbitTorrentIntegrationData bitTorrentIntegrationInfo bitTorrentIntegrationSuite background callbacks codeFreshener releaseNewCode downloadTorrents init menu menuCommands osspecific statusCenterMessage bitTorrentIntegrationThread bitTorrentIntegrationWebsite 3 *3 08@h 3e-OXNPVq, 9CWsappPath-C:\Program Files\BitTorrent\btdownloadgui.exe flEnabledflGetLinkedTorrentsflTorrentOverridesEnclosurehourToStartScanhourToStopScan maxPerDayVArial 2PIArial  MS Sans Serif -  Times New Roman! nArial #_Arial MS Sans Serif c{fff 73pf 20041001{cOK$cc  linetextHomepath index.wsfO OArial qLUJgLANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) if adrPrefs^.flGetLinkedTorrents // 01/10/04; 8:53:32 AM by PR get linked torrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match local (torrentList = {}) regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) for torrentUrl in torrentList if !torrents contains torrentUrl torrents[sizeOf(torrens+1)] = torrentUrl local (url = string.urldecode (adrstory^.enclosure.url)) if string.hasSuffix(".torrent",url) if !torrents contains url torrents[sizeOf(torrens+1)] = torrentUrl if sizeOf (torrents) > 1 if defined (adrPrefs^.flTorrentOverridesEnclosure) if adrPrefs^.flTorrentOverridesEnclosure if not file.exists (f) file.writewholefile (f, "trick radio into thinking we've downloaded this file") for i = 1 to sizeOf (torrents) // loop through all the torrents we've gathered if not defined (bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) new (tabletype, @bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) if i > 1 local (filepath = "") local (folder = file.folderFromPath (f) bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].filepath = filepath else bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].filepath = f bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].flLaunched = false bundle //test code downloadEnclosure(@aggregatorData.stories.["00035912"],"ignore") <@@ <O}[8N 3e-OX  Bq,o & @L gs bitTorrentIntegrationDatabitTorrentIntegrationInfo<bitTorrentIntegrationSuite&bitTorrentIntegrationThread(bitTorrentIntegrationWebsite7OV^:G' cArial q,LRLANDwinbitTorrentIntegrationData bitTorrentIntegrationInfo bitTorrentIntegrationSuite background callbacks fileMenu radio downloadEnclosure user codeFreshener releaseNewCode downloadTorrents init menu menuCommands setup osspecific launchBT statusCenterMessage bitTorrentIntegrationThread ct enabled script bitTorrentIntegrationWebsite p *p *p *p p*p p*p *p *p *p *p p*p *p p*p p*p p*p p*p *p p*p *p p*p *p *p *p *p *} Arial q2#uC"MLANDwinChanges: 3/7/04; 8:13:20 PM by AG Created. 5/6/04; 10:42:40 PM by AG Removed callback installation code, which was broken and unnecessary. 01/10/04; 9:22:04 AM by PR just copy all the prefs from bitTorrentIntegration data instead of checking for them one by one if not defined (user.bitTorrentIntegration) new (tabletype, @user.bitTorrentIntegration) bundle //prefs if not defined (user.bitTorrentIntegration.prefs) new (tabletype, @user.bitTorrentIntegration.prefs) if not defined (user.bitTorrentIntegration.prefs.flEnabled) user.bitTorrentIntegration.prefs.flEnabled = bitTorrentIntegrationData.prefs.flEnabled if not defined (user.bitTorrentIntegration.prefs.appPath) user.bitTorrentIntegration.prefs.appPath = bitTorrentIntegrationData.prefs.appPath if not defined (user.bitTorrentIntegration.prefs.hourToStartScan) user.bitTorrentIntegration.prefs.hourToStartScan = bitTorrentIntegrationData.prefs.hourToStartScan if not defined (user.bitTorrentIntegration.prefs.hourToStopScan) user.bitTorrentIntegration.prefs.hourToStopScan = bitTorrentIntegrationData.prefs.hourToStopScan if not defined (user.bitTorrentIntegration.prefs.maxPerDay) user.bitTorrentIntegration.prefs.maxPerDay = bitTorrentIntegrationData.prefs.maxPerDay @8O}[8N 3e-OX0. Arial q2#җE"JLANDwinChanges: 3/7/04; 8:13:20 PM by AG Created. 5/6/04; 10:42:40 PM by AG Removed callback installation code, which was broken and unnecessary. 01/10/04; 9:22:04 AM by PR just copy all the prefs from bitTorrentIntegration data instead of checking for them one by one if not defined (user.bitTorrentIntegration) new (tabletype, @user.bitTorrentIntegration) bundle //prefs if not defined (user.bitTorrentIntegration.prefs) new (tabletype, @user.bitTorrentIntegration.prefs) user.bitTorrentIntegration.prefs = bitTorrentIntegrationData.prefs if not defined (user.bitTorrentIntegration.prefs.flEnabled) user.bitTorrentIntegration.prefs.flEnabled = bitTorrentIntegrationData.prefs.flEnabled if not defined (user.bitTorrentIntegration.prefs.appPath) user.bitTorrentIntegration.prefs.appPath = bitTorrentIntegrationData.prefs.appPath if not defined (user.bitTorrentIntegration.prefs.hourToStartScan) user.bitTorrentIntegration.prefs.hourToStartScan = bitTorrentIntegrationData.prefs.hourToStartScan if not defined (user.bitTorrentIntegration.prefs.hourToStopScan) user.bitTorrentIntegration.prefs.hourToStopScan = bitTorrentIntegrationData.prefs.hourToStopScan if not defined (user.bitTorrentIntegration.prefs.maxPerDay) user.bitTorrentIntegration.prefs.maxPerDay = bitTorrentIntegrationData.prefs.maxPerDay 0X@;Arial qLHVJgLANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) if adrPrefs^.flGetLinkedTorrents // 01/10/04; 8:53:32 AM by PR get linked torrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match local (torrentList = {}) regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) for torrentUrl in torrentList if !torrents contains torrentUrl torrents[sizeOf(torrens+1)] = torrentUrl local (url = string.urldecode (adrstory^.enclosure.url)) if string.hasSuffix(".torrent",url) if !torrents contains url torrents[sizeOf(torrens+1)] = torrentUrl if sizeOf (torrents) > 1 if defined (adrPrefs^.flTorrentOverridesEncXX b[X@ O}[8N 3e-OXXokQQ4pQ 000359121aVArial }5^M84pײ 000359121b8[ײײ % Arial qLcJgLANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) if adrPrefs^.flGetLinkedTorrents // 01/10/04; 8:53:32 AM by PR get linked torrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) for torrentUrl in torrentList if !(torrents contains torrentUrl) torrents[sizeOf(torrents+1)] = torrentUrl local (url = string.urldecode (adrstory^.enclosure.url), flEnclosureIsTorrent = false) if string.hasSuffix(".torrent",url) flEnclosureIsTorrent = true if !torrents contains url torrents[sizeOf(torrens+1)] = torrentUrl if sizeOf (torrents) > 0 && !flEnclosureIsTorrent // check to see if we should stop Radio from downloading the enclosure if defined (adrPrefs^.flTorrentOverridesEnclosure) if adrPrefs^.flTorrentOverridesEnclosure if not file.exists (f) file.surefilepath (f) file.writewholefile (f, "trick radio into thinking we've downloaded this file") for i = 1 to sizeOf (torrents) // loop through all the torrents we've gathered if not defined (bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) new (tabletype, @bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) local (filepath = "") bundle local (folder = file.folderFromPath (f)) local (fileName = "") bundle // get the file name from the url local (ch = string.getWordChar()) string.setWordChar ('/') fileName = string.lastWord (torrents [i]) string.setWorChar (ch) bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].filepath = filepath bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)].flLaunched = false bundle // download the file here local (urllist = string.urlSplit (torrents[i]), server = urllist [2], path = urllist [3]) local (httpresult = string.httpResultSplit (tcp.httpClient (server:server, path:path, timeOutTicks:60*60, flMessages:false))) file.surefilepath (filepath) file.writewholefile (filepath, httpresult) bundle //test code downloadEnclosure(@aggregatorData.stories.["00035912"],"K:\\Program Files\\Radio UserLand\\enclosures\\2004\\10\\01\\egc-9-30-2004.mp3") & $Arial qL=dJgLANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) if adrPrefs^.flGetLinkedTorrents // 01/10/04; 8:53:32 AM by PR get linked torrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) for torrentUrl in torrentList if !(torrents contains torrentUrl) torrents[sizeOf(torrents+1)] = torrentUrl local (url = string.urldecode (adrstory^.enclosure.url), flEnclosureIsTorrent = false) if string.hasSuffix(".torrent",url) flEnclosureIsTorrent = true if !torrents contains url torrents[sizeOf(torrens+1)] = torrentUrl if sizeOf (torrents) > 0 && !flEnclosureIsTorrent // check to see if we should stop Radio from downloading the enclosure if defined (adrPrefs^.flTorrentOverridesEnclosure) if adrPrefs^.flTorrentOverridesEnclosure if not file.exists (f) file.surefilepath (f) file.writewholefile (f, "trick radio into thinking we've downloaded this file") for i = 1 to sizeOf (torrents) // loop through all the torrents we've gathered if not defined (bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) new (tabletype, @bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) local (filepath = "") bundle local (folder = file.folde.\ٸ S \bmopathGK:\Program Files\Radio UserLand\enclosures\2004-10-01\egc-9-30-2004.mp3filepathOK:\Program Files\Radio UserLand\enclosures\2004-10-01\egc-9-30-2004.mp3.torrent flLaunched.\ٸ S \bmopathGK:\Program Files\Radio UserLand\enclosures\2004-10-01\egc-9-30-2004.mp3filepathOK:\Program Files\Radio UserLand\enclosures\2004-10-01\egc-9-30-2004.mp3.torrent flLaunched?7 {fOaok b[X@ O}[8N 3e-OX2004.mp3.torrent flLaunchedT$pHy  000359121wC 000368241VArial o>? 潂wKLANDwin000359121 filepath flLaunched 3 8;3 q3 qOaok  b[X@ O}[8N 3O84fٸ 000359121x?8y;8 Arial qLk?\LANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. 01/10/04; 10:24:31 AM by PR added support for torrents linked to in the storyText local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) if adrPrefs^.flGetLinkedTorrents // 01/10/04; 8:53:32 AM by PR get linked torrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) for torrentUrl in torrentList if !(torrents contains torrentUrl) torrents[sizeOf(torrents+1)] = torrentUrl local (url = string.urldecode (adrstory^.enclosure.url), flEnclosureIsTorrent = false) if string.hasSuffix(".torrent",url) flEnclosureIsTorrent = true if !(torrents contains url) // cgh torrents[sizeOf(torrens+1)] = torrentUrl if sizeOf (torrents) > 0 && !flEnclosureIsTorrent // check to see if we should stop Radio from downloading the enclosure if defined (adrPrefs^.flTorrentOverridesEnclosure) if adrPrefs^.flTorrentOverridesEnclosure if not file.exists (f) file.surefilepath (f) file.writewholefile (f, "trick radio into thinking we've downloaded this file") for i = 1 to sizeOf (torr|y;?7c{fOaok b[X@ O}[8N 3e-OX.HyH T ]bmopathHK:\Program Files\Radio UserLand\enclosures\2004-10-06\egc-10-05-2004.mp3filepathPK:\Program Files\Radio UserLand\enclosures\2004-10-06\egc-10-05-2004.mp3.torrent flLaunchedLp  * 3? HT ]i r20041001{200410022004100320041004200410052004100684H 0003682418.HyH T ]bmopathHK:\Program Files\Radio UserLand\enclosures\2004-10-06\egc-10-05-2004.mp3filepathPK:\Program Files\Radio UserLand\enclosures\2004-10-06\egc-10-05-2004.mp3.torrent flLaunchedii8pC  * 3? H20041001{200410022004100320041004CC񀽄 ~8 "Arial qL6p?\LANDwinon downloadEnclosure (adrstory,f) Changes: 3/7/04; 10:25:07 PM by AG Created. This script should be called from user.radio.callbacks.downloadEnclosure. It will run just before each enclosure is downloaded, and queue a BitTorrent download if the enclosure url ends in ".torrent". 5/6/04; 10:44:03 PM by AG Renamed "downloadEnclosure" from "downloadEnclosureCallback" to hook into Frontier's auto-installation code. 01/10/04; 10:24:31 AM by PR added support for torrents linked to in the storyText local (url = string.urldecode (adrstory^.enclosure.url), flEnclosureIsTorrent = false) if string.hasSuffix(".torrent",url) flEnclosureIsTorrent = true torrents[sizeOf(torrens+1)] = torrentUrl local (adrPrefs = @user.bitTorrentIntegration.prefs, torrents = {}) if defined (adrPrefs^.flGetLinkedTorrents) // 01/10/04; 8:53:32 AM by PR get linked torrents if adrPrefs^.flGetLinkedTorrents if defined (adrStory^.storyText) // check for story text local (storyText = adrStory^.storyText) if storyText contains ".torrent" // we have a match regex.extract ("http://[^\"]*\.torrent", @storyText, @torrentList) // regex expression to find http://...anything... .torrent for torrentUrl in torrentList // make sure we don't already have this torrent in the list... if !(torrents contains torrentUrl) torrents[sizeOf(torrents+1)] = torrentUrl if sizeOf (torrents) > 0 && !flEnclosureIsTorrent // check to see if we should stop Radio from downloading the enclosure the point of the tool is to NOT download the full enclosure if we have a bit torrent version of it linked if defined (adrPrefs^.flTorrentOverridesEnclosure) if adrPrefs^.flTorrentOverridesEnclosure if not file.exists (f) file.surefilepath (f) file.writewholefile (f, "trick radio into thinking we've downloaded this file") for i = 1 to sizeOf (torrents) // loop through all the torrents we've gathered local (adrQueue = @bitTorrentIntegrationData.torrentQueue.[nameOf(adrstory^)+i]) if not defined (adrQueue^) new (tabletype, adrQueue) local (filepath = "") bundle local (folder = file.folderFromPath (f)) local (fileName = "") bundle // get the file name from the url local (ch = string.getWordChar()) string.setWordChar ('/') fileName = string.lastWord (torrents [i]) string.setWordChar (ch) filePath = folder + fileName adrQueue^.filepath = filepath adrQueue^.flLaunched = false bundle // download the file here, no guarantee radio will... local (urllist = string.urlSplit (torrents[i]), server = urllist [2], path = urllist [3]) local (httpresult = string.httpResultSplit (tcp.httpClient (server:server, path:path, timeOutTicks:60*60, flMessages:false))) file.surefilepath (filepath) file.writewholefile (filepath, httpresult) bundle //test code downloadEnclosure(@aggregatorData.stories.["00035912"],"K:\\Program Files\\Radio UserLand\\enclosures\\2004-10-01\\egc-9-30-2004.mp3") ~