Jump to content


Photo

python script to convert m3u file to strm files with emby folder structure (free)

m3u strm vod iptv

  • Please log in to reply
35 replies to this topic

#1 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 12 March 2020 - 08:39 PM

I wanted to add the vod streams from my iptv provider into emby and make it look like the other movie and tv show directories.  I couldn't find a free tool to do this ridiculously simple task, and so I decided to put my python skills to work for other my other emby enthusiasts.  

 

Hope it helps someone.

Depending on the type of m3u file you have, one of these scripts may support it, or you may need to post a few lines of your TV shows and Movies in order for me to add parsing for it.

Check below in the updates to see which script you want to use depending on how your m3u file is formatted.

Type 1:

https://github.com/s...ter/m3u2strm.py

Type 2:

https://github.com/s...r/m3u2strm-2.py

UPDATES

code Last Updated 3/26/2020

Update on 3/26/2020

I have released a new version which is more versitile. You can find it at 

 

https://github.com/s...rm/tree/nextgen

This one handles more m3u types, and has support for live tv streams (though live tv is not yet implemented.)

I was able to generate about 10000 stream files with this in less than 2 minutes.

 

Update on 3/14/2020

In order to make this script more globally compatible... if anyone can PM me the first 25 lines of your m3u file for your VOD TV (please edit out your username and password before sending it) it will allow me to add parsing for other companies m3u files.

 

The current supported formats are as follows:

 

For TV Shows:

#EXTINF:0 group-title="TV VOD",HD : My Hero Academia S04E10
#EXTGRP:TV VOD
http://URL

