Jump to content

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


t1m

Recommended Posts

PackMan55

Hello, I found this last night and I think this is exactly what I'm looking for. I've been messing around trying to get it to work without success. I'm confident that I'm messing up something simple. This is what getting when I run main.py:

C:\Users\PackMan\m3u2strm-nextgen>python main.py
Traceback (most recent call last):
  File "C:\Users\PackMan\m3u2strm-nextgen\main.py", line 14, in <module>
    apollomovies = streamClasses.rawStreamList('m3u/iptmovies.m3u')
  File "C:\Users\PackMan\m3u2strm-nextgen\streamClasses.py", line 131, in __init__
    self.readLines()
  File "C:\Users\PackMan\m3u2strm-nextgen\streamClasses.py", line 135, in readLines
    self.lines = [line.rstrip('\n') for line in open(self.filename, encoding="utf8")]
FileNotFoundError: [Errno 2] No such file or directory: 'm3u/iptmovies.m3u'
Link to comment
Share on other sites

PackMan55
2 hours ago, PackMan55 said:

Hello, I found this last night and I think this is exactly what I'm looking for. I've been messing around trying to get it to work without success. I'm confident that I'm messing up something simple. This is what getting when I run main.py:

C:\Users\PackMan\m3u2strm-nextgen>python main.py
Traceback (most recent call last):
  File "C:\Users\PackMan\m3u2strm-nextgen\main.py", line 14, in <module>
    apollomovies = streamClasses.rawStreamList('m3u/iptmovies.m3u')
  File "C:\Users\PackMan\m3u2strm-nextgen\streamClasses.py", line 131, in __init__
    self.readLines()
  File "C:\Users\PackMan\m3u2strm-nextgen\streamClasses.py", line 135, in readLines
    self.lines = [line.rstrip('\n') for line in open(self.filename, encoding="utf8")]
FileNotFoundError: [Errno 2] No such file or directory: 'm3u/iptmovies.m3u'

For what it's worth, I was able to successfully use the older m3u2strm.py script. But I really want to be able to scrape from the URL

Link to comment
Share on other sites

PackMan55
On 13/03/2022 at 06:59, requa3r0 said:

This gets me into another mess where I currently don't have a device with linux up and running. Can I run this on a PC on on my Shield?

With the NextGen script am I supposed to create an M3U file?

FileNotFoundError: [Errno 2] No such file or directory: 'm3u/iptmovies.m3u'

Any suggestions on how to resolve the error?

Link to comment
Share on other sites

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

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

UrlFileExample.m3u 1.18 kB · 32 downloads

So I have put some more work into this. Mostly for selfish reasons. I have been using this on ApolloGroup Iptv to get the TV shows... and... well im never going to watch all those shows SO i wanted to be able to limit shows to the ones i chose. SO i added that feature. then added a feature to create a file of the chosen ones using a gui program to display all the possible shows.  

Both of these are guis and the create Streams is also command line driven. Essentially you use showList to parse the file you want to turn into Streams for emby... pick the tv shows you want (by show not season) and then you can include that in the create streams ui or command line to limit shows to those you selected. it will still include any shows that are in the years you select (i use this to see new shows for this year) but you can avert that by setting the start year to next year :)

CreateStreams-1.0.zip ShowList-1.0.zip

Link to comment
Share on other sites

PackMan55
On 13/03/2022 at 06:59, requa3r0 said:

 

Okay, I installed WSL and ran the script. I entered:

bash m3u2strm.sh 'the url here' 'directory here'

and got this result:

Please wait while converting the M3U to STRM files.
m3u2strm.sh: line 110: php: command not found
All done!

 

Link to comment
Share on other sites

requa3r0

@PackMan55you need PHP in our WLS

https://www.freecodecamp.org/news/setup-a-php-development-environment-on-windows-subsystem-for-linux-wsl-9193ff28ae83/

but seriously ..

Just run a proper linux enviroment, either virtualbox or real live linux box, or even better try the Termux app on a android tv box.

The script will convert your m3u link...which is a playlist..to a nice organized set of folders and STRM files, that you can index in to your library.

I have made a run script, that will hack and chop up the m3u file, to be a perfect match for the converter, to ensure minimal missing titles etc, and a guide how to install everyting and more on a android box.

I have send you a copy of the software to play with, its designed for the Termux app on android. If you run it elsewhere change paths etc.

Are you on github, I can add you to the repo also.

If anyone else is interested, let me know in a PM.

Edited by requa3r0
Link to comment
Share on other sites

gillmacca01
19 hours ago, afogleson said:

So I have put some more work into this. Mostly for selfish reasons. I have been using this on ApolloGroup Iptv to get the TV shows... and... well im never going to watch all those shows SO i wanted to be able to limit shows to the ones i chose. SO i added that feature. then added a feature to create a file of the chosen ones using a gui program to display all the possible shows.  

