Jump to content

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


t1m

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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"


?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'

 

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

  • 4 months later...
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 months later...

I used the python stuff but... well my python is not what it used to be it worked fine but I wanted to make some changes... and have a ui and so on... So I decided to write it all in java. so there is not any documentation yet im still working on adding some features but here is the long and short of it initially. 

1) you can use the zip or tar archive in build/distributions... make sure your JDK is JDK 11 

2) you can compile right now it is set up for JDK 11 not sure if a 10 or lower would work but higher should work 

3) when you run and get the ui you can either have it parse a file or a url... so select that.

4) if you chose file browse for your M3U file.  if you have issues (it never finishes etc.,... send me a sample of the file (I already found some tags that it was not handling).

5) choose the output directory an maybe years... as long as your m3u identifies things with XXXXX (YYYY) where XXXX is the name and YYYY is the year in parens then it will filter the m3u and only create items that have the yeas in it (it is a from year to end year...) 

6) you can run this over and over and over and it only adds new things. kind of nice once you have a large VOD library installed to update with just the new things. 

7) there is one hidden feature... for this you select file but the file you browse for is not m3u it is aby file that is formatted like so:

#URLS

URL1 

URL2 ...

 

it will parse all the urls in that file I do this with my IPTV providers 20+ TV files to get new episodes without working on it. 

 

 

Finally it does not yet have a command line interface (so kind of bad for automating this right now) but that is coming once i have  some time to work on that. 

it should in general work with most of the m3u files I have tested. so let me know 

 

It is available here: https://github.com/afogleson/emby-m3uToStrm  or the zip is in the attached file

 

Allen Fogleson

CreateStreams-1.0.zip

Link to comment
Share on other sites

1 minute ago, afogleson said:

I used the python stuff but... well my python is not what it used to be it worked fine but I wanted to make some changes... and have a ui and so on... So I decided to write it all in java. so there is not any documentation yet im still working on adding some features but here is the long and short of it initially. 

1) you can use the zip or tar archive in build/distributions... make sure your JDK is JDK 11 

2) you can compile right now it is set up for JDK 11 not sure if a 10 or lower would work but higher should work 

3) when you run and get the ui you can either have it parse a file or a url... so select that.

4) if you chose file browse for your M3U file.  if you have issues (it never finishes etc.,... send me a sample of the file (I already found some tags that it was not handling).

5) choose the output directory an maybe years... as long as your m3u identifies things with XXXXX (YYYY) where XXXX is the name and YYYY is the year in parens then it will filter the m3u and only create items that have the yeas in it (it is a from year to end year...) 

6) you can run this over and over and over and it only adds new things. kind of nice once you have a large VOD library installed to update with just the new things. 

7) there is one hidden feature... for this you select file but the file you browse for is not m3u it is aby file that is formatted like so:

#URLS

URL1 

URL2 ...

 

it will parse all the urls in that file I do this with my IPTV providers 20+ TV files to get new episodes without working on it. 

 

 

Finally it does not yet have a command line interface (so kind of bad for automating this right now) but that is coming once i have  some time to work on that. 

it should in general work with most of the m3u files I have tested. so let me know 

 

It is available here: https://github.com/afogleson/emby-m3uToStrm  or the zip is in the attached file

 

Allen Fogleson

CreateStreams-1.0.zip 17.34 kB · 0 downloads

Ohh and here is an example file for how to handle multiple urls

UrlFileExample.m3u

Link to comment
Share on other sites

  • 4 months later...

@t1m First, thank you for the program.  I got it partially working, but after creating 277 strm files, it stops and gives me the following message:

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    apollomovies = streamClasses.rawStreamList('m3u/movies.m3u')
  File "/media/2TB_Live/VOD/stream/streamClasses.py", line 132, in __init__
    self.parseLine()
  File "/media/2TB_Live/VOD/stream/streamClasses.py", line 164, in parseLine
    self.parseStream(thisline, nextline)
  File "/media/2TB_Live/VOD/stream/streamClasses.py", line 210, in parseStream
    self.parseVodMovie(streaminfo, streamURL)
  File "/media/2TB_Live/VOD/stream/streamClasses.py", line 256, in parseVodMovie
    language = tools.languageMatch(title)
  File "/media/2TB_Live/VOD/stream/tools.py", line 181, in languageMatch
    languagematch = re.compile('[|][A-Z][A-Z][|]', re.IGNORECASE).search(line)
TypeError: expected string or bytes-like object

Any ideas on how to fix this?

 

Edited by cycochuck
account info accidentally sent
Link to comment
Share on other sites

