Jump to content
Sign in to follow this  
nacerbaaziz

need help to read the m3u files

Recommended Posts

hello sirs
i need to read the m3u files which it  audio playList file
as you all know that the m3u files can content an paths or urls
for that i started to write an function to read it
i did the following
it now success some time and Failed others
for that if you have any other idea please give it to me
as well i couldn't make it read the urls
please help me to that
here is the code that i written

Func M3UImport($M3UFile)
    Dim $AM3UItems
    Local $fileOpen = _FileReadToArray($M3UFile, $AM3UItems)
    If @error Then Return SetError(1)
    Local $M3UPath
    Local $pltest = ""
    For $i = 1 To $AM3UItems[0]
        $pltest = StringLeft($AM3UItems[$i], 😎
        If $pltest = "#EXTINF:" Then
            For $ii = 9 To StringLen($AM3UItems[$i])
                If StringMid($AM3UItems[$i], $ii, 1) = "," Then
                    $AM3UItems[$i] = StringTrimLeft($AM3UItems[$i], $ii + 1)
                    ExitLoop
                ElseIf $ii > 25 Then
                    $AM3UItems[$i] = StringTrimLeft($AM3UItems[$i], 9)
                    ExitLoop
                EndIf
            Next
        EndIf
            $AM3UItems[$i] = StringReplace($AM3UItems[$i], "file:///", "")
        $AM3UItems[$i] = StringReplace($AM3UItems[$i], "/", "\")
        $AM3UItems[$i] = StringReplace($AM3UItems[$i], "%20", " ")
        $AM3UItems[$i] = _MakeReadable($AM3UItems[$i])
            $M3UPath = _fileGetDirPath($AM3UItems[$i])
        If $M3UPath = "" Then
            $M3UPath = @WorkingDir
            If Not StringTrimRight($M3UPath, 1) = "\" Then $M3UPath &= "\"
            $AM3UItems[$i] = $M3UPath & $AM3UItems[$i]
        EndIf
        Local $ext = _GetFileExt($AM3UItems[$i])
        If FileExists($AM3UItems[$i]) And Not (StringInStr($FilesExt, $ext) = 0) Then
            $aListItems[0] += 1
            GUICtrlCreateListViewItem(_GetFileName($AM3UItems[$i]) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & $AM3UItems[$i], $list)
        EndIf
    Next
    Return ""
EndFunc   ;==>M3UImport
    Func _MakeReadable($sString)
    Local $aReg = StringRegExp($sString, '%[0-9a-fA-F]{2}|.', 3)
        Local $sChar = ""
        Local $sReadableString = ""
    Local $number = 0
    For $i = 0 To UBound($aReg) - 1
        $sChar = StringReplace($aReg[$i], "%", "")
        If StringLen($sChar) = 2 Then
            $sReadableString &= Chr("0x" & $sChar)
            $number += 1
        Else
            $sReadableString &= $sChar
            $number -= 1
        EndIf
    Next
        If $number < 2 Then
        Return String($sReadableString)
    Else
        Return BinaryToString(StringToBinary($sReadableString), 4)
    EndIf
EndFunc   ;==>_MakeReadable


thx in advanced

Share this post


Link to post
Share on other sites

@nacerbaaziz

Could you please post a sample of an m3u file path and what are you trying to do with your script? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...