Both of these are guis and the create Streams is also command line driven. Essentially you use showList to parse the file you want to turn into Streams for emby... pick the tv shows you want (by show not season) and then you can include that in the create streams ui or command line to limit shows to those you selected. it will still include any shows that are in the years you select (i use this to see new shows for this year) but you can avert that by setting the start year to next year :)

CreateStreams-1.0.zip 70.42 kB · 1 download ShowList-1.0.zip 70.52 kB · 1 download

I use appologroup as well,

Have you had any luck with creating strm for their Sports VOD?

Link to comment
Share on other sites

2 hours ago, gillmacca01 said:

I use appologroup as well,

Have you had any luck with creating strm for their Sports VOD?

Hey sorry I actually specifically excluded the sports that i could as I don't watch them much and it's difficult to auto parse the titles. you would need to add that to the parsing section in the 'tools' file

Link to comment
Share on other sites

19 hours ago, PackMan55 said:

 

Okay, I installed WSL and ran the script. I entered:

bash m3u2strm.sh 'the url here' 'directory here'

and got this result:

Please wait while converting the M3U to STRM files.
m3u2strm.sh: line 110: php: command not found
All done!

 

This script that i published is really only useful for people with a bit of python experience as in 95% of cases it will require some bit of customization. 

Link to comment
Share on other sites

requa3r0

@t1m

You should also have a look at https://github.com/erdesigns-eu/M3U2STRM

That scprit does a perfect job.

Especially if you teddy up the m3u a bit for IPTVservice specific flukes and errors.

If you are on git-hub you can have a look at my code/ script where I do quite a bit of house cleaning before i feed the m3u to the strm converter.

This process is important to avoid lost titles and messy out-put.

I can also just send you a PM with a download link.

It wound be fun to have an another programmers opinion on the approach ;O)

Edited by requa3r0
  • Agree 1
Link to comment
Share on other sites

afogleson
On 3/15/2022 at 2:13 PM, gillmacca01 said:

I use appologroup as well,

Have you had any luck with creating strm for their Sports VOD?

To be honest i have not tried but I will have a look and see if it works

  • Thanks 1
Link to comment
Share on other sites

afogleson
58 minutes ago, afogleson said:

To be honest i have not tried but I will have a look and see if it works

I had a slight defect where i always looked for Season and episode information on TV shows. i fixed that  and parsed the current  url and i create the strm files and you can view them in emby if you create the library as "home videos". I just leave the options file empty its possible that would still work  anyway i have attached the version that works with Sports VOD below

CreateStreams-1.0.zip

Link to comment
Share on other sites

gillmacca01
14 minutes ago, afogleson said:

I had a slight defect where i always looked for Season and episode information on TV shows. i fixed that  and parsed the current  url and i create the strm files and you can view them in emby if you create the library as "home videos". I just leave the options file empty its possible that would still work  anyway i have attached the version that works with Sports VOD below

CreateStreams-1.0.zip 71.13 kB · 0 downloads

Thanks. Will give it a try later and let you know how I got on

Link to comment
Share on other sites

afogleson
5 hours ago, afogleson said:

I had a slight defect where i always looked for Season and episode information on TV shows. i fixed that  and parsed the current  url and i create the strm files and you can view them in emby if you create the library as "home videos". I just leave the options file empty its possible that would still work  anyway i have attached the version that works with Sports VOD below

CreateStreams-1.0.zip 71.13 kB · 0 downloads

And here is an improved showList selector that allows selecting movies ... again at least from apollogroup

CreateStreams-1.0.zip

  • Agree 1
Link to comment
Share on other sites

  • 2 weeks later...

This looks like it's hard coded to work only for Apollo vs working with multiple different providers.

From a quick look I only saw movie and show processing but not other types like sports that are available.

I'd change that so it works with many different services and adapts to each new service if something is different.
You might want to build in the ability to use the existing path where the files are stored and used so you can remove items no longer in the feed which is just as important as adding new content.  

A couple quick ways you can do that.  On any file system honoring the Archive bit you can set all strm files as backed up (no archive).  Any media file processed and overwritten will get the archive bit set by the OS due to change.  When strm writing is done anything without the bit set wasn't present so can be deleted or moved.  The archive bit is handy if you want to shell xcopy to do that work for you. If you want to handle it all in code, forget archive bit and look at all strm files with a date/time earlier then when you started processing the m3u files.

The only thing to handle special is a company who used 20 tv show m3us and keeps adding new ones.  So you would want to have 2 directories for these shows.  One holds the current working m3u files and the second is hands off from deleting and is the other 19 m3u files no longer being processed.

I noticed when I used to use them they would sometimes change the files.  It could be a mkv being used but gets replaced and the new one is an mp4.  So every once in a while you will want to reprocess the old lists to freshen them up too.

  • Agree 1
Link to comment
Share on other sites

1 hour ago, cayars said:

This looks like it's hard coded to work only for Apollo vs working with multiple different providers.

From a quick look I only saw movie and show processing but not other types like sports that are available.

