Beispiel #1
0
def list_movies():
    movies = get_sub_folders("static/movies")
    formatted_movies = []
    for movie in movies:
        title = get_file(f"static/movies/{movie}/title.txt")
        f = f'''
            <h3><a style="color: gray;" href="/play/movie/{movie}/">{title}</a></h3>
            '''
        formatted_movies.append(f)
    formatted_movies = " ".join(formatted_movies)
    html = get_file("views/movies.html").format(movies=formatted_movies)
    return html
Beispiel #2
0
def list_shows():
    shows = get_sub_folders("static/shows")
    formatted_shows = []
    for show in shows:
        show_name = get_file(f"static/shows/{show}/title.txt")
        if show_name == "File not found":
            show_name = string.capwords(show)
        f = f'''
            <h3><a style="color: gray;" href="/shows/{show}">{show_name}</a></h3>
            '''
        formatted_shows.append(f)
    formatted_shows = " ".join(formatted_shows)
    html = get_file("views/shows.html").format(shows=formatted_shows)
    return html
Beispiel #3
0
def play_next_episode():
    referrer = request.referrer
    if referrer is None:
        return "You did not go to this page from a previous episode so we cannot find the next episode."
    else:
        path = [
            item for item in urlparse(referrer).path.split("/") if item != ""
        ]
        if len(path) == 5:
            show = path[2]
            season = path[3]
            episode = path[4]
            season_episodes = get_folder_files(f"static/shows/{show}/{season}")
            next_episode_num = int(episode[1:]) + 1
            next_episode = f"e{next_episode_num}"
            if next_episode + ".mp4" in season_episodes:
                return redirect(f"/play/show/{show}/{season}/{next_episode}")
            else:
                seasons = get_sub_folders(f"static/shows/{show}")
                next_season_num = int(season[1:]) + 1
                next_season = f"s{next_season_num}"
                if next_season in seasons:
                    next_season_episodes = get_folder_files(
                        f"static/shows/{show}/{next_season}")
                    next_episode = os.path.splitext(next_season_episodes[0])[0]
                    return redirect(
                        f"/play/show/{show}/{next_season}/{next_episode}")
                else:
                    show_name = get_file(f"static/shows/{show}/title.txt")
                    if show_name == "File not found":
                        show_name = string.capwords(show)
                    return f"<h1 style=\"font-family: arial;\">You have finished watching all episodes for {show_name}. Sorry!</h1>"
        else:
            abort(404)
Beispiel #4
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}
    
    for path in misc.get_file(startpoint):
        
        if path.lower().endswith(misc.PATH_DISQUALIFIERS):
            continue

        with open(path, "r") as fin:
            sys.stderr.write(path + "\n")
            contents = fin.read(20 * 1024)
            hash = hashlib.sha512(contents).hexdigest()
            
            value = "%s : %d" % (path, os.stat(path).st_size)
            
            try:
                file_hashes[hash].append(value)
            except KeyError:
                file_hashes[hash] = []
                file_hashes[hash].append(value)

    for hash in file_hashes:
        if len(file_hashes[hash]) > 1:
            print "found possible duplicates:"
            for f in file_hashes[hash]:
                print "\t%s" % f
Beispiel #5
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}

    for path in misc.get_file(startpoint):

        if path.lower().endswith(misc.PATH_DISQUALIFIERS):
            continue

        with open(path, "r") as fin:
            sys.stderr.write(path + "\n")
            contents = fin.read(20 * 1024)
            hash = hashlib.sha512(contents).hexdigest()

            value = "%s : %d" % (path, os.stat(path).st_size)

            try:
                file_hashes[hash].append(value)
            except KeyError:
                file_hashes[hash] = []
                file_hashes[hash].append(value)

    for hash in file_hashes:
        if len(file_hashes[hash]) > 1:
            print "found possible duplicates:"
            for f in file_hashes[hash]:
                print "\t%s" % f
Beispiel #6
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}
    
    for path in misc.get_file(startpoint):
        with open(path, "r") as path:
            contents = path.read()
            hash = hashlib.sha512(contents).hexdigest()
            
            try:
                file_hashes[hash].append(path)
            except KeyError:
                file_hashes[hash] = []
                file_hashes[hash].append(path)

    for hash in file_hashes:
        if len(file_hashes[hash]) > 1:
            print "found possible duplicates"
            for path in file_hashes[hash]:
                print "\t%s" % path
Beispiel #7
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}

    for path in misc.get_file(startpoint):
        with open(path, "r") as path:
            contents = path.read()
            hash = hashlib.sha512(contents).hexdigest()

            try:
                file_hashes[hash].append(path)
            except KeyError:
                file_hashes[hash] = []
                file_hashes[hash].append(path)

    for hash in file_hashes:
        if len(file_hashes[hash]) > 1:
            print "found possible duplicates"
            for path in file_hashes[hash]:
                print "\t%s" % path
Beispiel #8
0
def list_seasons(show):
    show_name = get_file(f"static/shows/{show}/title.txt")
    if show_name == "File not found":
        show_name = string.capwords(show)
    season_numbers = [
        season[1:] for season in get_sub_folders(f"static/shows/{show}")
    ]
    formatted_seasons = []
    for number in season_numbers:
        f = f'''
            <h3><a style="color: gray;" href="/shows/{show}/s{number}">Season {number}</a></h3>
            '''
        formatted_seasons.append(f)
    formatted_seasons = " ".join(formatted_seasons)
    html = get_file("views/seasons.html").format(show_name=show_name,
                                                 seasons=formatted_seasons)
    return html
