VERSION 5.00
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "shdocvw.dll"
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Vanasha's YouTube Playlist"
   ClientHeight    =   6045
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9840
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6045
   ScaleWidth      =   9840
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "Play"
      Height          =   255
      Left            =   5400
      TabIndex        =   9
      Top             =   120
      Width           =   855
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   5160
      Top             =   480
   End
   Begin VB.TextBox PlaylistName 
      Height          =   285
      Left            =   7440
      TabIndex        =   8
      Text            =   "Playlist1"
      Top             =   120
      Width           =   2295
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Help"
      Height          =   255
      Left            =   240
      TabIndex        =   7
      Top             =   5760
      Width           =   1215
   End
   Begin SHDocVwCtl.WebBrowser Player 
      Height          =   5175
      Left            =   120
      TabIndex        =   6
      Top             =   480
      Width           =   6255
      ExtentX         =   11033
      ExtentY         =   9128
      ViewMode        =   0
      Offline         =   0
      Silent          =   0
      RegisterAsBrowser=   0
      RegisterAsDropTarget=   1
      AutoArrange     =   0   'False
      NoClientEdge    =   0   'False
      AlignLeft       =   0   'False
      NoWebView       =   0   'False
      HideFileNames   =   0   'False
      SingleClick     =   0   'False
      SingleSelection =   0   'False
      NoFolders       =   0   'False
      Transparent     =   0   'False
      ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
      Location        =   ""
   End
   Begin VB.TextBox PName 
      Height          =   285
      Left            =   2880
      MaxLength       =   100
      TabIndex        =   4
      Top             =   120
      Width           =   2415
   End
   Begin VB.ListBox Playlist 
      BackColor       =   &H00000000&
      ForeColor       =   &H00FFFFFF&
      Height          =   5520
      ItemData        =   "frmMain.frx":000C
      Left            =   6480
      List            =   "frmMain.frx":000E
      TabIndex        =   3
      Top             =   480
      Width           =   3255
   End
   Begin VB.CommandButton Add 
      Caption         =   "Add"
      Height          =   255
      Left            =   6360
      TabIndex        =   2
      Top             =   120
      Width           =   975
   End
   Begin VB.TextBox ID 
      Height          =   285
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   2055
   End
   Begin VB.Label Label2 
      Caption         =   "Name:"
      Height          =   255
      Left            =   2400
      TabIndex        =   5
      Top             =   120
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "ID:"
      Height          =   255
      Left            =   0
      TabIndex        =   1
      Top             =   120
      Width           =   375
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Data() As String: Dim i As Long: Dim SData As String
Private Type Song
    SName As String
    SID As String
End Type
Dim Current As Long
Private Type Playlist
    SongS(5000) As Song
End Type
Dim CurrentPlaylist As Playlist

Private Sub Add_Click()
If (PName.Text <> "" And ID.Text <> "") Then
    
    CurrentPlaylist.SongS(Current).SID = ID.Text
    CurrentPlaylist.SongS(Current).SName = PName.Text
    Playlist.AddItem Current & ": " & PName.Text
    Dim There As Boolean
   If (Dir(App.Path & "\Playlists\" & PlaylistName.Text & ".ytp") <> "") Then There = True
    Open App.Path & "\Playlists\" & PlaylistName.Text & ".ytp" For Append As #1
        If (There = True) Then Print #1, ""
        Print #1, ID.Text
        Print #1, PName.Text
    Close #1
    Current = Current + 1
    ID.Text = ""
    PName.Text = ""
End If
End Sub


Private Sub Command1_Click()
Me.Hide
Help.Show
End Sub

Private Sub Command2_Click()
Player.Navigate "http://www.youtube.com/v/" & ID.Text
Form1.Caption = "Watch " & PName.Text
'LoadPlaylist (PlaylistName.Text)
End Sub

Private Sub Form_Activate()
PlaylistName.Text = GetSetting(App.EXEName, "Data", "Playlist", 0)
If (PlaylistName.Text = "0") Then
    Select Case MsgBox("Welcome to Vanasha's YouTube playlist maker!" & vbNewLine & "For Help please press 'Yes'.", vbYesNo + vbInformation, "Vanasha's YouTuber")
    Case vbYes
        Me.Hide
        Help.Show
        Call SaveSetting(App.EXEName, "Data", "Playlist", "Playlist1")
        PlaylistName.Text = "Playlist1"
    End Select
End If
LoadPlaylist (PlaylistName.Text)
End Sub

Private Sub Form_Load()
Current = 1

Dim FF, FF2 As Integer
FF = FreeFile(): FF2 = FreeFile()





On Error Resume Next
MkDir (App.Path & "\Playlists\")
End Sub



Private Sub Playlist_Click()
i = InStr(1, Playlist.Text, ":", vbTextCompare) - 1
Player.Navigate "http://www.youtube.com/v/" & CurrentPlaylist.SongS(Left(Playlist.Text, i)).SID

Form1.Caption = "Watch " & CurrentPlaylist.SongS(Left(Playlist.Text, i)).SName
'"<html>" & vbNewLine & "<body>" & vbNewLine & "<object width=""425"" height=""350""><param name=""movie"" value=""http://www.youtube.com/v/AHd3ck6fHBw""></param><param name=""wmode"" value=""transparent""></param><embed src=""http://www.youtube.com/v/AHd3ck6fHBw"" type=""application/x-shockwave-flash"" wmode=""transparent"" width=""425"" height=""350""></embed></object>" & vbNewLine & "</body>" & vbNewLine & "</html")

End Sub

Private Function LoadPlaylist(TName As String)
Playlist.Clear
Current = 1
On Error GoTo EndF
Open App.Path & "\Playlists\" & TName & ".ytp" For Input As #2
    Data() = Split(Input(LOF(2), 2), vbCrLf)
Close #2
For i = 0 To UBound(Data())
    If (Data(i) = "") Then
        CurrentPlaylist.SongS(Current).SID = Data(i - 2)
        CurrentPlaylist.SongS(Current).SName = Data(i - 1)
        Playlist.AddItem Current & ": " & CurrentPlaylist.SongS(Current).SName
        Current = Current + 1
    End If
Next i
EndF:
End Function

Private Sub PlaylistName_Change()
Call SaveSetting(App.EXEName, "Data", "Playlist", PlaylistName.Text)
LoadPlaylist (PlaylistName.Text)
End Sub

Private Sub Timer1_Timer()
If (Player.LocationName = "500 Internal Server Error") Then
    Player.Navigate ("")
    i = Val(Left(Playlist.Text, 1))
    Call FormPlaylist(PlaylistName.Text, CurrentPlaylist.SongS(i).SID & vbNewLine & CurrentPlaylist.SongS(i).SName)
    CurrentPlaylist.SongS(i).SID = ""
    CurrentPlaylist.SongS(i).SName = ""
    On Error Resume Next
    Playlist.RemoveItem (i - 1)
    
End If

If (Player.LocationName = "YouTube - Broadcast Yourself.") Then
    Player.Navigate ("")
End If
End Sub

Private Function FormPlaylist(TName As String, FText As String)
On Error GoTo EndF
Open App.Path & "\Playlists\" & TName & ".ytp" For Input As #3
    SData = Replace(Input(LOF(3), 3), FText, "")
Close #3
Open App.Path & "\Playlists\" & TName & ".ytp" For Output As #4
    Print #4, SData
Close #4

EndF:
End Function

