home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / Shoutcast_1979773122006.psc / frmMain.frm < prev    next >
Text File  |  2006-02-09  |  27KB  |  943 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  5. Begin VB.Form frmMain 
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "Quick Radio Ripper"
  8.    ClientHeight    =   4785
  9.    ClientLeft      =   2055
  10.    ClientTop       =   2370
  11.    ClientWidth     =   6255
  12.    BeginProperty Font 
  13.       Name            =   "Century Gothic"
  14.       Size            =   8.25
  15.       Charset         =   0
  16.       Weight          =   400
  17.       Underline       =   0   'False
  18.       Italic          =   0   'False
  19.       Strikethrough   =   0   'False
  20.    EndProperty
  21.    Icon            =   "frmMain.frx":0000
  22.    LinkTopic       =   "Form1"
  23.    MaxButton       =   0   'False
  24.    ScaleHeight     =   319
  25.    ScaleMode       =   3  'Pixel
  26.    ScaleWidth      =   417
  27.    StartUpPosition =   2  'CenterScreen
  28.    Begin VB.Timer tmrStats 
  29.       Interval        =   100
  30.       Left            =   4560
  31.       Top             =   3960
  32.    End
  33.    Begin VB.Timer tmrLaunch 
  34.       Enabled         =   0   'False
  35.       Interval        =   3000
  36.       Left            =   4560
  37.       Top             =   4440
  38.    End
  39.    Begin VB.CommandButton btAbout 
  40.       Caption         =   "&About"
  41.       Height          =   375
  42.       Left            =   4320
  43.       TabIndex        =   22
  44.       Top             =   2280
  45.       Width           =   1815
  46.    End
  47.    Begin MSComctlLib.ProgressBar Bar 
  48.       Height          =   375
  49.       Left            =   120
  50.       TabIndex        =   11
  51.       Top             =   2880
  52.       Width           =   6015
  53.       _ExtentX        =   10610
  54.       _ExtentY        =   661
  55.       _Version        =   393216
  56.       BorderStyle     =   1
  57.       Appearance      =   0
  58.    End
  59.    Begin VB.CommandButton btSave 
  60.       Caption         =   "..."
  61.       Height          =   375
  62.       Left            =   5760
  63.       TabIndex        =   10
  64.       Top             =   960
  65.       Width           =   375
  66.    End
  67.    Begin VB.TextBox txtSave 
  68.       BeginProperty Font 
  69.          Name            =   "MS Sans Serif"
  70.          Size            =   8.25
  71.          Charset         =   0
  72.          Weight          =   400
  73.          Underline       =   0   'False
  74.          Italic          =   0   'False
  75.          Strikethrough   =   0   'False
  76.       EndProperty
  77.       Height          =   360
  78.       Left            =   120
  79.       TabIndex        =   8
  80.       Text            =   "..."
  81.       Top             =   960
  82.       Width           =   5535
  83.    End
  84.    Begin VB.CommandButton btRun 
  85.       Caption         =   "&Start Ripping"
  86.       Height          =   375
  87.       Left            =   4320
  88.       TabIndex        =   7
  89.       Top             =   1800
  90.       Width           =   1815
  91.    End
  92.    Begin VB.Frame Frame1 
  93.       Caption         =   "Record Until:"
  94.       Height          =   1215
  95.       Left            =   120
  96.       TabIndex        =   2
  97.       Top             =   1440
  98.       Width           =   4095
  99.       Begin VB.TextBox txtBreak 
  100.          Height          =   360
  101.          Index           =   1
  102.          Left            =   2160
  103.          TabIndex        =   6
  104.          Text            =   "100"
  105.          Top             =   600
  106.          Width           =   1695
  107.       End
  108.       Begin VB.TextBox txtBreak 
  109.          Height          =   360
  110.          Index           =   0
  111.          Left            =   120
  112.          TabIndex        =   5
  113.          Text            =   "60"
  114.          Top             =   600
  115.          Width           =   1695
  116.       End
  117.       Begin VB.OptionButton optBreak 
  118.          Caption         =   "(x) megabytes:"
  119.          Height          =   255
  120.          Index           =   1
  121.          Left            =   2160
  122.          TabIndex        =   4
  123.          Top             =   360
  124.          Width           =   1455
  125.       End
  126.       Begin VB.OptionButton optBreak 
  127.          Caption         =   "(x) minutes:"
  128.          Height          =   255
  129.          Index           =   0
  130.          Left            =   120
  131.          TabIndex        =   3
  132.          Top             =   360
  133.          Value           =   -1  'True
  134.          Width           =   1215
  135.       End
  136.    End
  137.    Begin VB.TextBox txtStream 
  138.       BeginProperty Font 
  139.          Name            =   "MS Sans Serif"
  140.          Size            =   8.25
  141.          Charset         =   0
  142.          Weight          =   400
  143.          Underline       =   0   'False
  144.          Italic          =   0   'False
  145.          Strikethrough   =   0   'False
  146.       EndProperty
  147.       Height          =   360
  148.       Left            =   120
  149.       TabIndex        =   0
  150.       Text            =   "http://64.236.34.4:80/stream/1003"
  151.       Top             =   360
  152.       Width           =   6015
  153.    End
  154.    Begin MSWinsockLib.Winsock WS 
  155.       Left            =   5520
  156.       Top             =   3960
  157.       _ExtentX        =   741
  158.       _ExtentY        =   741
  159.       _Version        =   393216
  160.    End
  161.    Begin MSComDlg.CommonDialog CD 
  162.       Left            =   5040
  163.       Top             =   3960
  164.       _ExtentX        =   847
  165.       _ExtentY        =   847
  166.       _Version        =   393216
  167.    End
  168.    Begin VB.Label lbSong 
  169.       BackStyle       =   0  'Transparent
  170.       Caption         =   "[No song title recieved from ICE data yet]"
  171.       Height          =   255
  172.       Left            =   120
  173.       MouseIcon       =   "frmMain.frx":058A
  174.       TabIndex        =   25
  175.       Top             =   4440
  176.       Width           =   6015
  177.    End
  178.    Begin VB.Label Label9 
  179.       BackStyle       =   0  'Transparent
  180.       Caption         =   "Stream Name And Current Song:"
  181.       BeginProperty Font 
  182.          Name            =   "Century Gothic"
  183.          Size            =   8.25
  184.          Charset         =   0
  185.          Weight          =   700
  186.          Underline       =   0   'False
  187.          Italic          =   0   'False
  188.          Strikethrough   =   0   'False
  189.       EndProperty
  190.       Height          =   255
  191.       Left            =   120
  192.       TabIndex        =   24
  193.       Top             =   3960
  194.       Width           =   3015
  195.    End
  196.    Begin VB.Label lbStream 
  197.       BackStyle       =   0  'Transparent
  198.       Caption         =   "[Waiting for ICE Header]"
  199.       Height          =   255
  200.       Left            =   120
  201.       MouseIcon       =   "frmMain.frx":0894
  202.       TabIndex        =   23
  203.       Top             =   4200
  204.       Width           =   6015
  205.    End
  206.    Begin VB.Label lbGenre 
  207.       BackStyle       =   0  'Transparent
  208.       Caption         =   "[Unknown]"
  209.       Height          =   255
  210.       Left            =   3720
  211.       TabIndex        =   21
  212.       Top             =   3360
  213.       Width           =   2775
  214.    End
  215.    Begin VB.Label Label8 
  216.       BackStyle       =   0  'Transparent
  217.       Caption         =   "Stream Genre:"
  218.       BeginProperty Font 
  219.          Name            =   "Century Gothic"
  220.          Size            =   8.25
  221.          Charset         =   0
  222.          Weight          =   700
  223.          Underline       =   0   'False
  224.          Italic          =   0   'False
  225.          Strikethrough   =   0   'False
  226.       EndProperty
  227.       Height          =   255
  228.       Left            =   2280
  229.       TabIndex        =   19
  230.       Top             =   3360
  231.       Width           =   1815
  232.    End
  233.    Begin VB.Label lbPackets 
  234.       BackStyle       =   0  'Transparent
  235.       Caption         =   "0"
  236.       Height          =   255
  237.       Left            =   1320
  238.       TabIndex        =   20
  239.       Top             =   3360
  240.       Width           =   735
  241.    End
  242.    Begin VB.Label lbBitrate 
  243.       BackStyle       =   0  'Transparent
  244.       Caption         =   "0"
  245.       Height          =   255
  246.       Left            =   5760
  247.       TabIndex        =   18
  248.       Top             =   3600
  249.       Width           =   975
  250.    End
  251.    Begin VB.Label Label6 
  252.       BackStyle       =   0  'Transparent
  253.       Caption         =   "Stream Bitrate:"
  254.       BeginProperty Font 
  255.          Name            =   "Century Gothic"
  256.          Size            =   8.25
  257.          Charset         =   0
  258.          Weight          =   700
  259.          Underline       =   0   'False
  260.          Italic          =   0   'False
  261.          Strikethrough   =   0   'False
  262.       EndProperty
  263.       Height          =   255
  264.       Left            =   4440
  265.       TabIndex        =   17
  266.       Top             =   3600
  267.       Width           =   1815
  268.    End
  269.    Begin VB.Label lbTime 
  270.       BackStyle       =   0  'Transparent
  271.       Caption         =   "0:00"
  272.       Height          =   255
  273.       Left            =   3720
  274.       TabIndex        =   16
  275.       Top             =   3600
  276.       Width           =   975
  277.    End
  278.    Begin VB.Label Label5 
  279.       BackStyle       =   0  'Transparent
  280.       Caption         =   "Audio Duration:"
  281.       BeginProperty Font 
  282.          Name            =   "Century Gothic"
  283.          Size            =   8.25
  284.          Charset         =   0
  285.          Weight          =   700
  286.          Underline       =   0   'False
  287.          Italic          =   0   'False
  288.          Strikethrough   =   0   'False
  289.       EndProperty
  290.       Height          =   255
  291.       Left            =   2280
  292.       TabIndex        =   14
  293.       Top             =   3600
  294.       Width           =   1815
  295.    End
  296.    Begin VB.Label lbStore 
  297.       BackStyle       =   0  'Transparent
  298.       Caption         =   "0 KB"
  299.       Height          =   255
  300.       Left            =   1320
  301.       TabIndex        =   15
  302.       Top             =   3600
  303.       Width           =   975
  304.    End
  305.    Begin VB.Label Label4 
  306.       BackStyle       =   0  'Transparent
  307.       Caption         =   "Data Stored: "
  308.       BeginProperty Font 
  309.          Name            =   "Century Gothic"
  310.          Size            =   8.25
  311.          Charset         =   0
  312.          Weight          =   700
  313.          Underline       =   0   'False
  314.          Italic          =   0   'False
  315.          Strikethrough   =   0   'False
  316.       EndProperty
  317.       Height          =   255
  318.       Left            =   120
  319.       TabIndex        =   13
  320.       Top             =   3600
  321.       Width           =   1815
  322.    End
  323.    Begin VB.Label Label3 
  324.       BackStyle       =   0  'Transparent
  325.       Caption         =   "ICE Packets:"
  326.       BeginProperty Font 
  327.          Name            =   "Century Gothic"
  328.          Size            =   8.25
  329.          Charset         =   0
  330.          Weight          =   700
  331.          Underline       =   0   'False
  332.          Italic          =   0   'False
  333.          Strikethrough   =   0   'False
  334.       EndProperty
  335.       Height          =   255
  336.       Left            =   120
  337.       TabIndex        =   12
  338.       Top             =   3360
  339.       Width           =   1815
  340.    End
  341.    Begin VB.Label Label2 
  342.       Caption         =   "Save Location:"
  343.       BeginProperty Font 
  344.          Name            =   "Century Gothic"
  345.          Size            =   8.25
  346.          Charset         =   0
  347.          Weight          =   700
  348.          Underline       =   0   'False
  349.          Italic          =   0   'False
  350.          Strikethrough   =   0   'False
  351.       EndProperty
  352.       Height          =   255
  353.       Left            =   120
  354.       TabIndex        =   9
  355.       Top             =   720
  356.       Width           =   6015
  357.    End
  358.    Begin VB.Label Label1 
  359.       Caption         =   "Stream Address:"
  360.       BeginProperty Font 
  361.          Name            =   "Century Gothic"
  362.          Size            =   8.25
  363.          Charset         =   0
  364.          Weight          =   700
  365.          Underline       =   0   'False
  366.          Italic          =   0   'False
  367.          Strikethrough   =   0   'False
  368.       EndProperty
  369.       Height          =   255
  370.       Left            =   120
  371.       TabIndex        =   1
  372.       Top             =   120
  373.       Width           =   6015
  374.    End
  375.    Begin VB.Shape Shape1 
  376.       FillColor       =   &H00FFFFFF&
  377.       FillStyle       =   0  'Solid
  378.       Height          =   1095
  379.       Left            =   -120
  380.       Top             =   3900
  381.       Width           =   6495
  382.    End
  383.    Begin VB.Shape Shape2 
  384.       FillColor       =   &H00FFC0C0&
  385.       FillStyle       =   0  'Solid
  386.       Height          =   1215
  387.       Left            =   -120
  388.       Top             =   2760
  389.       Width           =   6495
  390.    End
  391. End
  392. Attribute VB_Name = "frmMain"
  393. Attribute VB_GlobalNameSpace = False
  394. Attribute VB_Creatable = False
  395. Attribute VB_PredeclaredId = True
  396. Attribute VB_Exposed = False
  397. 'Sample ICE Request
  398. 'GET /stream/1017 HTTP/1.1
  399. 'Accept: */*
  400. 'cache -Control: no -cache
  401. 'User-Agent: iTunes/6.0.1 (Windows; N)
  402. 'x-audiocast-udpport: 4171
  403. 'icy-metadata: 1
  404. 'Host: 64.236.34.67
  405. 'Connection: Close
  406.  
  407. 'Sample ICE Header
  408. '
  409. 'ICY 200 OK
  410. 'icy-notice1: <BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
  411. 'icy-notice2: SHOUTcast Distributed Network Audio Server/SolarisSparc v1.9.5<BR>
  412. 'icy-name: D I G I T A L L Y - I M P O R T E D - DJ MIXES - non-stop DJ sets featuring various forms of techno & trance!
  413. 'icy-genre: Trance Techno House
  414. 'icy-url: http://www.di.fm
  415. 'icy-pub: 1
  416. 'icy-metaint: 8192
  417. 'icy-br: 96
  418. 'icy-irc: #shoutcast
  419. 'icy-icq: 0
  420. 'icy-aim: N/A
  421.  
  422. 'SHOUTCast END OF HEADER Key
  423. Const endHeader = vbCr & vbLf & vbCr & vbLf
  424.  
  425. Dim Running As Boolean
  426.  
  427. Private Sub btAbout_Click()
  428.   frmAbout.Show 1, Me
  429. End Sub
  430.  
  431. Private Sub btRun_Click()
  432.   If Running Then
  433.      'Close the stream
  434.      EndStream
  435.      
  436.      'Close the file
  437.      CloseFile
  438.      
  439.      Call SetMode(True)
  440.      
  441.      btRun.Caption = "&Start Ripping"
  442.      Running = False
  443.   Else
  444.      CurrentPath = MakePath()
  445.      
  446.      'Overwrite Warning
  447.      If StopOverwrite = True Then Exit Sub
  448.      
  449.      'Open the file
  450.      OpenFile
  451.      
  452.      'Open the stream
  453.      If StartStream = False Then Exit Sub
  454.      
  455.      Call SetMode(False)
  456.      
  457.      Running = True
  458.      btRun.Caption = "&Stop Ripping"
  459.   End If
  460. End Sub
  461.  
  462. Public Sub SetMode(ByVal State As Boolean)
  463.   txtSave.Enabled = State
  464.   txtStream.Enabled = State
  465.   txtBreak(0).Enabled = State
  466.   txtBreak(1).Enabled = State
  467.   optBreak(0).Enabled = State
  468.   optBreak(1).Enabled = State
  469.   btSave.Enabled = State
  470. End Sub
  471.  
  472. Private Sub btSave_Click()
  473.   On Error GoTo SaveNext
  474.  
  475.   CD.DialogTitle = "Stream Save Location"
  476.   CD.Filter = "MP3 File (*.mp3)|*.mp3"
  477.   
  478.   CD.ShowSave
  479.   txtSave.Text = CD.FileName
  480.   
  481. SaveNext:
  482.   On Error GoTo 0
  483. End Sub
  484.  
  485. Public Sub EndStream()
  486.   On Error Resume Next
  487.   
  488.   'Flush the buffer
  489.   'Put StreamFile, Loc(StreamFile) + 1, Buffer
  490.   Call WriteToDisk(Buffer, True)
  491.   Stream.Bytes = Stream.Bytes + Len(Buffer)
  492.   Buffer = ""
  493.  
  494.   'Close the socket
  495.   WS.Close
  496.   
  497.   'Stop the Playback
  498.   Call Cleanup
  499.   
  500.   On Error GoTo 0
  501. End Sub
  502.  
  503. Public Function MakePath() As String
  504.   Path = txtSave.Text
  505.   
  506.   Path = Replace(Path, "%TIME%", Round(Timer))
  507.   Path = Replace(Path, "%DATE%", Date$)
  508.   
  509.   MakePath = Path
  510. End Function
  511.  
  512. Public Function StopOverwrite() As Boolean
  513.   StopOverwrite = False
  514.   On Error GoTo Safe
  515.   
  516.   Tmp = FreeFile
  517.   
  518.   Open CurrentPath For Input As Tmp
  519.   Close Tmp
  520.   
  521.   Rtn = MsgBox("Warning! This file already exists. Overwrite it?", vbExclamation + vbYesNo, "Quick Radio Ripper")
  522.   
  523.   StopOverwrite = True
  524.   If Rtn = vbYes Then StopOverwrite = False
  525.  
  526. Safe:
  527.   On Error GoTo 0
  528. End Function
  529.  
  530. Public Sub OpenFile()
  531.   StreamFile = FreeFile
  532.   
  533.   Open CurrentPath For Output As StreamFile
  534. End Sub
  535.  
  536. Public Sub CloseFile()
  537.   Close StreamFile
  538. End Sub
  539.  
  540. Private Sub Form_Load()
  541.   Dim Cmds() As String
  542.   
  543.   Set fDebug = New frmDebug
  544.   fDebug.Hide
  545.   
  546.   txtSave.Text = App.Path & "\rip.mp3"
  547.   
  548.   Running = False
  549.   
  550.   'Command Line Parsing
  551.   If Trim(Command()) <> "" Then
  552.      Cmds = Split(Command(), " ")
  553.  
  554.      '-a (url) -s (savefile) [-t (timelimit)] [-m (sizelimit)]
  555.      For a = LBound(Cmds) To UBound(Cmds)
  556.        Select Case Cmds(a)
  557.          Case "-v":
  558.            Me.WindowState = 1
  559.          Case "-a":
  560.            txtStream.Text = Cmds(a + 1)
  561.          Case "-s":
  562.            txtSave.Text = Cmds(a + 1)
  563.          Case "-t":
  564.            txtBreak(0).Text = Cmds(a + 1)
  565.            optBreak(0).Value = True
  566.          Case "-m":
  567.            txtBreak(1).Text = Cmds(a + 1)
  568.            optBreak(1).Value = True
  569.        End Select
  570.      Next a
  571.      
  572.      'Now start it up
  573.      tmrLaunch.Enabled = True
  574.   End If
  575. End Sub
  576.  
  577. Public Sub Cleanup()
  578.   'Nothing to cleanup yet
  579. End Sub
  580.  
  581. Public Function StartStream() As Boolean
  582.   StartStream = False
  583.   
  584.   'Parse the address
  585.   Call ParseAddress
  586.   
  587.   'Start the Stream
  588.   WS.Connect Stream.IP, Stream.Port
  589.  
  590.   'Set the 'Waiting for ICE' flag
  591.   Stream.ICE = False
  592.   
  593.   'Clear old data
  594.   Stream.iMeta = ""
  595.   Stream.iPack = 0
  596.   Stream.Bytes = 0
  597.   Buffer = ""
  598.   Resync = False
  599.  
  600.   Blocks = 0
  601.   Max_Buffer = 0
  602.   Average_Packet = 0
  603.   Max_Packet = 0
  604.   BWritten = 0
  605.   Resyncs = 0
  606.   RDiscard = 0
  607.   
  608.   'Generate the Playback System
  609.   
  610.   'Wait for connection
  611.   Do While WS.State <> sckConnected
  612.      If WS.State = sckError Then
  613.         'Failed
  614.         MsgBox "Failed to create connection to Radio Station.", vbCritical + vbOKOnly, "Quick Radio Ripper"
  615.         Exit Function
  616.      End If
  617.      DoEvents
  618.   Loop
  619.   
  620.   On Error GoTo 0
  621.   
  622.   'Build and send the Stream Request
  623.   Header = "GET " & Stream.Path & " HTTP/1.0" & vbCrLf
  624.   Header = Header & "Host: " & Stream.IP & vbCrLf
  625.   Header = Header & "User-Agent: WinampMPEG/2.7" & vbCrLf
  626.   Header = Header & "Accept: */*" & vbCrLf
  627.   Header = Header & "Icy-MetaData: 1" & vbCrLf
  628.   Header = Header & "Connection: Close" & vbCrLf & vbCrLf
  629.   
  630.   WS.SendData Header
  631.   
  632.   StartStream = True
  633. End Function
  634.  
  635. Public Sub ParseAddress()
  636.    Dim Data As String
  637.    
  638.    Data = Replace(txtStream.Text, "http://", "", , , vbTextCompare)
  639.    
  640.    PntA = InStr(1, Data, ":")
  641.    PntB = InStr(PntA, Data, "/")
  642.    If PntB < PntA Then PntB = Len(Data)
  643.    
  644.    Stream.IP = Mid(Data, 1, PntA - 1)
  645.    Stream.Port = CInt(Mid(Data, PntA + 1, (PntB - 1) - PntA))
  646.    Stream.Path = "/"
  647.    If PntB <> Len(Data) Then Stream.Path = Mid(Data, PntB)
  648. End Sub
  649.  
  650. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  651.   If Running Then
  652.      'Stop the stream and close the file
  653.      Call btRun_Click
  654.   End If
  655.   
  656.   fDebug.Tag = "allow"
  657.   Unload fDebug
  658. End Sub
  659.  
  660. Private Sub lbSong_Click()
  661.   If lbSong.Tag <> "" Then Call ShellURL(lbSong.Tag)
  662. End Sub
  663.  
  664. Private Sub lbStream_Click()
  665.   If lbStream.Tag <> "" Then Call ShellURL(lbStream.Tag)
  666. End Sub
  667.  
  668. Private Sub tmrLaunch_Timer()
  669.   tmrLaunch.Enabled = False
  670.   Call btRun_Click
  671. End Sub
  672.  
  673. Private Sub tmrStats_Timer()
  674.   On Error Resume Next
  675.  
  676.   If Stream.Bytes < (950000) Then
  677.      TmpA = Round(Stream.Bytes / 1024, 2) & " KB"
  678.   Else
  679.      TmpA = Round((Stream.Bytes / 1024) / 1024, 2) & " MB"
  680.   End If
  681.   
  682.   'Recalculate our estimated 'music duration' in seconds
  683.   Stream.Duration = (Stream.Bytes / ((Stream.Bitrate / 8) * 1000))
  684.   
  685.   TmpB = MakeTime(Stream.Duration)
  686.   TmpC = Stream.Bitrate
  687.   TmpD = Stream.iPack
  688.   
  689.   'Update the progress bar if needed
  690.   If optBreak(0).Value = True Then
  691.      'Max Minutes
  692.      Progress = (Stream.Duration * 100) / (CInt(txtBreak(0).Text) * 60)
  693.      If Progress > 100 Then Progress = 100
  694.      If Progress < 0 Then Progress = 0
  695.      Bar.Value = Progress
  696.      
  697.      'Do we need to stop?
  698.      If Running = True Then
  699.        If Progress = 100 And CInt(txtBreak(0).Text) > 0 Then Call btRun_Click
  700.      End If
  701.   Else
  702.      'Max Filesize
  703.      Progress = ((Stream.Bytes / 1024) * 100) / (CInt(txtBreak(1).Text) * 1024)
  704.      If Progress > 100 Then Progress = 100
  705.      If Progress < 0 Then Progress = 0
  706.      Bar.Value = Progress
  707.   
  708.      'Do we need to stop?
  709.      If Running = True Then
  710.        If Progress = 100 And CInt(txtBreak(1).Text) > 0 Then Call btRun_Click
  711.      End If
  712.   End If
  713.   
  714.   'Update the necessary fields
  715.   
  716.   If lbStore.Caption <> TmpA Then lbStore.Caption = TmpA
  717.   If lbTime.Caption <> TmpB Then lbTime.Caption = TmpB: Me.Caption = "(" & TmpB & ") Quick Radio Ripper"
  718.   If lbBitrate.Caption <> TmpC Then lbBitrate.Caption = TmpC
  719.   If lbPackets.Caption <> TmpD Then lbPackets.Caption = TmpD
  720.   
  721.   On Error GoTo 0
  722. End Sub
  723.  
  724. Private Sub WS_Close()
  725.   'Stop
  726. End Sub
  727.  
  728. Private Sub WS_ConnectionRequest(ByVal requestID As Long)
  729.   WS.Accept requestID
  730. End Sub
  731.  
  732. Public Function MakeTime(ByVal Seconds As Long) As String
  733.   Min = 0
  734.   Sec = "00"
  735.   
  736.   Do While Seconds >= 60
  737.     Seconds = Seconds - 60
  738.     Min = Min + 1
  739.   Loop
  740.   
  741.   Sec = CStr(Seconds)
  742.   If Len(Sec) < 2 Then Sec = "0" & Sec
  743.   
  744.   MakeTime = Min & ":" & Sec
  745. End Function
  746.  
  747. Private Sub WS_DataArrival(ByVal bytesTotal As Long)
  748.   Dim inBuf As String, Dump As Long
  749.   
  750.   'Read the incoming data, attach it to the buffer
  751.   WS.GetData inBuf
  752.   Buffer = Buffer & inBuf
  753.   
  754.   'DEBUG: Update stats
  755.   If Len(Buffer) > Max_Buffer Then Max_Buffer = Len(Buffer)
  756.   If Average_Packet = 0 Then Average_Packet = Len(inBuf)
  757.   Average_Packet = (Average_Packet + Len(inBuf)) / 2
  758.   If Len(inBuf) > Max_Packet Then Max_Packet = Len(inBuf)
  759.   
  760.   'Are we still expecting a starting ICE header? Then make sure we get it before anything else.
  761.   If Stream.ICE = False Then
  762.      PntA = InStr(1, Buffer, endHeader, vbBinaryCompare)
  763.      
  764.      If PntA > 0 Then
  765.         Stream.iMeta = Mid(Buffer, 1, (PntA + Len(endHeader)) - 1)
  766.         Buffer = Mid(Buffer, PntA + Len(endHeader) + 0)
  767.         Stream.iHeader = Stream.iMeta
  768.         
  769.         Call Parse_Header
  770.         Stream.ICE = True
  771.      End If
  772.   
  773.      Exit Sub
  774.   End If
  775.   
  776.   'Are we in an emergency resync mode?
  777.   If Resync = True Then
  778.      'We need to stop dumping data to disk until we can locate a valid ICE packet.
  779.      'Time to get our hands dirty with this experimental routine.
  780.      
  781.      'Try to locate the start of a valid Metadata packet
  782.      PntA = InStr(1, Buffer, "StreamTitle") - 1
  783.      
  784.      If PntA <= 0 Then Exit Sub  'Nothing yet, keep waiting
  785.      
  786.      'Now we know where the metadata sync point SHOULD be. Calculate how much data we
  787.      'need to dump to repair our stream.
  788.      Dump = PntA
  789.      Do
  790.       Dump = Dump - (Stream.MetaRate + 1)
  791.       'Debug.Print Asc(Mid(Buffer, Dump, 1))
  792.      Loop Until Dump < Stream.MetaRate
  793.      
  794.      'Dump should tell us how much excess data we have. Use it to trim that data out of the buffer.
  795.      Buffer = Mid(Buffer, Dump + 1)
  796.      Resync = False
  797.      
  798.      Resyncs = Resyncs + 1
  799.      RDiscard = RDiscard + Dump
  800.   End If
  801.   
  802.   'Do we have enough data to extract the metadata packet?
  803.   If Len(Buffer) > Stream.MetaRate Then
  804.      'Read the METABYTE
  805.      mTmp = Asc(Mid(Buffer, Stream.MetaRate + 1, 1)) * 16
  806.      
  807.      If mTmp = 0 Then
  808.         'No metadata for this occurance. Flush the buffer up to this point and continue.
  809.         'Put StreamFile, Loc(StreamFile) + 1, Mid(Buffer, 1, Stream.MetaRate)
  810.         Call WriteToDisk(Mid(Buffer, 1, Stream.MetaRate), False)
  811.         Buffer = Mid(Buffer, Stream.MetaRate + 2)
  812.         Stream.Bytes = Stream.Bytes + (Stream.MetaRate)
  813.      Else
  814.         If mTmp + Stream.MetaRate > Len(Buffer) Then
  815.            'Not enough data to read the whole meta-block, wait for more data
  816.            Exit Sub
  817.         End If
  818.         
  819.         'We have enough to read the block.  Extract the metadata block first.
  820.         Meta = Mid(Buffer, Stream.MetaRate + 2, mTmp)
  821.         
  822.         'Is this Meta packet corrupted?
  823.         If IsCorrupt(Meta) Then
  824.            'Crap, time to start an emergency stream resync. Stop parsing, start buffering your ass off.
  825.            Resync = True
  826.            Exit Sub
  827.         End If
  828.         
  829.         'Metadata appears to be intact, flush the buffer.
  830.         Call WriteToDisk(Mid(Buffer, 1, Stream.MetaRate), False)
  831.         Stream.Bytes = Stream.Bytes + (Stream.MetaRate)
  832.         Buffer = Mid(Buffer, (Stream.MetaRate + 2) + (mTmp))
  833.         
  834.         Stream.iPack = Stream.iPack + 1
  835.         
  836.         'Parse the new metadata
  837.         Stream.iMeta = Meta
  838.         Call Parse_Header
  839.      End If
  840.   End If
  841. End Sub
  842.  
  843. Public Sub Parse_Header()
  844.   Dim Tmp() As String
  845.   
  846.   If InStr(1, Stream.iMeta, vbCrLf, vbBinaryCompare) <= 0 Then
  847.      'Odd metadata
  848.      'StreamTitle='Ying Yang Twins featuring Pitbull - Shake';StreamUrl='';
  849.      
  850.      Call Parse_Special
  851.      Exit Sub
  852.   End If
  853.   
  854.   Tmp = Split(Stream.iMeta, vbCrLf)
  855.   
  856.   If UBound(Tmp) <= 1 Then Exit Sub
  857.   
  858.   For i = 0 To UBound(Tmp)
  859.     If Left(Tmp(i), Len("icy-url:")) = "icy-url:" Then Stream.URL = Trim(Mid(Tmp(i), Len("icy-url:") + 1)): Call SetHyperlinkA(Stream.URL)
  860.     If Left(Tmp(i), Len("icy-br:")) = "icy-br:" Then Stream.Bitrate = CInt(Mid(Tmp(i), Len("icy-br:") + 1))
  861.     If Left(Tmp(i), Len("icy-name:")) = "icy-name:" Then
  862.        If Stream.ICE = False Then
  863.           lbStream.Caption = Trim(Mid(Tmp(i), Len("icy-name:") + 1))
  864.           lbStream.ToolTipText = lbStream.Caption
  865.        Else
  866.           lbSong.Caption = Trim(Mid(Tmp(i), Len("icy-name:") + 1))
  867.           lbSong.ToolTipText = lbSong.Caption
  868.        End If
  869.     End If
  870.     If Left(Tmp(i), Len("icy-genre:")) = "icy-genre:" Then lbGenre.Caption = Trim(Mid(Tmp(i), Len("icy-genre:") + 1))
  871.     If Left(Tmp(i), Len("icy-metaint:")) = "icy-metaint:" Then
  872.        Stream.MetaRate = CLng(Mid(Tmp(i), Len("icy-metaint:") + 1))
  873.     End If
  874.   Next i
  875. End Sub
  876.  
  877. Private Sub WS_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  878.   'Stop
  879. End Sub
  880.  
  881. Public Sub Parse_Special()
  882.   On Error Resume Next
  883.   
  884.   'StreamTitle='Ying Yang Twins featuring Pitbull - Shake';StreamUrl='';
  885.   Dim TmpA() As String, TmpB() As String
  886.   
  887.   TmpA = Split(Stream.iMeta, ";")
  888.   
  889.   For a = LBound(TmpA) To UBound(TmpA)
  890.     TmpB = Split(TmpA(a), "=")
  891.     
  892.     Select Case LCase(TmpB(0)) 'Key
  893.       Case "streamtitle":
  894.         lbSong.Caption = Trim(Replace(TmpB(1), "'", ""))
  895.       Case "streamurl":
  896.         Call SetHyperlinkB(Trim(Replace(TmpB(1), "'", "")))
  897.     End Select
  898.   Next a
  899.   
  900.   On Error GoTo 0
  901. End Sub
  902.  
  903. Public Sub SetHyperlinkA(ByVal Link As String)
  904.   If Link <> "" Then
  905.      lbStream.Tag = Link
  906.      lbStream.ForeColor = RGB(0, 0, 255)
  907.      lbStream.FontUnderline = True
  908.      lbStream.MousePointer = 99
  909.   Else
  910.      lbStream.Tag = ""
  911.      lbStream.ForeColor = vbBlack
  912.      lbStream.FontUnderline = False
  913.      lbStream.MousePointer = 0
  914.   End If
  915. End Sub
  916.  
  917. Public Sub SetHyperlinkB(ByVal Link As String)
  918.   If Link <> "" Then
  919.      lbSong.Tag = Link
  920.      lbSong.ForeColor = RGB(0, 0, 255)
  921.      lbSong.FontUnderline = True
  922.      lbSong.MousePointer = 99
  923.   Else
  924.      lbSong.Tag = ""
  925.      lbSong.ForeColor = vbBlack
  926.      lbSong.FontUnderline = False
  927.      lbSong.MousePointer = 0
  928.   End If
  929. End Sub
  930.  
  931. Public Sub WriteToDisk(ByVal Data As String, ByVal Flush As Boolean)
  932.   'Enable Disk Caching
  933.   DCache = DCache & Data
  934.   
  935.   'Do we have enough to justify a write?
  936.   If Len(DCache) > MaxCache Or Flush = True Then
  937.      Print #StreamFile, DCache;
  938.      Blocks = Blocks + 1
  939.      BWritten = BWritten + Len(DCache)
  940.      DCache = ""
  941.   End If
  942. End Sub
  943.