Jump to content
t1m

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

Recommended Posts

t1m

well, I played with it for a while tonight but didn't get it finished.  I ported the m3u parser into c# and created a really simple channel plugin but I have not yet got it to add the m3u yet, just a list of individual streams... I am having trouble figuring out how to make those streams be parsed as movies or tv, I also am not sure if i can have both movies and tv series in one channel... 

I'm considering using a different method, whereby it would just be a plugin that can create the strm filesystem, but using this method I have not found how to create new libraries programatically yet.  It will take a while before I have anything ready to show the community!  Still alot of fun.

Share this post


Link to post
Share on other sites
requa3r0

Very good news

 

A fork of the IPTV app what will allow M3u import...would be great.

As i see it. The Emby premium feature to load m3u as a tv tvtuner...to pair with EPG data...is fine...for everyone who have payed for a license.

I geuss some pro features must exist..and im good with that..i have a lifetime license.

 

But it makes no sense that every free user of empy has to sit at type in hundreds of IPTV links in the IPTV app...and maintain them as they update..just because the IPTV app does not support bulk import. This needs to be resolved.

 

But ...as a solusion first...a script that will convert a m3u to IPTV config file..to sideload the IPTV app...will most deffentliy help a lot.

 

I have no shares in this problem..but would like to see it solved anyway ;O)

Share this post


Link to post
Share on other sites
requa3r0
Posted (edited)

Just to clear up what i mean with side load the original IPTV app.

 

It has all the tv channels saved in a config file hidden here.

/var/lib/emby/plugins/configurations/MediaBrowser.Channels.IPTV.xml
 

On a debian 9 linux anyway.

 

The trick is to parse the M3u file, or subsection heroff...with live TV channels...

NOT VOD (This is sideloaded with strm folder/files and indexed as normal based on content etc.)

 

The file structure is as follows

<?xml version="1.0"?>
<PluginConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Bookmarks>
    <Bookmark>
      <Name>DR 1 DK GEO</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1514675161.6633.png</Image>
      <Path>https://dr01-lh.akamaihd.net/i/live/dr01_0@147054/master.m3u8?b=100-10000</Path>
      <Protocol>Http</Protocol>
      <UserId>***** USERID *****</UserId>
    </Bookmark>
    <Bookmark>
      <Name>DR 2 DK GEO</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1514675219.3517.png</Image>
      <Path>https://dr02-lh.akamaihd.net/i/live/dr02_0@147055/master.m3u8?b=100-10000</Path>
      <Protocol>Http</Protocol>
      <UserId>***** USERID *****</UserId>
    </Bookmark>
    <Bookmark>
      <Name>DR 3 DK GEO</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1514675240.2972.png</Image>
      <Path>https://dr03-lh.akamaihd.net/i/live/dr03_0@147056/master.m3u8?b=100-10000</Path>
      <Protocol>Http</Protocol>
      <UserId>***** USERID *****</UserId>
    </Bookmark>
    <Bookmark>
      <Name>DR KULTUR DK GEO</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1514675260.777.png</Image>
      <Path>https://dr04-lh.akamaihd.net/i/live/dr04_0@147057/master.m3u8?b=100-10000</Path>
      <Protocol>Http</Protocol>
      <UserId>***** USERID *****</UserId>
    </Bookmark>
    <Bookmark>
      <Name>DR RAMASJANG DK GEO</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1514675309.4873.png</Image>
      <Path>https://dr05-lh.akamaihd.net/i/live/dr05_0@147058/master.m3u8?b=100-10000</Path>
      <Protocol>Http</Protocol>
      <UserId>***** USERID *****</UserId>
    </Bookmark>

etc etc etc

     <Bookmark>
      <Name>Showtime</Name>
      <Image>https://danishbits.org/static/bitbucket/users/1549643055.2418.png</Image>
      <Path>http://80.80.160.168/live/7/live.m3u8</Path>
      <Protocol>Http</Protocol>
      <UserId>7e77537889044e159cc8072ac2928d88</UserId>
    </Bookmark>
    <Bookmark>
      <Name>TV3max</Name>
      <Image />
      <Path>http://192.168.1.100:9981/play/stream/service/d431a4cab1994e0c6291682b8e37090b?title=TV3%20MAX%20%2F%20YouSee</Path>
      <Protocol>Http</Protocol>
      <UserId>20fe5e5e034743f79874cca08852fc47</UserId>
    </Bookmark>
  </Bookmarks>
</PluginConfiguration>

.

.

All you need to do is parse the M3u file to this structure...overwrite the config file...and start emby

(which must be stoped duing the overwrite)

 

Done.

 

You now have live TV.. (no EPG data ) in the IPTV app

And VOD in your standard library via the strm folder/files.

 

all done

 

enjoy

 

Requaero

Edited by requa3r0

Share this post


Link to post
Share on other sites
t1m

Hey Requaero

Thanks for showing me that. I already am half way through making a plugin which takes the m3u url and generates the libraries. Just trying to decide if i should use a channel or do it through the filesystem with strm files.

 

I will add the ability to do what you are asking to add to the iptv plugin to the python script tonight.

 

Is there any chat rooms related to development of emby stuff? If not we should make one. Either Irc or discord

Share this post


Link to post
Share on other sites
requa3r0

I'm not aware of any chatroom...its been years since i used irc.

Can you make the pytho script as an individual script..just to parse the M3u to IPTV xml file.

It would make it a bit more easy to work with.

 

I think i will use the mu3 tuner + epg data..for my main channels..and IPTV for extra...such as the 450 US channels etc.

 

