Jump to content

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


Recommended Posts

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/silence48/m3u2strm/blob/master/m3u2strm.py

Type 2:

https://github.com/silence48/m3u2strm/blob/master/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/silence48/m3u2strm/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
  • Like 1
Link to post
Share on other sites

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.

Link to post
Share on other sites
Rom1toul1

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>
Link to post
Share on other sites
Rom1toul1

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

 

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

Link to post
Share on other sites

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.

Link to post
Share on other sites
Rom1toul1

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'
Link to post
Share on other sites
Rom1toul1

A new error,

 

Unexpected indent at (line 35):

 

print('Created Streams Directory:', rootdirectory)

Link to post
Share on other sites
Rom1toul1

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>
>>> 
Link to post
Share on other sites
Rom1toul1

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
Link to post
Share on other sites

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

Link to post
Share on other sites
Posted (edited)
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
Link to post
Share on other sites
Posted (edited)

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
Link to post
Share on other sites
Posted (edited)

I have created a second script for the other VOD m3u files mentioned.  It can be found located at : https://github.com/silence48/m3u2strm/blob/master/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
Link to post
Share on other sites
requa3r0

Hi Nice work

 

I did not test it yet.

 

As of now im using this webpage

 

https://iptv-tools.com/app/tools/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
Link to post
Share on other sites
requa3r0

I have a quisiton to t1m.

 

Your script is pretty nice, so you are deffently most cable of writing code

 

Would you be intersted in making a M3u to IPTV app setup file converter.

 

To sideload the M3u into the IPTV app.

 

I have Emby Premiere, and use the M3U tuner and EPG data setup as you can with a license,  but lots dont have alicense and dont care about EPG data etc.

Its very tedious to mannualy load and maintain the IPTV app, with hundreds of TV channels.

Its a bit strange that the IPTV app does not have a bulk loader interface, to load and maintain the channels.

 

so...Could you script a M3u to MediaBrowser.Channels.IPTV.xml generator ?

 

To automatically sideload the IPTV app with automatically updated M3u links?

 

Just an idear to make Emby more versatile.

 

Requaero

 

Link to post
Share on other sites

I have a quisiton to t1m.

 

Your script is pretty nice, so you are deffently most cable of writing code

 

Would you be intersted in making a M3u to IPTV app setup file converter.

 

To sideload the M3u into the IPTV app.

 

I have Emby Premiere, and use the M3U tuner and EPG data setup as you can with a license,  but lots dont have alicense and dont care about EPG data etc.

Its very tedious to mannualy load and maintain the IPTV app, with hundreds of TV channels.

Its a bit strange that the IPTV app does not have a bulk loader interface, to load and maintain the channels.

 

so...Could you script a M3u to MediaBrowser.Channels.IPTV.xml generator ?

 

To automatically sideload the IPTV app with automatically updated M3u links?

 

Just an idear to make Emby more versatile.

 

Requaero

Hi Requaero.

I will have to research it, but this was something I was already thinking of doing. I was planning to fork the plugin called "iptv" to allow someone to load their VOD m3u direct into this to get the VOD libraries, thereby bypassing the strm file requirement alltogether.  I'm not experienced enough with emby yet to know how to do it, and even if I use this script i'll have to port it to c# first.

I will make this my goal but it will be at least a few weeks before i finish it.  I'll keep you updated here.

Link to post
Share on other sites

Hi Nice work

 

I did not test it yet.

 

As of now im using this webpage

 

https://iptv-tools.com/app/tools/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)

 

Since the world has gone crazy with corona virus, I have had a lot of extra time on my hands (as I'm sure many of you can relate) and so I've decided to start writing the plugin to accept VOD m3u url without putting them into the EPG guide but rather have a library. For me having them in their own library gives me amazing imdb/moviedb/tvdb integrations that are not possible to get in the epg guide without adding extra info into the m3u.

I found using the EPG/ tvtuner for vod caused my emby to become SUPER slow adding the guid, plus it did not seem to integrate it with tvdb and imdb correctly.  I am working on a plugin to try to make it add vod movie and vod tv libraries with just inputting a m3u url, but it is a ways out.

 

I did see the website you mentioned, but I was more comfortable parsing my files locally instead of trusting a third party with my streams... more though I just wanted to play around in python on it.

 

I have a new version of the script almost ready to relase which is much simpler for the end user to use. It uses classes and functions in order to run more efficiently, and I've made some improvements to the parser.  I guess I could also make one that uses the API you mentioned. For most users that website and/or using the api as you mention above is probably simpler than trying to use my python script.

 

If you want to help contribute could you give me any examples of your vod m3u section... tv and movie, just a few lines showing distinct examples, be sure to edit out your username and password and server urls.

 

Have a good day everyone.  

 

Link to post
Share on other sites

I have a quisiton to t1m.

 

Your script is pretty nice, so you are deffently most cable of writing code

 

Would you be intersted in making a M3u to IPTV app setup file converter.

 

To sideload the M3u into the IPTV app.

 

I have Emby Premiere, and use the M3U tuner and EPG data setup as you can with a license,  but lots dont have alicense and dont care about EPG data etc.

Its very tedious to mannualy load and maintain the IPTV app, with hundreds of TV channels.

Its a bit strange that the IPTV app does not have a bulk loader interface, to load and maintain the channels.

 

so...Could you script a M3u to MediaBrowser.Channels.IPTV.xml generator ?

 

To automatically sideload the IPTV app with automatically updated M3u links?

 

Just an idear to make Emby more versatile.

 

Requaero

I should ask from what you are describing. I THINK (not sure because i haven't tried) that the plugin called "IPTV" does what you are looking for

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
×
×
  • Create New...