[SOLVED]Text Parsing Issue (1 Viewer)

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
Hi All,
I'm trying to build a text parser for editing my IPTV playlist (as it has thousands of channels that I don't want).
They usually are spreaded within Lines in a good format, like this:
Code:
#EXTM3U
#EXTINF:-1 tvg-id="" tvg-name="------|France|------" tvg-logo="" group-title="France",------|France|------
http://www.WebServer.com/UserName/Password/2866
#EXTINF:-1 tvg-id="13e.rue.fr" tvg-name="FR001:13 Eme Rue" tvg-logo="" group-title="France",FR001:13 Eme Rue
http://www.WebServer.com/UserName/Password/2865
#EXTINF:-1 tvg-id="6ter.fr" tvg-name="FR002:6Ter" tvg-logo="" group-title="France",FR002:6Ter
http://www.WebServer.com/UserName/Password/2864
#EXTINF:-1 tvg-id="ab.moteurs.fr" tvg-name="FR003:AB Moteur" tvg-logo="" group-title="France",FR003:AB Moteur
http://www.WebServer.com/UserName/Password/2863
#EXTINF:-1 tvg-id="ab.1.fr" tvg-name="FR004:AB1" tvg-logo="" group-title="France",FR004:AB1
http://www.WebServer.com/UserName/Password/2862
and I have managed to read this,
But sometimes it is saved like it's unformatted, like this:
Code:
#EXTM3U#EXTINF:-1 tvg-id="" tvg-name="------|France|------" tvg-logo="" group-title="France",------|France|------http://www.WebServer.com/UserName/Password/2866#EXTINF:-1 tvg-id="13e.rue.fr" tvg-name="FR001:13 Eme Rue" tvg-logo="" group-title="France",FR001:13 Eme Ruehttp://www.WebServer.com/UserName/Password/2865#EXTINF:-1 tvg-id="6ter.fr" tvg-name="FR002:6Ter" tvg-logo="" group-title="France",FR002:6Terhttp://www.WebServer.com/UserName/Password/2864#EXTINF:-1 tvg-id="ab.moteurs.fr" tvg-name="FR003:AB Moteur" tvg-logo="" group-title="France",FR003:AB Moteurhttp://www.WebServer.com/UserName/Password/2863#EXTINF:-1 tvg-id="ab.1.fr" tvg-name="FR004:AB1" tvg-logo="" group-title="France",FR004:AB1http://www.WebServer.com/UserName/Password/2862

Is there any way I could be able to parse it for both ways? I'm struggling to find a way how to do it...
Please find Attached the file to see where I've come so far and 2 sample txt files.

Thanks in Advance,
Margarit
 

Attachments

  • TextImport.zip
    71.6 KB · Views: 95

namliam

The Mailman - AWF VIP
Local time
Today, 01:52
Joined
Aug 11, 2003
Messages
11,696
Seems to me like your seperator is simply #EXTINF: which starts a new record
tvg-id
tvg-name
tvg-logo
group-title
Are the columns, perhaps an additional column which is after group-title to capture: FR001:13 Eme Rue

Should not be to hard to loop thru the file...
 

namliam

The Mailman - AWF VIP
Local time
Today, 01:52
Joined
Aug 11, 2003
Messages
11,696
Oh btw, best way I found to process these kind of files is simply replace extra information and write back to a comma or semi column seperated file.
?replace(replace(replace(replace(replace(replace("#EXTINF:-1 tvg-id="""" tvg-name=""------|France|------"" tvg-logo="""" group-title=""France"",------|France|------ http://www.WebServer.com/UserName/Password/2866","#EXTINF:", "")," tvg-id=", ",")," tvg-name=", ",")," tvg-logo=", ",")," group-title=", ",")," http:/", ",http:/")
-1,"","------|France|------","","France",------|France|------,http://www.WebServer.com/UserName/Password/2866

If need be you can replace in end of lines with the ext replace, something like
,"#EXTINF:", Chr(10)

Good hunting !
 