Not for me it doesn't, so I wrote my own custom job for events.

I've seen another python script that I think does handle this.

Link to comment
Share on other sites

1 hour ago, gillmacca01 said:

Can this handle sport VOD?

Hi I didn't write the parser for sports...

4 hours ago, cycochuck said:

Ok, did some more digging and the program dies with any movie or tv show that has a # in the title.

in the "tools" class i am using the python regular expression library to parse the file.  would need to look in there.

On 1/6/2021 at 7:08 PM, afogleson said:

I used the python stuff but... well my python is not what it used to be it worked fine but I wanted to make some changes... and have a ui and so on... So I decided to write it all in java. so there is not any documentation yet im still working on adding some features but here is the long and short of it initially. 

1) you can use the zip or tar archive in build/distributions... make sure your JDK is JDK 11 

2) you can compile right now it is set up for JDK 11 not sure if a 10 or lower would work but higher should work 

3) when you run and get the ui you can either have it parse a file or a url... so select that.

4) if you chose file browse for your M3U file.  if you have issues (it never finishes etc.,... send me a sample of the file (I already found some tags that it was not handling).

5) choose the output directory an maybe years... as long as your m3u identifies things with XXXXX (YYYY) where XXXX is the name and YYYY is the year in parens then it will filter the m3u and only create items that have the yeas in it (it is a from year to end year...) 

6) you can run this over and over and over and it only adds new things. kind of nice once you have a large VOD library installed to update with just the new things. 

7) there is one hidden feature... for this you select file but the file you browse for is not m3u it is aby file that is formatted like so:

#URLS

URL1 

URL2 ...

 

it will parse all the urls in that file I do this with my IPTV providers 20+ TV files to get new episodes without working on it. 

 

 

Finally it does not yet have a command line interface (so kind of bad for automating this right now) but that is coming once i have  some time to work on that. 

it should in general work with most of the m3u files I have tested. so let me know 

 

It is available here: https://github.com/afogleson/emby-m3uToStrm  or the zip is in the attached file

 

Allen Fogleson

CreateStreams-1.0.zip 17.34 kB · 3 downloads

Nice job on the java fork!

Link to comment
Share on other sites

On both the python and java, they both die whenever something has a # in its name.  I admit, I suck at coding.  At this point I'm just trying to figure out how to either strip out the # or to ignore any name that has it.  I hope I can get the python one doing this because I prefer having it able to auto run as a cron job.  Is this even possible, or am I wasting my time?

Link to comment
Share on other sites

  • 8 months later...

Not sure if this is still active or not, but a couple things i noticed when running the script... I did receive some errors around wget missing when running this script within Windows. 

Downloaded the module... https://pypi.org/project/wget/#files and dropped wget.py within the same folder.. sill had errors and they broke it down to command line and did one at a time. Some reason with the link I have, it complains about me using this. 

I did make my own script and still use the majority of yours... 

I use powershell to download my m3u file:

wget  <URLFROMIPTVCompany> -o <SourceTom3u2strm>\vod.m3u

and dump it in the same location where teh m3utostrm folder is located.

 

on the main.py file, i removed:

ipttvurl = 'https://tv123.me/m3u.php' #replace url with your link, or comment this line out and put the filename in the streamlist below.
'''for i in range(20):
  url = baseurl + str(i)
  print(wget.download(url, ('m3u/apollotvshows-'+str(i)+'.m3u')))
  apollolist = streamClasses.rawStreamList('m3u/apollotvshows-'+str(i)+'.m3u')'''

print(wget.download(iptmovieurl, ('m3u/iptmovies.m3u'))) #if not downloading comment out this line.

and am now left with:

import tools
import logger
import streamClasses
import wget
import sys

apollomovies = streamClasses.rawStreamList('vod.m3u')

I can then now create a ps1 file to execute the the wget file on a daily basis and run the main.py to update my VOD content.. I'm sure i can do this on python too.. i'm just not as familiar with it! 

Great job on creating the script! @t1m

 

Updated due to windows paths too long.... 

If you are running windows and do generate the folder structure, you may run into path limit of over 260 chars. If you do, open regedit, navigated to 

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

And modify the REG_DWORD key called LongPathsEnabled and change it form 0 to 1. You may not have to reboot your computer, but if it does not allow over 260 chars after modifying, reboot your computer and retry. If you have issues, you can simply change the key back to 0 and then you will not be able to browse to the location. 

Please note: THIS ONLY WORKS ON WINDOWS 10 and higher. This means Windows Server 2016 will also have this same setting.

Edited by ctyokley
Link to comment
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...