#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    VLC Custom TV channel Maker script error


    I recently downloaded a plugin for vlc that makes a tv station for you out of all of your targeted video files and plays them like a tv station would.
    Plugin: http://addons.videolan.org/content/show.php?action=content&content=153209

    but i'm facing a problem with it, this problem is that everytime i run the script "Makechannel.py" i get an error, a syntax error
    Since i've no knowledge of python programming i'm looking for somebody who can help me with this problem.

    Here's the script code

    Code:
    # makechannel.py v0.01 (alpha) # by Jason D. Ozubko, 2012 (jdozubko@gmail.com) ############################################################################# # This file builds a database of media files for use with channelwatch.lua to # simulate an ongoing television/radio station in VLC. # # To use this file, place it in a folder that contains all the video files you # want to access. Then execute this file from the command prompt using python. # The script will then search through that folder and all subfolders for any # valid video files (currently avi, mpeg/mpg, asf/wmv/wma, mp4/mov/3gp, ogg/ogm, # and mkv). # # Both filenames and video length will be extracted for each file and saved to # a file called "new.channel". [Note that to extract video file length, this # script depends on an external function, "ffprobe"]. Playing the new.channel # file in VLC media play (with the watchchannel.lua script installed) will # execute this new channel. You may rename the new.channel file to anything you # like, save it anywhere you like, and edit it to remove or add any files you # like. # # To edit the type of file that this script looks for edit the line below that # starts off as: # # if name.lower().endswith(".avi") or name.lower().endswith(".mpg")... # # Note that if you change this line to be audio files (e.g., mp3, wav, etc.) # then the script will create a new custom radio station channel. # # Happy TV viewing/radio listening!!! # import os import subprocess # open the new.channel file to output things to f = open('new.channel', 'w') # channel is 0 by default f.write("0\r\n") #function... returns the duration HH:MM:SS of a video file def getLength(filename): #uses ffprobe to get info about the video file result = subprocess.Popen(["ffprobe", filename], stdout = subprocess.PIPE, stderr = subprocess.STDOUT) #finds the info that has the word "Duration" y = [x for x in result.stdout.readlines() if "Duration: " in x] #get the location of the "Duration: " phrase loc = y[0].find("Duration: ") #assuming we find the location of that phrase.. if loc <> -1: #cut out everything before and everything more than 10 characters later return y[0][loc+10:loc+18] else: #if we don't find anything then set it to be 2 seconds of nothing... return '00:00:02' #main code... walk through the subfolders looking for movie files for dirpath, dirnames, files in os.walk('.'): for name in files: ############################################################################# # EDIT THE LINE BELOW TO CHANGE THE TYPE OF MEDIA FILES YOU WANT TO FIND ############################################################################# if name.lower().endswith(".avi") or name.lower().endswith(".mpg") or name.lower().endswith(".mpeg") or name.lower().endswith(".asf") or name.lower().endswith(".wmv") or name.lower().endswith(".wma") or name.lower().endswith(".mp4") or name.lower().endswith(".mov") or name.lower().endswith(".3gp") or name.lower().endswith(".ogg") or name.lower().endswith(".ogm") or name.lower().endswith(".mkv"): fn = os.path.join(dirpath, name) try: #figure out the full name, output it, then save it fn_full = os.environ["PWD"] + fn[1:] print fn_full f.write("%s\r\n" % fn_full) #figure out the length, output it, then save it fn_len = getLength(fn_full) print fn_len f.write("%s\r\n" % fn_len) except: pass # ignore errors #close the file f.close()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    You must use the program with python version 2.7.3

    It will not work with python version 3.

    www.python.org
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Thanks, it works to run the script now but the file that is supposed to be created that targets the video files(new.channel)
    is not working, when i open the file in notepad the only thing written in it is the number 0, any thoughts on how to fix this?
    i think it might somehow involve the ffprobe thing but not sure
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    I ran the program in a directory with a few recognized files with and without the ffprobe program. The first line of the new.channel file is
    0
    And other files follow. With ffprobe I also get the length measured as time.

    It works on my linux distribution.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    This is very strange :/ i just won't get it to work the .channel file has nothing else written in it other than the number 0, i run the makechannel.py script in a folder with .avi files, and other formats of video files
    and now when i try to run it with "IDLE" i get an error saying
    "Error: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), or 2) Your indentation mixes tabs and spaces."
    in line 56, "return y[0][loc+10:loc+18]"
    BTW using windows
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    White space, particularly leading white space on a line, is part of the python language syntax. The program unadvisedly mixed tabs and spaces. I replaced tabs with spaces. Try this which should work in python 2 or 3:
    Code:
    # makechannel.py v0.01 (alpha) 
    # by Jason D. Ozubko, 2012 (jdozubko@gmail.com)
    #############################################################################
    # This file builds a database of media files for use with channelwatch.lua to
    # simulate an ongoing television/radio station in VLC.
    #
    # To use this file, place it in a folder that contains all the video files you
    # want to access.  Then execute this file from the command prompt using python.
    # The script will then search through that folder and all subfolders for any
    # valid video files (currently avi, mpeg/mpg, asf/wmv/wma, mp4/mov/3gp, ogg/ogm, 
    # and mkv).
    #
    # Both filenames and video length will be extracted for each file and saved to
    # a file called "new.channel".  [Note that to extract video file length, this
    # script depends on an external function, "ffprobe"].  Playing the new.channel
    # file in VLC media play (with the watchchannel.lua script installed) will
    # execute this new channel.  You may rename the new.channel file to anything you
    # like, save it anywhere you like, and edit it to remove or add any files you
    # like.
    #
    # To edit the type of file that this script looks for edit the line below that
    # starts off as:
    #
    # if name.lower().endswith(".avi") or name.lower().endswith(".mpg")...
    #
    # Note that if you change this line to be audio files (e.g., mp3, wav, etc.)
    # then the script will create a new custom radio station channel.
    #
    # Happy TV viewing/radio listening!!!
    #
    
    import os
    import subprocess
    
    # open the new.channel file to output things to
    f = open('new.channel', 'w')
    
    # channel is 0 by default
    f.write("0\r\n")
    
    #function... returns the duration HH:MM:SS of a video file
    def getLength(filename):
        #uses ffprobe to get info about the video file
        result = subprocess.Popen(["ffprobe", filename],
                                 stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
    
        #finds the info that has the word "Duration"
        y = [x for x in result.stdout.readlines() if "Duration: " in x]
    
        #get the location of the "Duration: " phrase
        loc = y[0].find("Duration: ")
    
        #assuming we find the location of that phrase..
        if loc != -1:
            #cut out everything before and everything more than 10 characters later
            return y[0][loc+10:loc+18]
        else:
            #if we don't find anything then set it to be 2 seconds of nothing...
            return '00:00:02'
    
    
    #main code... walk through the subfolders looking for movie files
    for dirpath, dirnames, files in os.walk('.'):
        for name in files:
    #############################################################################
    # EDIT THE LINE BELOW TO CHANGE THE TYPE OF MEDIA FILES YOU WANT TO FIND
    #############################################################################
            if name.lower().endswith(".avi") or name.lower().endswith(".mpg") or name.lower().endswith(".mpeg") or name.lower().endswith(".asf") or name.lower().endswith(".wmv") or name.lower().endswith(".wma") or name.lower().endswith(".mp4") or name.lower().endswith(".mov") or name.lower().endswith(".3gp") or name.lower().endswith(".ogg") or name.lower().endswith(".ogm") or name.lower().endswith(".mkv"):
                fn = os.path.join(dirpath, name)
                try:
                    #figure out the full name, output it, then save it
                    fn_full = os.environ["PWD"] + fn[1:]
                    print(fn_full)
                    f.write("%s\r\n" % fn_full)
    
                    #figure out the length, output it, then save it
                    fn_len  = getLength(fn_full)
                    print(fn_len)
                    f.write("%s\r\n" % fn_len)
                except:
                    pass # ignore errors
    
    #close the file
    f.close()
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    i can run the script now but still won't get more than the number 0 in the .channel file :/ I don't believe i'm doing anything wrong, though i might but very unlikely
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    This might be an improved version of the code. Jason probably didn't test the program on Windows. I tested parts of it and discovered that the program would likely fail as you described on windows.
    Code:
    # Warning: does not work with python3.
    
    # makechannel.py v0.01 (alpha)
    # by Jason D. Ozubko, 2012 (jdozubko@gmail.com)
    # modified by Lambert Electronics, USA, NY.
    #############################################################################
    # This file builds a database of media files for use with channelwatch.lua to
    # simulate an ongoing television/radio station in VLC.
    #
    # To use this file, place it in a folder that contains all the video files you
    # want to access.  Then execute this file from the command prompt using python.
    # The script will then search through that folder and all subfolders for any
    # valid video files (currently avi, mpeg/mpg, asf/wmv/wma, mp4/mov/3gp, ogg/ogm,
    # and mkv).
    #
    # Both filenames and video length will be extracted for each file and saved to
    # a file called "new.channel".  [Note that to extract video file length, this
    # script depends on an external function, "ffprobe"].  Playing the new.channel
    # file in VLC media play (with the watchchannel.lua script installed) will
    # execute this new channel.  You may rename the new.channel file to anything you
    # like, save it anywhere you like, and edit it to remove or add any files you
    # like.
    #
    # To edit the type of file that this script looks for edit the line below that
    # starts off as:
    #
    # if name.lower().endswith(".avi") or name.lower().endswith(".mpg")...
    #
    # Note that if you change this line to be audio files (e.g., mp3, wav, etc.)
    # then the script will create a new custom radio station channel.
    #
    # Happy TV viewing/radio listening!!!
    #
    
    import os
    import subprocess
    
    # open the new.channel file to output things to
    f = open('new.channel', 'w')
    
    # channel is 0 by default
    f.write("0\r\n")
    
    #function... returns the duration HH:MM:SS of a video file
    def getLength(filename):
        #uses ffprobe to get info about the video file
        result = subprocess.Popen(["ffprobe", filename],
                                  stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
    
        #finds the info that has the word "Duration"
        for LINE in result.stdout:
            #in python 3 the type of LINE is bytes which we'd need to decode
            if 'Duration: ' in LINE:
                FIELDS = LINE.split()
                TIME = FIELDS[1]
                if '.' in TIME:
                    return TIME.split('.')[0]
                return TIME[:-1]
    
        return '00:00:02'
    
    
    #main code... walk through the subfolders looking for movie files
    
    CWD = os.getcwd()
    
    for (dirpath, dirnames, files,) in os.walk('.'):
        for name in files:
            fileExtension = name.split('.')[-1].lower()
    #############################################################################
    # EDIT THE LINE BELOW TO CHANGE THE TYPE OF MEDIA FILES YOU WANT TO FIND
    #############################################################################
            if fileExtension in set('avi mpg mpeg asf wmv wma mp4 mov 3gp ogg ogm mkv'.split()):
                fn_full = os.path.join(CWD, dirpath, name)
                print(fn_full)
                f.write("%s\r\n" % fn_full)
                try:
                    #figure out the length, output it, then save it
                    fn_len  = getLength(fn_full)
                except:
                    pass # ignore errors
                else:
                    print(fn_len)
                    f.write("%s\r\n" % fn_len)
    
    #close the file
    f.close()

    For those who care about the python or operating system aspects, there was too much code in the try: block. When the CWD environment variable doesn't exist (it didn't exist on the NT platform I checked) the program jumps around writing the file name to the new.channel file.
    fn_full = os.environ["PWD"] + fn[1:]
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Worked like a charm this time, thanks but now the .lua script is most likely being a problem. when i move the new.channel file to vlc nothing happens, i just get an error saying "Your input can't be opened:
    VLC is unable to open the MRL:C:\Users\Olafur\episodes\.\Through the Wormhole\Season 1\through.the.wormhole.s01e07.what.are.we.really.made.of.hdtv.xvid-momentum.avi'. Check the log for details.".
    When i check in vlc menu, Tools/plugins and extensions i can't find the plugin anywhere in the extension tab or the plugins tab, would have thought that it should have been there. This Jason guy most likely hasn't tested the plugin on windows like you said above.
  18. #10
  19. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,855
    Rep Power
    481
    I haven't used lua.

    Is MRL:C:\Users\ somehow valid?
    Do the file names in new.channel look valid to you?
    [code]Code tags[/code] are essential for python code and Makefiles!
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I haven't used lua.

    Is MRL:C:\Users\ somehow valid?
    Do the file names in new.channel look valid to you?
    VLC is unable to open the MRL 'C:\Users\Olafur\ the error says not mrl:c:\...
    Yes the location paths are correct in the .channel file, nothing wrong there
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Exclamation Um, help?


    Originally Posted by stufur
    VLC is unable to open the MRL 'C:\Users\Olafur\ the error says not mrl:c:\...
    Yes the location paths are correct in the .channel file, nothing wrong there
    I am sorry for the necro, but I was wondering, has anyone figured out a way to fix this? I am using the modified python script and have ffmpeg for windows so i have ffprobe, but i get the same error. Help?

IMN logo majestic logo threadwatch logo seochat tools logo