I'd change that so it works with many different services and adapts to each new service if something is different.
You might want to build in the ability to use the existing path where the files are stored and used so you can remove items no longer in the feed which is just as important as adding new content.  

A couple quick ways you can do that.  On any file system honoring the Archive bit you can set all strm files as backed up (no archive).  Any media file processed and overwritten will get the archive bit set by the OS due to change.  When strm writing is done anything without the bit set wasn't present so can be deleted or moved.  The archive bit is handy if you want to shell xcopy to do that work for you. If you want to handle it all in code, forget archive bit and look at all strm files with a date/time earlier then when you started processing the m3u files.

The only thing to handle special is a company who used 20 tv show m3us and keeps adding new ones.  So you would want to have 2 directories for these shows.  One holds the current working m3u files and the second is hands off from deleting and is the other 19 m3u files no longer being processed.

I noticed when I used to use them they would sometimes change the files.  It could be a mkv being used but gets replaced and the new one is an mp4.  So every once in a while you will want to reprocess the old lists to freshen them up too.

it isn't specifically designed only for apollo, but was the provider I was using when first making the script.  I also used IPT vod files... more provider could be added but you would need to manually setup the rules for the parsing to determine which ruleset to use.

As for the overwriting files/removing unused files those are great suggestions.  Whenever i update my library i just delete the existing strm directory and recreate all strms even though I know it isn't the most efficient this was just a fast and dirty implementation.

I will definitely checkout the new version next time i update mine.

Link to comment
Share on other sites

I was just thinking.  A better method would be to use a local copy.  Read each strm file to see if the contents match the URL in the m3u file. 99+% of the time it will match so you can just write it back to get an updated file time.  If you find with a different URL write it local and then immediately copy it to the destination.  If you come across new media create it locally and then copy it to the destination. When you get done the list Emby has already been updated for new and changed URLs. The advantage of this is that Emby only needs to reprocess a few new/changed files but not every single one that will get a new timestamp from a regular copy.

The you can do what's mentioned above and delete any local files/folders with a date/time earlier then you started.  Now you just need to sync the destination to your local copy removing files that no longer exist.  Could be done in code but far easier is to just run the script from a batch file.  Right after the script gets done and ends you could run a robocopy line that does this for you I think with this syntax but you'd want to look it up.

ROBOCOPY Source-Dir Dest-Dir /PURGE should do it but I'd look it up.
 

Link to comment
Share on other sites

hooray4me
40 minutes ago, cayars said:

I was just thinking.  A better method would be to use a local copy.  Read each strm file to see if the contents match the URL in the m3u file. 99+% of the time it will match so you can just write it back to get an updated file time.  If you find with a different URL write it local and then immediately copy it to the destination.  If you come across new media create it locally and then copy it to the destination. When you get done the list Emby has already been updated for new and changed URLs. The advantage of this is that Emby only needs to reprocess a few new/changed files but not every single one that will get a new timestamp from a regular copy.

The you can do what's mentioned above and delete any local files/folders with a date/time earlier then you started.  Now you just need to sync the destination to your local copy removing files that no longer exist.  Could be done in code but far easier is to just run the script from a batch file.  Right after the script gets done and ends you could run a robocopy line that does this for you I think with this syntax but you'd want to look it up.

ROBOCOPY Source-Dir Dest-Dir /PURGE should do it but I'd look it up.
 

destination = shutil.copytree(src, dest, dirs_exist_ok=True) ... with shutil if it already exists, then it skips right? So running the above script nightly, any net new content shows up. And yes, the challenge with this becomes the format of the streaming providers info... the M3U structure... IF its a M3U... maybe some error handling to try a download from 0 to x until fail?
Would almost need to be by request to support a new provider? Just thinking outside the box. I've benefitted alot from these forums over the years, anything I can do to pay it forward.

Link to comment
Share on other sites

hooray4me
4 minutes ago, robrhedrick said:

destination = shutil.copytree(src, dest, dirs_exist_ok=True) ... with shutil if it already exists, then it skips right? So running the above script nightly, any net new content shows up. And yes, the challenge with this becomes the format of the streaming providers info... the M3U structure... IF its a M3U... maybe some error handling to try a download from 0 to x until fail?
Would almost need to be by request to support a new provider? Just thinking outside the box. I've benefitted alot from these forums over the years, anything I can do to pay it forward.

I see, it touches the directories on every run, but not the files... I will see if I can do something about that... image.png.0addbd6eb51ee84a43d1965cedbde936.png

image.png.e4f16e25224a8d2dfa33fa8bfe4d9d6c.png

Link to comment
Share on other sites

afogleson
12 hours ago, cayars said:

This looks like it's hard coded to work only for Apollo vs working with multiple different providers.

 

 

Edited by afogleson
Link to comment
Share on other sites

hooray4me

I just updated the code and added in a provider variable. Right now I only know what the format is for apollo, but others could be added in if needed.

I also created a compare function so existing stuff doesn't get "re-written" with a new timestamp.

https://github.com/hooray4me/m3u2strm

 

  • Like 2
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...