home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Online / NapSearch / NapSearch.Amirx next >
Text File  |  2000-08-13  |  7KB  |  268 lines

  1. /* Napster search script for Amirc V1.0  © Purp|e 2000 :) */
  2.  
  3.  
  4. /*     C O N F I G   A R E A        */
  5.  
  6.  
  7.  
  8. AmsterPath = "DH0:Internet/Amster/Amster"
  9. AmsterPort = "AMSTER.1"
  10.  
  11. MaxHits = 4
  12.  
  13.  
  14.  
  15. /*   E N D  C O N F I G   A R E A   */
  16.  
  17.  
  18.  
  19.  
  20. Options results
  21. if exists(AmsterPath) = 0 then do
  22.    techo("Amster Not Found: "Amsterpath)
  23.    call endprog
  24. end
  25. IRCPort = address()
  26. parse arg SMode" "SearchString
  27. NL='0a'x;ES= d2c(27);Bold = d2c(2);TC = 5
  28. NotRun = "N"
  29. DebugIt = "N"
  30. If DebugIt = "Y" then do
  31.    techo("Port: "IRCPort)
  32.    techo("Mode: "smode)
  33.    techo("String: "searchstring)
  34. End
  35. If upper(SMode) = "FIND" then call FindIt
  36. If upper(smode) = "GET" then call GetIt
  37. If Upper(Smode) = "HIDE" then do
  38.    Ports = ShowList("P")
  39.    if pos(amsterport,ports) = 0 then do
  40.       techo("Error: Amster not running!")
  41.       call endprog
  42.    end
  43.    address(AMsterPort)
  44.    "HIDE"
  45. End
  46. If Upper(Smode) = "SHOW" then do
  47.    Ports = ShowList("P")
  48.    if pos(amsterport,ports) = 0 then do
  49.       techo("Error: Amster not running!")
  50.       call endprog
  51.    end
  52.    address(AMsterPort)
  53.    "SHOW"
  54. End
  55. If Upper(Smode) = "RUN" then do
  56.    Ports = ShowList("P")
  57.    if pos(amsterport,ports) ~=0 then do
  58.       techo("Error: Amster already running!")
  59.       call endprog
  60.    end
  61.    address command "Run >nil: "Amsterpath
  62.    call time(R)
  63.    do until pos(amsterport,ports) ~=0|Time(E) >20.00
  64.       Ports = ShowList("P")
  65.       delay(30)
  66.    End
  67.    if pos(amsterport,ports) = 0 then do
  68.       techo("Error! Amster Failed to load!")
  69.       call endprog
  70.    end
  71.    address(AMsterPort)
  72.    "CONNECT"
  73.    call endprog
  74. End
  75. If Upper(Smode) = "QUIT" then do
  76.    Ports = ShowList("P")
  77.    if pos(amsterport,ports) = 0 then do
  78.       techo("Error: Amster not running!")
  79.       call endprog
  80.    end
  81.    address(AMsterPort)
  82.    "SHOW"
  83.    "QUIT"
  84. End
  85. If Upper(Smode) = "QUIT" then do
  86.    Call HelpIt
  87. End
  88. If upper(smode) = "INSTALL" then DO
  89.    "say /alias /NapFind /rx NapSearch.amirx Find %p"
  90.    "say /alias /NapGet /rx NapSearch.amirx Get %p"
  91.    "say /alias /NapHide /rx NapSearch.amirx Hide"
  92.    "say /alias /NapShow /rx NapSearch.amirx Show"
  93.    "say /alias /NapRun /rx NapSearch.amirx Run"
  94.    "say /alias /NapQuit /rx NapSearch.amirx Quit"
  95.    "say /alias /NapHelp /rx NapSearch.amirx Help"
  96.    techo("Please Save your settings now!")
  97. end
  98. If upper(smode) = "HELP"|upper(smode) = "?"|upper(smode) = "" then DO
  99.    Call HelpIt
  100. End
  101. Call EndProg
  102. Exit
  103.  
  104. FindIt:
  105. techo("Searching for "bold""Searchstring""Bold" on Napster, Hits = "bold""maxhits)
  106. Ports = ShowList("P")
  107. if pos(amsterport,ports) = 0 then do
  108.    if debugit = "Y" then techo("Port not found, starting Amster...")
  109.    address command "Run >nil: "AmsterPath
  110.    NotRun = "Y"
  111. end
  112. Ports = ShowList("P")
  113. call time(R)
  114. do until pos(amsterport,ports) ~=0|Time(E) >20.00
  115.    Ports = ShowList("P")
  116.    if debugit = "Y" then techo("Waiting for port...")
  117.    delay(30)
  118. End
  119. if pos(amsterport,ports) = 0 then do
  120.    techo("Error! Amster Failed to load!")
  121.    call endprog
  122. end
  123. if debugit = "Y" then techo("Port ready!")
  124. address(AmsterPort)
  125. If NotRun = "Y" then "Hide"
  126. "ISONLINE"
  127. ison = RC
  128. address(IRCPort)
  129. if debugit = "Y" then techo("Ison: "ison)
  130. address(AMsterPort)
  131. if ison = 0 then do
  132.    "CONNECT"
  133.    checkconnect = RC
  134.    address(IRCPort)
  135.    if debugit = "Y" then techo("Check: "CheckConnect)
  136.    if checkconnect ~= 0 then do
  137.       techo("Error connecting to server!")
  138.       call endprog
  139.    end
  140. end
  141. address(AmsterPort)
  142. call time(R)
  143. do until ison2 = 1|Time(E) >60.00
  144.    address(AMsterPort)
  145.    "ISONLINE"
  146.    ison2 = rc
  147.    address(IRCPort)
  148.    if debugit = "Y" then techo("Waiting for online state...")
  149.    delay(30)
  150. end
  151. techo("Connected and Searching, Please Wait...")
  152. address(AmsterPort)
  153. 'SEARCH TITLE = "'searchString'" STEM = SG'
  154. do until res1 = 2
  155.    "SEARCHSTATE"
  156.    res1 = RC
  157.    if res1 = 0 then do
  158.       address(IRCPort)
  159.       techo("no list")
  160.       leave
  161.    end
  162.    delay(60)
  163. end
  164. address(IRCPort)
  165. techo("Search Complete!")
  166. if SG.COUNT < Maxhits then MaxHits = SG.COUNT
  167. if debugit = "Y" then techo(Maxhits)
  168. if SG.COUNT > 1 then do
  169.    techo("Displaying "Maxhits" of "SG.COUNT" Total Matches:")
  170.    do i = 0 to MaxHits-1
  171.       ConSpeed = GetConSpeed(SG.0.Link)
  172.       SongInfo = bold""i+1"."bold" "substr(SG.i.title,LastPos("\",SG.i.title)+1)", "SG.i.Size" bytes, "Bold""ConSpeed
  173.       techo(SongInfo)
  174.       setclip(NapSearchFind.i,SongInfo)
  175.    End
  176. End
  177. if SG.COUNT = 1 then do
  178.    techo("Displaying 1 of 1 Total Matches:")
  179.    ConSpeed = GetConSpeed(SG.0.Link)
  180.    SongInfo = bold""i+1"."bold" "substr(SG.0.title,LastPos("\",SG.0.title)+1)", "SG.0.Size" bytes, "Bold""ConSpeed
  181.    techo(SongInfo)
  182.    setclip(NapSearchFind.0,SongInfo)
  183. End
  184. if SG.COUNT = 0 then do
  185.    techo("No Matches Found.")
  186. End
  187. SetClip(NapSearchFind,MaxHits)
  188. Return 0
  189.  
  190. GetIt:
  191. Ports = ShowList("P")
  192. if pos(amsterport,ports) = 0 then do
  193.    techo("Error: Amster not running!")
  194.    call endprog
  195. end
  196. Matches = Getclip(NapSearchFind)
  197. address(IRCPort)
  198. if debugit = "Y" then techo(Matches)
  199. if searchstring > matches then DO
  200.    techo("Requested song number out of search result range, try again.")
  201.    call endprog
  202. end
  203. address(AmsterPort)
  204. "ISONLINE"
  205. ison = RC
  206. address(IRCPort)
  207. if ison = 0 then do
  208.    techo("Error: Amster went offline, try another search.")
  209.    call endprog
  210. end
  211. address(AmsterPort)
  212. "SEARCHSTATE"
  213. state = rc
  214. address(IRCPort)
  215. if State = 0 then do
  216.    techo("No Search Results Found. Do a search first!")
  217.    call endprog
  218. end
  219. if state = 1 then do
  220.    techo("Search already in progress, wait for results!")
  221.    call endprog
  222. end
  223. address(AmsterPort)
  224. 'DOWNLOAD 'searchstring-1
  225. res1 = RC
  226. address(IRCPort)
  227. if debugit = "Y" then techo(res1)
  228. SST = searchstring-1
  229. techo("Downloading "getclip(NapSearchFind.sst))
  230. Return 0
  231.  
  232. Endprog:
  233. if debugit = "Y" then techo("Done.")
  234. exit
  235.  
  236. Techo:
  237. parse arg EchoString
  238. "ECHO P="d2c(27)"b«NapSearch» C="TC" "EchoString
  239. say EchoString
  240. Return 0
  241.  
  242. GetConSpeed:
  243. Speed = Arg(1)
  244. If Speed = 0 then TheSpeed = "Unknown"
  245. If Speed = 1 then TheSpeed = "14.4K"
  246. If Speed = 2 then TheSpeed = "28.8K"
  247. If Speed = 3 then TheSpeed = "33.6K"
  248. If Speed = 4 then TheSpeed = "56K"
  249. If Speed = 5 then TheSpeed = "ISDN 64K"
  250. If Speed = 6 then TheSpeed = "ISDN 128K"
  251. If Speed = 7 then TheSpeed = "Cable"
  252. If Speed = 8 then TheSpeed = "DSL"
  253. If Speed = 9 then TheSpeed = "T1"
  254. If Speed = 10 then TheSpeed = "T3+"
  255. Return TheSpeed
  256.  
  257. HelpIt:
  258.    techo("Usage:")
  259.    techo("  /RX NapSearch Install - Install Aliases (Save Config after!)")
  260.    techo("  /NapFind   <Search String> - Search for a song")
  261.    techo("  /NapGet    <Song Number> - Download Song found by /NapFind")
  262.    techo("  /NapHide   Hide Amster")
  263.    techo("  /NapShow   Show Amster")
  264.    techo("  /NapRun    Run Amster and go online")
  265.    techo("  /NapQuit   Quit Amster")
  266.    techo("End Usage.")
  267. Return 0
  268.