(for daily running shows like "The Late Show" or "Jimmy Fallon"

#EXTINF:0 group-title="TV VOD",HD : Jimmy Fallon 2019 12 20 Eddie Murphy 720p WEB x264-XLF
#EXTGRP:TV VOD
http://tURL

 

For Movies:

#EXTINF:0 group-title="Movie VOD",HD : The Adventure Of A R I My Robot Friend 2020
#EXTGRP:Movie VOD
http://URLS

Update on 3/18/2020

I have created a second script for the other VOD m3u files mentioned.  It can be found located at : https://github.com/s...r/m3u2strm-2.py

Eventually when I have some time I will make it just a single script, right now the code is not very clean, I need to break stuff into separate classes and functions, then I can have a single script to parse them all, but for now this works.

This one supports TV shows in the following formats:

 

#EXTINF:-1,|FR| Blindspot S01 |FR| Blindspot 01x12 - Super soldat
http://serverIPTV.co...ssword/9975.mkv
#EXTINF:-1,|FR| Burger Quiz S01 |FR| Burger Quiz 01x05
http://serverIPTV.co...word/751209.mkv
 
and Movies in this format:
#EXTINF:-1,|FR| Le plan B
http://serverIPTV.co...word/755418.mkv

Edited by t1m, 26 March 2020 - 08:55 PM.

  • maximumentropy likes this

#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 156699 posts
  • Local time: 02:37 PM

Posted 12 March 2020 - 09:30 PM

Great, thanks for sharing.
  • t1m likes this

#3 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 05:03 PM

Hello,

 

That is very interisting, but... 

 

How can I do to install this script?



#4 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 05:08 PM

How can I do to install this script?


Its not something to "install" but rather run.

To run it first put the script and your m3u file in a folder.

Replace the name of the file in the script with the name of your m3u file.

There is another variable in the script called rootfolder. Change this to the name of the folder you want the strm files and folder structure to be generated

After you update these items run the script with "python3 m3u2strm.py"

I will try to update it to ask for this information from the user when the script is ran sometime tonight or tomorrow.

Sorry it lacks clear instructions. I would say this is geared towards someone with a little bit of python experience.

Good luck, I will post here once I update the code to make it easier to run, in case you don't feel like trying to figure out my instructions above.

If you do get it to run, let me know what you think.

#5 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 05:36 PM

I try... 

 

Python say : 

Traceback (most recent call last):
  File "D:\Bureau\m3u2strm-master\essai\m3u2strm.py", line 33, in <module>
    streamlist = m3ulist.read()
  File "C:\Users\romai\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 4755: character maps to <undefined>


#6 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 05:42 PM

Its not something to "install" but rather run.

To run it first put the script and your m3u file in a folder.

Replace the name of the file in the script with the name of your m3u file.

There is another variable in the script called rootfolder. Change this to the name of the folder you want the strm files and folder structure to be generated

After you update these items run the script with "python3 m3u2strm.py"

I will try to update it to ask for this information from the user when the script is ran sometime tonight or tomorrow.

Sorry it lacks clear instructions. I would say this is geared towards someone with a little bit of python experience.

Good luck, I will post here once I update the code to make it easier to run, in case you don't feel like trying to figure out my instructions above.

If you do get it to run, let me know what you think.

 

I try, I try... Lol

 

Where do you put "strms" directory?

 

Best regards.



#7 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:11 PM

The strms directory should just be an empty directory in the same location as where you execute the script. Make sure you are setting the name of your file in the script where it says m3ufile = "yourfilename.m3u"

I am not sure how it will work with other iptv providers since everyone lists their information a little different, but it looks like that error you got is because it is not finding your m3u file.

#8 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:14 PM


I try...

Python say :
Traceback (most recent call last):
File "D:\Bureau\m3u2strm-master\essai\m3u2strm.py", line 33, in <module>
streamlist = m3ulist.read()
File "C:\Users\romai\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 4755: character maps to <undefined>


Add this to the very first line of the python file, it looks like it could be a text encoding issue which is strange since you are on the same OS i tested it on. But regardless this line will tell python to use utf8

# This Pythin file uses the following encoding: utf-8

#9 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:16 PM

I just made a quick update to the file. It will automatically create the strms directory now if it doesnt exist and also i added the character encoding line.

#10 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 06:23 PM

Add this to the very first line of the python file, it looks like it could be a text encoding issue which is strange since you are on the same OS i tested it on. But regardless this line will tell python to use utf8

# This Pythin file uses the following encoding: utf-8

 

Thanks you so much. But I have the same problem.

 

When I make an error in m3ufile = "yourfileERRORname.m3u", it is not the same Message :

 

Traceback (most recent call last):

  File "C:\m3u2strm-master\m3u2strm.py", line 33, in <module>
    m3ulist = open(m3ufile,"r")
FileNotFoundError: [Errno 2] No such file or directory: 'lifeTV.2020.03.12 (1).m3u'


#11 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 06:28 PM

A new error,

 

Unexpected indent at (line 35):

 

print('Created Streams Directory:', rootdirectory)



#12 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 06:30 PM

Ho I see, that's a tabulation error (for the "else" too)

 

I have again :

Traceback (most recent call last):
  File "C:\m3u2strm-master\m3u2strm-master\m3u2strm.py", line 39, in <module>
    streamlist = m3ulist.read()
  File "C:\Users\romai\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 4755: character maps to <undefined>
>>> 


#13 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 06:36 PM

I try at home, I now have a line 37 error : 

 

File "C:\m3u2strm-master\m3u2strm-master\m3u2strm.py", line 37, in <module>
    print('Streams Directory Found', moviedirectory)
NameError: name 'moviedirectory' is not defined


#14 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:44 PM

Oops i updated the file again that should have been rootdirectory not moviedirectory variable name

#15 Rom1toul1 OFFLINE  

Rom1toul1

    Member

  • Members
  • 11 posts
  • Local time: 08:37 PM

Posted 13 March 2020 - 06:44 PM

My M3U architecture is like that (for serie):

 

#EXTINF:-1,|FR| SERIE (VOST) S01 |FR| SERIE 01x01 - TITLE (VOST)

 
Is-it compatible with your script?


#16 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:46 PM

I fixed the tab error now too

#17 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 06:47 PM

Rom1toul1, on 13 Mar 2020 - 6:44 PM, said:
My M3U architecture is like that (for serie):

#EXTINF:-1,|FR| SERIE (VOST) S01 |FR| SERIE 01x01 - TITLE (VOST)http://serveradress.com:port/series/username/password/764285.mkv


Is-it compatible with your script?

No i dont think it will parse that correctly for tv shows.


Edited by t1m, 13 March 2020 - 07:24 PM.


#18 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 13 March 2020 - 07:04 PM

In order to make this script more globally compatible... if anyone can PM me the first 25 lines of your m3u file for your VOD TV (please edit out your username and password before sending it) it will allow me to add parsing for other companies m3u files.

 

The current supported formats are as follows:

 

For TV Shows:

#EXTINF:0 group-title="TV VOD",HD : My Hero Academia S04E10
#EXTGRP:TV VOD
http://URL

For daily running shows like "The Late Show" or "Jimmy Fallon"

#EXTINF:0 group-title="TV VOD",HD : Jimmy Fallon 2019 12 20 Eddie Murphy 720p WEB x264-XLF
#EXTGRP:TV VOD
http://tURL

For Movies:

#EXTINF:0 group-title="Movie VOD",HD : The Adventure Of A R I My Robot Friend 2020
#EXTGRP:Movie VOD
http://URLS

Edited by t1m, 13 March 2020 - 09:25 PM.


#19 t1m OFFLINE  

t1m

    Advanced Member

  • Members
  • 35 posts
  • Local time: 02:37 PM

Posted 18 March 2020 - 03:14 PM

I have created a second script for the other VOD m3u files mentioned.  It can be found located at : https://github.com/s...r/m3u2strm-2.py

Eventually when I have some time I will make it just a single script, right now the code is not very clean, I need to break stuff into separate classes and functions, then I can have a single script to parse them all, but for now this works.

This one supports TV shows in the following formats:

 

#EXTINF:-1,|FR| Blindspot S01 |FR| Blindspot 01x12 - Super soldat
http://serverIPTV.co...ssword/9975.mkv
#EXTINF:-1,|FR| Burger Quiz S01 |FR| Burger Quiz 01x05
http://serverIPTV.co...word/751209.mkv
 
and Movies in this format:
#EXTINF:-1,|FR| Le plan B
http://serverIPTV.co...word/755418.mkv

Edited by t1m, 18 March 2020 - 03:18 PM.


#20 requa3r0 OFFLINE  

requa3r0

    Newbie

  • Members
  • 9 posts
  • Local time: 08:37 PM

Posted 20 March 2020 - 09:39 AM

Hi Nice work

 

I did not test it yet.

 

As of now im using this webpage

 

https://iptv-tools.c...ols/m3u-to-strm

Propplerly use Name...not the tvg-name (Default)

 

This could also be a solusion for some.

 

I have emailed with the owner, and its alowed to use the API to scrpit a download of the strm.zip

 

I have recieved the API from him but needed to edit it a bit to work porpperly.

 

Here is is as a gift to all

curl -X POST -d '{"url":"http://tv..---some--link--and--login--stuff----&type=m3u_plus&output=ts","tag":"name","movies":true,"series":true}' https://tools.erdesigns.eu/strm >> /var/lib/someprogram/strm.zip

NB

 

As a bonus ill give the bash command to spilt a M3U file into each contry and VOD section

#download

wget --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0" "http://tv...---some--link--and--login--stuff----&&type=m3u_plus&output=ts"-O /var/lib/somefile.m3u

#split M3U
csplit -z /var/lib/hts/.xmltv/somefilename.m3u /'tvg-name=" ^v'/ '{*}'

thenmove the propper xx01 and xx02 etc to correct lable.m3u file ass needed.

 

I found a "black bar" shown as '^v' in my linux server (shown correctly on my mac ?? ) deviding each section in the M3U file..and then it was easy to split the file up;O)

 

Investigate our own file for the devider key!

 

replace /'tvg-name=" ^v'/ with /your-key/

 

Then, just add the file header to your new files and you are good to go

    #file-header
    sed -i '1s/^/#EXTM3U\n/' /var/lib/hts/.xmltv/somefile.DK.M3U



Smack everyting into a script and run it in cron...and use them for emby and kodi etc.

 

In Emby, you can now add each M3u sectment  as a TV tuner...and asign correct EPG link to each one.

 

An you can make the strm folder/ files for the index of VOD stuff

 

Pretty handy ;O)


Edited by requa3r0, 20 March 2020 - 10:30 AM.






Also tagged with one or more of these keywords: m3u, strm, vod, iptv

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users