sonic8

AWF VIP
Local time
Today, 01:52
Joined
Oct 27, 2015
Messages
998
But sometimes it is saved like it's unformatted, like this:
Your "Not Good List" is almost identical to the apparantly better formatted one. The only difference is that the one uses CR+LF (Carriage return + Line Feed) for line breaks and the other uses only LF, which is common with Unix software.
You can read the file into a string, remove all CR characters and then do the parsing only based on LF characters as record separators. This way both file formats can be treated the same way.

PS: You might want to look at the M3U file format description.
 

vba_php

Forum Troll
Local time
Yesterday, 19:52
Joined
Oct 6, 2019
Messages
2,884
Your "Not Good List" is almost identical to the apparantly better formatted one. The only difference is that the one uses CR+LF (Carriage return + Line Feed) for line breaks and the other uses only LF, which is common with Unix software.
this is extremely useful. thanks. :) It's very possible that my issue was a result of the same thing that Margarit is having here:

https://www.access-programmers.co.u...a-csv-file-via-i-o-stream.309097/post-1664174

https://www.access-programmers.co.u...a-csv-file-via-i-o-stream.309097/post-1665381

also Margarit,

importing your "Not Good List" only gives on record in the Access form. In my thread, another person suggested trying the docmd.TransferText method in VBA. Have you tried that? I wonder if that would work for you here....??
 
Last edited:

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
Your "Not Good List" is almost identical to the apparantly better formatted one. The only difference is that the one uses CR+LF (Carriage return + Line Feed) for line breaks and the other uses only LF, which is common with Unix software.
You can read the file into a string, remove all CR characters and then do the parsing only based on LF characters as record separators. This way both file formats can be treated the same way.

PS: You might want to look at the M3U file format description.
Yes it is the exact same one but I'm just having a hard time to parse it :( .

Regards,
Margarit
 

namliam

The Mailman - AWF VIP
Local time
Today, 01:52
Joined
Aug 11, 2003
Messages
11,696
Did you catch my suggestion of replacing "crap" for seperators in code?
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
another person suggested trying the docmd.TransferText method in VBA. Have you tried that? I wonder if that would work for you here....??
I have tried it in but need to have delimiters in the lines.


Did you catch my suggestion of replacing "crap" for seperators in code?
Yes but how to replace all the text in thousands of lines? that's where I got stuck. ( sorry, newbie here :) ) Probably I'll separate the lines to add CR characters right before #EXTINF.
 

vba_php

Forum Troll
Local time
Yesterday, 19:52
Joined
Oct 6, 2019
Messages
2,884
I have tried it in but need to have delimiters in the lines.
from what I saw in your text files, it looks like you could use spaces (" "). I'll step out of this thread now, because this was the only idea I had for you. I hope you solve it!
 

namliam

The Mailman - AWF VIP
Local time
Today, 01:52
Joined
Aug 11, 2003
Messages
11,696
Something along these lines:
Code:
Sub test()
    Open "C:\YourDocs\Not Good List.txt" For Input As #1
    Dim myLine As String
    Dim myCounter As Double
    Dim myQuote As Integer
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("T")
    
    Do While Not EOF(1)
        Line Input #1, myLine
        myCounter = 1
        Do While myCounter <= Len(myLine)
           ' Debug.Print Mid(myLine, myCounter, 20)
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvg-name") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
            myCounter = myCounter + 1
        Loop
    Loop
    rs.Close
    Set rs = Nothing
End Sub

This assumes a table named T in the database with one column named "tgv-name"

May need to tweak this a little to handle the last record properly and will need additional stuff to parse other fields you want to pick up.

NOTE: though I use tvg-name here, this is a bad name for a column down the line. Probably better to use tvgname or even something completely different like ChannelName or some sort to your requirement or desires.
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
I'll give it a try later and see. :)
Thank you
 

moke123

