VOD Image python script (Windows and Linux versions)

Windows

from asyncio.windows_events import NULL
from email.mime import image
from multiprocessing.sharedctypes import Value
from operator import contains
from unittest import result, skip
from urllib import response
from wsgiref import headers
from re import search
import requests
from ipytv import playlist
from ipytv.channel import IPTVAttr, IPTVChannel
from ipytv.playlist import M3UPlaylist
from ipytv.doctor import M3UDoctor, M3UPlaylistDoctor
import os
import re

# variables
# Import TMDb from tmdbv3api module using the import keyword
from tmdbv3api import TMDb

# Import Movie from tmdbv3api module using the import keyword 
from tmdbv3api import Movie
from tmdbv3api import TV

# Initialize the TMDb object and store it in a variable 
tmdbobj=TMDb()

# Using the export command below, you may also export your API key as an environment variable.
# command:- export TMDb_API_KEY= 'XXX123ABC456XYZ789' << example obviously

# Apply language attribute to the above tmdb object to specify the 
# language of the data must be get from TMDB. It is optional.
tmdbobj.language = 'en'

# Set debug to True to make it enable for debugging.
tmdbobj.debug = True

# Initialize the Movie object and store it in another variable 
movieobj=Movie()
tvobj=TV()


if __name__ == "__main__":

    ############################################################
    # ONLY CHANGE THESE USER DEFINED VARIABLES IN THIS SECTION #
    ############################################################

    # your TMDB api key
    TMDb.api_key= 'XXX123ABC456XYZ789'

    # your .m3u url from provider. If using a file use the location
    # where it is stored and change pl = playlist.loadu(M3Uurl) >> pl = playlist.loadf(filename)
    M3Uurl = "https://XXXXX.com/iptv/123456/ab3m7j2g8x/YYY"

    # location of .m3u file output on completion
    file = "C:/Users/MyPC/Google Drive/MyVOD.m3u"

    ############################################################
      ##########     ##########     ##########     ##########
    ############################################################


    # open file and write #NEXTM3U on the first line and close it
    file2 = open(file, "w+")
    file2.write("#EXTM3U" + '\n')
    file2.close

    # load playlist and leverage m3u-ipytv, sort if Movie or TV VOD
    pl = playlist.loadu(M3Uurl)
    channel = IPTVChannel(pl)
    for channel in pl:
        type = channel.attributes
        Mov = "{'group-title': 'Movie VOD'}"
        Tv = "{'group-title': 'TV VOD'}"
       
       # if Movie filter title
        if str(Mov) == str(type):            
                title0 = channel.name
                t1 = re.compile('(\s*)HD : (\s*)')
                title1 = t1.sub(' ', title0)
                t2 = re.compile('(\s*)2022(\s*)')
                title2 = t2.sub(' ', title1)

                # for each movie title search for TMDB poster and rebuild .m3u and append
                url = channel.url
                search = movieobj.search(title2)
                for index, res in enumerate(search):
                    if not index:
                        if res is not None:
                            Poster =  "https://image.tmdb.org/t/p/w500" + str(res.poster_path)
                            reject = "https://image.tmdb.org/t/p/w500None"

                            # if poster found
                            if Poster != reject:                                
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str("tvg-logo=" + '"' + Poster + '",' + " group-title=" + '"' + "Movie VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:Movie VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
                            # poster not found
                            else:
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str(" group-title=" + '"' + "Movie VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:Movie VOD" '\n')
                                file3.write(url + '\n')
                                file3.close                            


        # if TV filter title
        elif str(Tv) == str(type):        
                
                title0 = channel.name
                t1 = re.compile('(\s*)HD : | AU | NZ(\s*)')
                title1 = t1.sub(' ', title0)
                t2 = re.compile('(\s*)[S]+[0-9]+[0-9](\s*)')
                title2 = t2.sub(' ', title1)
                t3 = re.compile('(\s*)[E]+[0-9]+[0-9](\s*)')
                title3 = t3.sub(' ', title2)
                t4 = re.compile('(\s*)720p WEB h264(\s*)', re.IGNORECASE)
                title4 = t4.sub(' ', title3)
                t5 = re.compile('(\s*)KOGi(\s*)', re.IGNORECASE)
                title5 = t5.sub(' ', title4)
                t6 = re.compile('(\s*)GLHF(\s*)', re.IGNORECASE)
                title6 = t6.sub(' ', title5)
                t7 = re.compile('(\s*)720p WEB H264-JEBAITED(\s*)', re.IGNORECASE)
                title7 = t7.sub(' ', title6)
                t8 = re.compile('(\s*)[0-9]+[0-9](\s*)')
                title8 = t8.sub(' ', title7)
                t9 = re.compile('(\s*)-JEBAITED(\s*)', re.IGNORECASE)
                title9 = t9.sub(' ', title8)
                
                # for each tv title search TMDB for poster and rebuild .m3u and append
                url = channel.url
                search = tvobj.search(title9)
                for index, res in enumerate(search):
                    if not index:                        
                        if res is not None:                            
                            Poster =  "https://image.tmdb.org/t/p/w500" + str(res.poster_path)
                            reject = "https://image.tmdb.org/t/p/w500None"
                            # if poster found
                            if Poster != reject:
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str("tvg-logo=" + '"' + Poster + '",' + " group-title=" + '"' + "TV VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:TV VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
                            # poster not found
                            else:            
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str(" group-title=" + '"' + "TV VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:TV VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
   


        

        

Linux

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from email.mime import image
from multiprocessing.sharedctypes import Value
from operator import contains
from unittest import result, skip
from urllib import response
from wsgiref import headers
from re import search
import requests
from ipytv import playlist
from ipytv.channel import IPTVAttr, IPTVChannel
from ipytv.playlist import M3UPlaylist
from ipytv.doctor import M3UDoctor, M3UPlaylistDoctor
import os
import re

# variables
# Import TMDb from tmdbv3api module using the import keyword
from tmdbv3api import TMDb

# Import Movie from tmdbv3api module using the import keyword 
from tmdbv3api import Movie
from tmdbv3api import TV

# Initialize the TMDb object and store it in a variable 
tmdbobj=TMDb()

# Using the export command below, you may also export your API key as an environment variable.
# command:- export TMDb_API_KEY= 'XXX123ABC456XYZ789' << example obviously

# Apply language attribute to the above tmdb object to specify the 
# language of the data must be get from TMDB. It is optional.
tmdbobj.language = 'en'

# Set debug to True to make it enable for debugging.
tmdbobj.debug = True

# Initialize the Movie object and store it in another variable 
movieobj=Movie()
tvobj=TV()


if __name__ == "__main__":

    ############################################################
    # ONLY CHANGE THESE USER DEFINED VARIABLES IN THIS SECTION #
    ############################################################

    # your TMDB api key
    TMDb.api_key= 'XXX123ABC456XYZ789'

    # your .m3u url from provider. If using a file use the location
    # where it is stored and change pl = playlist.loadu(M3Uurl) >> pl = playlist.loadf(filename)
    M3Uurl = "https://ccc.com/iptv/1234567/3Ui458Bn/XXX"

    # location of .m3u file output on completion
    file = '/mnt/Google/MyVOD.m3u'

    ############################################################
      ##########     ##########     ##########     ##########
    ############################################################


    # open file and write #NEXTM3U on the first line and close it
    file2 = open(file, "w+")
    file2.write("#EXTM3U" + '\n')
    file2.close

    # load playlist and leverage m3u-ipytv, sort if Movie or TV VOD
    pl = playlist.loadu(M3Uurl)
    channel = IPTVChannel(pl)
    for channel in pl:
        type = channel.attributes
        Mov = "{'group-title': 'Movie VOD'}"
        Tv = "{'group-title': 'TV VOD'}"
       
       # if Movie filter title
        if str(Mov) == str(type):            
                title0 = channel.name
                t1 = re.compile('(\s*)HD : (\s*)')
                title1 = t1.sub(' ', title0)
                t2 = re.compile('(\s*)2022(\s*)')
                title2 = t2.sub(' ', title1)

                # for each movie title search for TMDB poster and rebuild .m3u and append
                url = channel.url
                search = movieobj.search(title2)
                for index, res in enumerate(search):
                    if not index:
                        if res is not None:
                            Poster =  "https://image.tmdb.org/t/p/w500" + str(res.poster_path)
                            reject = "https://image.tmdb.org/t/p/w500None"

                            # if poster found
                            if Poster != reject:                                
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str("tvg-logo=" + '"' + Poster + '",' + " group-title=" + '"' + "Movie VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:Movie VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
                            # poster not found
                            else:
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str(" group-title=" + '"' + "Movie VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:Movie VOD" '\n')
                                file3.write(url + '\n')
                                file3.close                            


        # if TV filter title
        elif str(Tv) == str(type):        
                
                title0 = channel.name
                t1 = re.compile('(\s*)HD : | AU | NZ(\s*)')
                title1 = t1.sub(' ', title0)
                t2 = re.compile('(\s*)[S]+[0-9]+[0-9](\s*)')
                title2 = t2.sub(' ', title1)
                t3 = re.compile('(\s*)[E]+[0-9]+[0-9](\s*)')
                title3 = t3.sub(' ', title2)
                t4 = re.compile('(\s*)720p WEB h264(\s*)', re.IGNORECASE)
                title4 = t4.sub(' ', title3)
                t5 = re.compile('(\s*)KOGi(\s*)', re.IGNORECASE)
                title5 = t5.sub(' ', title4)
                t6 = re.compile('(\s*)GLHF(\s*)', re.IGNORECASE)
                title6 = t6.sub(' ', title5)
                t7 = re.compile('(\s*)720p WEB H264-JEBAITED(\s*)', re.IGNORECASE)
                title7 = t7.sub(' ', title6)
                t8 = re.compile('(\s*)[0-9]+[0-9](\s*)', re.IGNORECASE)
                title8 = t8.sub(' ', title7)
                t9 = re.compile('(\s*)-JEBAITED(\s*)', re.IGNORECASE)
                title9 = t9.sub(' ', title8)
                
                # for each tv title search TMDB for poster and rebuild .m3u and append
                url = channel.url
                search = tvobj.search(title9)
                for index, res in enumerate(search):
                    if not index:                        
                        if res is not None:                            
                            Poster =  "https://image.tmdb.org/t/p/w500" + str(res.poster_path)
                            reject = "https://image.tmdb.org/t/p/w500None"
                            # if poster found
                            if Poster != reject:
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str("tvg-logo=" + '"' + Poster + '",' " group-title=" + '"' + "TV VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:TV VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
                            # poster not found
                            else:            
                                file3 = open(file, "a+")
                                file3.write("#EXTINF:0 " + str(" group-title=" + '"' + "TV VOD" + '", ' + channel.name) + '\n')
                                file3.write("#EXTGRP:TV VOD" '\n')
                                file3.write(url + '\n')
                                file3.close
   


        

        
Total 0 Votes
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?