Beispiel #9
0
def play_content(content_type, name, season=None, episode=None):
    if content_type == "show":
        show = name
        valid_shows = get_sub_folders("static/shows")
        show_name = get_file(f"static/shows/{show}/title.txt")
        if show_name == "File not found":
            show_name = string.capwords(show)
        season_num = season[1:]
        episode_num = episode[1:].split(".")[0]
        if show in valid_shows:
            valid_seasons = get_sub_folders(f"static/shows/{show}")
            if season in valid_seasons:
                valid_episodes = get_folder_files(
                    f"static/shows/{show}/{season}")
                if episode + ".mp4" in valid_episodes:
                    video_path = f"{show}/{season}/{episode}"
                    season_path = f"{show}/{season}"
                    return get_file("views/video.html").format(
                        show_name=show_name,
                        season_num=season_num,
                        episode_num=episode_num,
                        season_path=season_path,
                        video_path=video_path,
                        show=show)
                else:
                    abort(404)
            else:
                abort(404)
        else:
            abort(404)
    if content_type == "movie":
        movie = name
        valid_movies = get_sub_folders("static/movies")
        if movie in valid_movies:
            movies = get_folder_files(f"static/movies/{movie}")
            for f in movies:
                if f == "movie.mp4":
                    title = get_file(f"static/movies/{movie}/title.txt")
                    return get_file("views/movie.html").format(
                        movie_title=title, movie=movie)
                else:
                    abort(404)
        else:
            abort(404)
    else:
        abort(404)
Beispiel #10
0
def list_episodes(show, season):
    show_name = get_file(f"static/shows/{show}/title.txt")
    if show_name == "File not found":
        show_name = string.capwords(show)
    episode_numbers = sorted([
        int(num) for num in [
            episode[1:].split(".")[0]
            for episode in get_folder_files(f"static/shows/{show}/{season}")
        ] if num.isdigit()
    ])
    formatted_episodes = []
    for number in episode_numbers:
        f = f'''
            <h3><a style="color: gray;" href="/play/show/{show}/{season}/e{number}">Episode {number}</a></h3>
            '''
        formatted_episodes.append(f)
    formatted_episodes = " ".join(formatted_episodes)
    return get_file("views/episodes.html").format(show_name=show_name,
                                                  season=season,
                                                  season_num=season[1:],
                                                  episodes=formatted_episodes,
                                                  show=show)
Beispiel #11
0
    def _selectInput(self):
        """ GUI for the selection of an in-file. """

        (my_file, my_path) = misc.get_file(FilterSpec='*.wav',
                                           DialogTitle='Select sound-input:',
                                           DefaultName='')
        if my_path == 0:
            print('No file selected')
            return 0
        else:
            full_in_file = os.path.join(my_path, my_file)
            print('Selection: ' + full_in_file)
            return full_in_file
Beispiel #12
0
    def _selectInput(self):
        '''GUI for the selection of an in-file. '''

        (my_file, my_path) = misc.get_file(FilterSpec='*.wav',
                                           DialogTitle='Select sound-input:',
                                           DefaultName='')
        full_in_file = os.path.join(my_path, my_file)
        # filetypes=['*.wav', '*.mp3'])

        if full_in_file is None:
            print('No file selected')
            return 0
        else:
            print('Selection: ' + full_in_file)
            return full_in_file
Beispiel #13
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}
    deleted = 0

    for path in misc.get_file(startpoint):

        if path.lower().endswith(misc.PATH_DISQUALIFIERS):
            continue

        with open(path, "r") as f:
            sys.stderr.write(path + "\n")

            contents = f.read()
            hash = hashlib.sha512(contents).hexdigest()

            if hash in file_hashes:
                sys.stderr.write("possible duplicate\n")
                alen = os.stat(file_hashes[hash]).st_size
                blen = os.stat(path).st_size

                # They're the same size.
                if alen == blen:
                    f2 = open(file_hashes[hash])
                    contents2 = f2.read()
                    f2.close()

                    if contents == contents2:
                        print "deleted: %s" % path
                        #os.unlink(path)
                        deleted += blen

            else:
                file_hashes[hash] = path

    print "Deleted: %d bytes" % deleted
Beispiel #14
0
def main():

    if len(sys.argv) != 2:
        usage()
        sys.exit(-1)

    startpoint = sys.argv[1]
    file_hashes = {}
    deleted = 0
    
    for path in misc.get_file(startpoint):
        
        if path.lower().endswith(misc.PATH_DISQUALIFIERS):
            continue
        
        with open(path, "r") as f:
            sys.stderr.write(path + "\n")
            
            contents = f.read()
            hash = hashlib.sha512(contents).hexdigest()
            
            if hash in file_hashes:
                sys.stderr.write("possible duplicate\n")
                alen = os.stat(file_hashes[hash]).st_size
                blen = os.stat(path).st_size
                
                # They're the same size.
                if alen == blen:
                    f2 = open(file_hashes[hash])
                    contents2 = f2.read()
                    f2.close()
                    
                    if contents == contents2:
                        print "deleted: %s" % path
                        #os.unlink(path)
                        deleted += blen
                
            else:
                file_hashes[hash] = path

    print "Deleted: %d bytes" % deleted
Beispiel #15
0
def home():
    return get_file("views/home.html")