AWF VIP
Local time
Yesterday, 20:52
Joined
Jan 11, 2013
Messages
3,852
Where is the text file coming from?
Is it a response from a website?
Does it return XML?
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
Where is the text file coming from?
Is it a response from a website?
Does it return XML?
You get it as a link from your IPTV provider. But they tend to give you the full list of channels(which I don't want). That's why I need to open it with access, so I can edit the groups or channels and keep the ones I want, and then save them in a new file and upload it on my tv.
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
Something along these lines:
Code:
Sub test()
    Open "C:\YourDocs\Not Good List.txt" For Input As #1
    Dim myLine As String
    Dim myCounter As Double
    Dim myQuote As Integer
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("T")
   
    Do While Not EOF(1)
        Line Input #1, myLine
        myCounter = 1
        Do While myCounter <= Len(myLine)
           ' Debug.Print Mid(myLine, myCounter, 20)
            If Mid(myLine, myCounter, 8) = "tvg-name" Then
                myCounter = myCounter + 8 + 2
                myQuote = InStr(myCounter, myLine, """")
                rs.AddNew
                rs.Fields("tvg-name") = Mid(myLine, myCounter, myQuote - myCounter)
                rs.Update
                myCounter = myCounter + myQuote
            End If
            myCounter = myCounter + 1
        Loop
    Loop
    rs.Close
    Set rs = Nothing
End Sub

This assumes a table named T in the database with one column named "tgv-name"

May need to tweak this a little to handle the last record properly and will need additional stuff to parse other fields you want to pick up.

NOTE: though I use tvg-name here, this is a bad name for a column down the line. Probably better to use tvgname or even something completely different like ChannelName or some sort to your requirement or desires.
I tried your suggestion but still no luck :(
does anyone have any idea on how could I split the text in the .txt file from this:
Code:
#EXTINF:-1 tvg-id="" tvg-name="------|France|------" tvg-logo="" group-title="France",------|France|-----http://www.WebServer.com/UserName/Password/2866
to this:

Code:
#EXTINF:-1 tvg-id="" tvg-name="------|France|------" tvg-logo="" group-title="France",------|France|------
http://www.WebServer.com/UserName/Password/2866
so I would like the lines to starts at "#EXTINF" and end where "http:" starts and vice versa to start the second line ate "http:" and finish at "#EXTINF".
Any help is highly appreciated,
Thank You
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:52
Joined
Jan 23, 2006
Messages
15,364
Using a few records from your sample files, can you show us exactly what you want as a result?
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
Using a few records from your sample files, can you show us exactly what you want as a result?
I would like it to be like the one in the picture below:
screengrab.PNG


So they are separated like that and i can edit or delete the ones I don't need.

Thanks :)
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:52
Joined
Jan 23, 2006
Messages
15,364
I ran your routine after adjusting file location for Not Good List and got the following:
usingNotSoGood_txt.PNG


What is next? Seems you could work with this, but perhaps there's more to the requirement.
 

riti90

Registered User.
Local time
Today, 00:52
Joined
Dec 20, 2017
Messages
44
I ran your routine after adjusting file location for Not Good List and got the following: View attachment 78697

What is next? Seems you could work with this, but perhaps there's more to the requirement.
But how?? :) I cannot get it to do this the the Not Good List, what did you change in the code to make it work for that? I've been trying so get it work with no luck until now. :)
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:52
Joined
Jan 23, 2006
Messages
15,364
But how?? :) I cannot get it to do this the the Not Good List, what did you change in the code to make it work for that? I've been trying so get it work with no luck until now. :)

I opened your NotGoodList and copied it to Notepad++ and saved the file as iptvOrig.txt

I changed this line of code:
Code:
   ' Open "C:\Users\mp\Desktop\tv_channels_hjh14m2636_plus.txt" For Input As #1
   Open "C:\Users\jack\documents\iptvorig.txt" For Input As #1
I stepped through the code and checked a few values for a record or 2.
Then ran the code directly from the module. Saw that the table was populated, so deleted the records;
then ran the routine from the form button.
 

Users who are viewing this thread

Top Bottom