161 lines
5.3 KiB
VB.net
161 lines
5.3 KiB
VB.net
Imports System.Globalization
|
|
|
|
Public Class Song
|
|
|
|
'Songinfos aus Datei
|
|
Public Property Artist As String
|
|
Public Property Title As String
|
|
Public Property Genre As String
|
|
Public Property Language As String
|
|
Public Property Year As Integer
|
|
Public Property Previewstart As Decimal
|
|
Public Property BPM As Integer
|
|
Public Property GAP As Integer
|
|
Public Property Songfilename As String
|
|
Public Property CoverFilename As String
|
|
Public Property VideoFilename As String
|
|
|
|
Public Property SongInfos As New Dictionary(Of String, String)
|
|
|
|
'Weitere Properties
|
|
Public Property ID As Integer
|
|
Public Property RootDir As String
|
|
Public Property SubDirectory As String
|
|
Public Property IsFavorite As Boolean
|
|
Public Property InfoFile As String
|
|
Public Property HasError As Boolean
|
|
Public Property ErrorText As String
|
|
Public Property ExistsInFavDir As Boolean
|
|
|
|
|
|
Public ReadOnly Property SongInfoCount As Integer
|
|
Get
|
|
Return SongInfos.Count
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property FullPath As String
|
|
Get
|
|
Return RootDir & SubDirectory & "\"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Songfile As String
|
|
Get
|
|
Return FullPath & Songfilename
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Coverfile As String
|
|
Get
|
|
Return FullPath & CoverFilename
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property Videofile As String
|
|
Get
|
|
Return FullPath & VideoFilename
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ParentFolderName As String
|
|
'Gibt den übergeordneten Ordnernamen zurück, in dem sich der Pfad befindet
|
|
Get
|
|
Dim t As String = FullPath
|
|
If t.EndsWith("\") Then
|
|
t = t.Substring(0, t.Length - 1)
|
|
End If
|
|
t = t.Substring(0, t.LastIndexOf("\"))
|
|
Return IO.Path.GetFileName(t)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property FolderName As String
|
|
'Gibt den übergeordneten Ordnernamen zurück, in dem sich der Pfad befindet
|
|
Get
|
|
Dim t As String = FullPath
|
|
If t.EndsWith("\") Then
|
|
t = t.Substring(0, t.Length - 1)
|
|
End If
|
|
Return IO.Path.GetFileName(t)
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub ReadInfoFile()
|
|
Try
|
|
Dim line As String
|
|
Using sr As New IO.StreamReader(InfoFile, System.Text.Encoding.Default)
|
|
Do Until sr.EndOfStream
|
|
line = sr.ReadLine
|
|
If line.StartsWith("#") Then
|
|
AddSongInfo(line)
|
|
ElseIf line.Trim.Length > 0 Then 'Startet nicht mit # und ist auch keine Leerzeile, das heißt jetzt fängt wohl der Lyrics-Part an
|
|
Exit Do
|
|
End If
|
|
Loop
|
|
sr.Close()
|
|
End Using
|
|
Catch ex As IO.DirectoryNotFoundException
|
|
''Ggf Dateiname zu lang
|
|
ErrorText = "Dateiname zu lang"
|
|
HasError = True
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub AddSongInfo(infoline As String)
|
|
'#TITLE:Not Myself Tonight
|
|
'#ARTIST:Christina Aguilera
|
|
'#LANGUAGE:English
|
|
'#GENRE:Pop
|
|
'#YEAR:2010
|
|
'#MP3:Christina Aguilera - Not Myself Tonight (Duett).mp3
|
|
'#COVER:Christina Aguilera - Not Myself Tonight (Duett)[CO].jpg
|
|
'#VIDEO:Christina Aguilera - Not Myself Tonight (Duett).mp4
|
|
'#PREVIEWSTART:25,250
|
|
'#BPM:240
|
|
'#GAP:25000
|
|
|
|
Dim field, value As String
|
|
If infoline.StartsWith("#") AndAlso infoline.Contains(":") Then
|
|
field = infoline.Substring(1, infoline.IndexOf(":") - 1).Trim
|
|
value = infoline.Substring(infoline.IndexOf(":") + 1).Trim
|
|
|
|
Select Case field.ToUpper
|
|
Case "TITLE"
|
|
Title = value
|
|
Case "ARTIST"
|
|
Artist = value
|
|
Case "YEAR"
|
|
Year = CInt(value)
|
|
Case "MP3"
|
|
Songfilename = value
|
|
Case "COVER"
|
|
CoverFilename = value
|
|
Case "VIDEO"
|
|
VideoFilename = value
|
|
Case "LANGUAGE"
|
|
Language = value
|
|
Case "GENRE"
|
|
Genre = value
|
|
Case "PREVIEWSTART"
|
|
If value.Contains(",") Then
|
|
Decimal.TryParse(value, NumberStyles.Number, New CultureInfo("de-DE"), Previewstart)
|
|
Else
|
|
Decimal.TryParse(value, NumberStyles.Number, New CultureInfo("en-US"), Previewstart)
|
|
End If
|
|
Case "BPM"
|
|
BPM = CInt(value)
|
|
Case "GAP"
|
|
GAP = CInt(value)
|
|
Case Else
|
|
If SongInfos.ContainsKey(field) Then
|
|
Dim newvalue = SongInfos(field)
|
|
newvalue = $"{newvalue},{value}"
|
|
SongInfos(field) = newvalue
|
|
Else
|
|
SongInfos.Add(field, value)
|
|
End If
|
|
|
|
End Select
|
|
End If
|
|
End Sub
|
|
End Class
|