I tried your script..but did not have any success ;O(

root@xxxxx:/var/lib/hts/.xmltv/test# ./run.py 
./run.py: line 18: 
This is a python script to parse an m3u file that has a list of VOD media, and create a folder structure like follows:
/workspace folder
  /groupname
    /title(year)
      /resolution
        title.strm
title.strm is a text file which has the URL to the stream inside of it
the strm files can then be used in your emby media server as defined here:
https://support.emby.media/support/solutions/articles/44001159147-strm-files
additional reference material here:
https://emby.media/community/index.php?/topic/674-media-files-folders-structure/
https://support.emby.media/support/solutions/articles/44001159102-movie-naming
https://support.emby.media/support/solutions/articles/44001159319-library-setup
I plan to do some more work to this at some point, but i just needed something quick n dirty.  
Change the m3u file name to the m3u file you want to use, and root directory is relative to
the working directory which the python script is executed in ...
: No such file or directory
./run.py: line 19: import: command not found
./run.py: line 21: m3ufile: command not found
./run.py: line 23: rootdirectory: command not found
./run.py: line 25: syntax error near unexpected token `('
./run.py: line 25: `m3ulist = open(m3ufile,"r")'
root@xxxxx:/var/lib/hts/.xmltv/test# 

I did set

import os
#this should be the name of your m3u and in the same directory as this python file.
m3ufile = "danishM3u.m3u"
#root directory should be created already, it is where the group folders will be located. relative to the working directory.
rootdirectory = "strms"


?

Share this post


Link to post
Share on other sites
requa3r0
root@xxxx:/var/lib/hts/.xmltv/test# python run.py
Traceback (most recent call last):
  File "run.py", line 44, in <module>
    stream.append(info[1]) #language
IndexError: list index out of range

do i need to run it as >python run.py

 

And what is this errro

Share this post


Link to post
Share on other sites
t1m

Right now it will only parse the two types of vod m3u as i show in my first post in this thread. There are two scripts the first one does the first type and the second does the second type.

It wont parse livetv m3u just yet.

 

You need to run it with python3 also

Share this post


Link to post
Share on other sites
t1m

I have updated the program... it is currently located at https://github.com/s...rm/tree/nextgen

You'll need to clone the whole branch then set your m3u file name in main.py, then python3 main.py

 

This one is faster, more versitile (handles a broader range of m3u file types) and, has parsing support for live tv streams (though it does not generate the stream files for live streams)

try it out, let me know what you think.

Share this post


Link to post
Share on other sites
MaMoUs

Hello,

Thank you for the awesome work you have done.

when I try to run main.py i get the following error

m3u2strm-nextgen\streamClasses.py", line 1
    pytimport asyncio
              ^
SyntaxError: invalid syntax

i went to streamcalsses.py and removed the first line. it ran for a second then gave another error.

Traceback (most recent call last):
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\main.py", line 6, in <module>
    examplelist = streamClasses.rawStreamList('TV-VOD-2020-03-27.m3u')
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 125, in __init__
    self.parseLine()
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 157, in parseLine
    self.parseStream(thisline, nextline)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 198, in parseStream
    self.parseVodTv(streaminfo, streamURL)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 214, in parseVodTv
    episodeinfo = tools.parseEpisode(title)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\tools.py", line 202, in parseEpisode
    if seasonepisode.end() - seasonepisode.start() > 6 or len(seasonepisode.group()) == 5:
AttributeError: 'str' object has no attribute 'end'

 

Share this post


Link to post
Share on other sites
t1m

 

Hello,

Thank you for the awesome work you have done.

when I try to run main.py i get the following error

m3u2strm-nextgen\streamClasses.py", line 1
    pytimport asyncio
              ^
SyntaxError: invalid syntax

i went to streamcalsses.py and removed the first line. it ran for a second then gave another error.

Traceback (most recent call last):
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\main.py", line 6, in <module>
    examplelist = streamClasses.rawStreamList('TV-VOD-2020-03-27.m3u')
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 125, in __init__
    self.parseLine()
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 157, in parseLine
    self.parseStream(thisline, nextline)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 198, in parseStream
    self.parseVodTv(streaminfo, streamURL)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\streamClasses.py", line 214, in parseVodTv
    episodeinfo = tools.parseEpisode(title)
  File "C:\Users\\Downloads\m3u2strm-nextgen\m3u2strm-nextgen\tools.py", line 202, in parseEpisode
    if seasonepisode.end() - seasonepisode.start() > 6 or len(seasonepisode.group()) == 5:
AttributeError: 'str' object has no attribute 'end'

I had that error too, I thought I fixed it.  I will have to push a code update, I will let you know here once it is done.

Share this post


Link to post
Share on other sites
t1m

I pushed an update and think i fixed that error now... Sorry for the hassle, it's still a Work In Progress.

Share this post


Link to post
Share on other sites
travisolson99

@t1m  I have tried running your python script and am having issues.  I am no computer engineer, but am I to run the main.py to start the job?  I may need some help...LOL

Share this post


Link to post
Share on other sites
cayars
3 hours ago, travisolson99 said:

@t1m  I have tried running your python script and am having issues.  I am no computer engineer, but am I to run the main.py to start the job?  I may need some help...LOL

Did you install Python?

Share this post


Link to post
Share on other sites
t1m
4 hours ago, travisolson99 said:

@t1m  I have tried running your python script and am having issues.  I am no computer engineer, but am I to run the main.py to start the job?  I may need some help...LOL

Be sure to install python 3. You will then need to modify the main.py file to either point to or download your m3u files... it is only configured to parse certain m3u files so you could get an error and if so please post it in this thread.

 

Basically download the repository, and edit the main.py file as i described. Then to run it do:

Python3 main.py

From your command line in that folder.

There is someone else on the forum who has a tool on a website and a gui tool you can download which is a bit simpler to use.

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

×
×
  • Create New...