Giter Site home page Giter Site logo

tom-mumby / video-library-application Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.21 MB

A video library application which provides a graphical interface to select and play video files. It scans video folders creating thumbnails to display. A key features is a ‘Watch Next List’ which displays partially watched videos and any subsequent videos to watch in a series.

License: GNU General Public License v3.0

Python 100.00%
media-center-application media-player python video video-library video-player video-organizer watch-list next-up play-videos-on-tv

video-library-application's Introduction

Video-Selector-Player

A python application which uses the tkinter binding to enable selecting and playing saved Films and TV Shows. It provides an attractive environment to select videos to watch as well as displaying any partially watched or the next up in any series. The application was primarily designed to be displayed on a television and controlled using its remote, more information on this can be found in this section.

Demo-1.mp4

The project is structured as follows. "Project structure"

Prerequisites

Before the application runs, FFmpeg and VLC must be installed. These are used to create the video thumbnails and play the videos respectively. On Debian-based Linux distributions (e.g. Ubuntu and Raspberry Pi OS) these can installed with:

sudo apt install ffmpeg
sudo apt install vlc

In addition, some python packages are needed:

natsort, Pillow, ffmpeg-python, and python-vlc

These can be installed using PIP, with the command pip install followed by the package name.

Mounting network drives

If you are using a network drive they can be mounted on Debian-based systems using:

sudo mount -r -t cifs -o username=USERNAME,password=PASSWORD NETWORK_LOCATION .

This will mount the network drive in the current location. To avoid needing to do this each time the system boots you can add in /etc/fstab, the line:

NETWORK_LOCATION LOCAL_FOLDER cifs vers=1.0,user=USERNAME,password=PASSWORD,x-systemd.automount 0 0

Quickstart

A brief guide explaining how to set up and use the application.

Setup

Before running for the first time put top-level folders which contain videos in the file base_directories.txt, with each folder on a new line. These folders will become the video categories. Then run main.py, the application will guide you through the setup and launch the GUI.

Usage

Navigate using the arrow keys: press enter to select a folder or to play a video and backspace to go back one folder or to stop play. When playing a video; enter can be pressed to play or pause. The next-up videos will be added to a feature on the home screen. If you need more help or want to explore the features have a look at the full guide.

Features and usage guide

Here is a more comprehensive explanation of the application’s features is presented.

Preparation

This is a guide to preparing video folder structures and telling the application where to find them.

Folder Structure

The application is designed to simulate folder structures however they are organised, with top level directories becoming categories on the home screen. However, there are constraints on this, which are:

  • No folders containing a mixture of video files and folders; video files organised like this will not be recognised by the application.

  • No empty folders; the application will exit if it finds any.

An example a of compatible structure is given below. The folders "Nature Clips" and "Public Domain" serve as the categories.

"Example folder structure"

Setting Folder Locations

The top-level folders, which will become the video categories, are added as lines to a file database_directories.txt. After this is done, you can run main.py to scan for video files. Alternatively, when running for the first time the application can guide you through adding these folders.

Scanning

Before the GUI runs for the first time, the application will: scan the specified folders for video files, make thumbnail images of these files, and save them to the folder thumbnails/fixed_position. It will also scan the directory structure into an object and when it is complete save it to the file folder_structure.pickle.

"Scanning folder structure"

Video selection

In this section selecting video files is discussed. What follows will hopefully be intuitive for the user and the application should be able to be used without a careful consultation of it.

Home Screen

When scanning has completed the home screen appears, with the folders specified in the base_directories.txt file listed as categories in boxes across the screen. These can be selected using the arrow keys and there is a scroll feature with arrows displayed alongside. These indicate how many categories there are left to scroll through by fading to the background colour as the user approaches the last scroll position. All the selection transitions in the home screen and subsequent screens are faded in for visual appeal. In order to select a category press "Enter". The user can return to the home screen at any time by pressing the "h" key.

"Home Screen"

Selection Screen

After selecting a category a new screen will appear showing its contents. These can be browsed with the arrow keys, and you can scroll down if there are more folders than fit on the screen. The amount remaining to scroll is indicated by arrows along the top and bottom of the screen. In order to select a folder press "Enter" and go back at any point by pressing the "Backspace" key.

"Selection"

Once a folder containing video files is reached, these will also be displayed on screen. The application will attempt to clean each video file name by removing special characters and any parts which are repeated across all the videos. It will also add an episode number to the start of the name.

When entering a folder with only one file it will immediately play the video within, e.g. in the case of a Film inside a folder.

Folder Jumping

It is possible to jump to a folder which matches the nearest letter in the alphabet. To do this numbers can be pressed to cycle through the letters associated with them, as they appear on a phone keypad. For example, if the number "4" is pressed letters "GHI" will be cycled through.

Video player

Once you have browsed the folder structure you can select a video file by pressing "Enter". This will then launch the player which has several features.

Action Keypress
Play / Pause Enter
Stop Backspace
Cycle through subtitles - if available "m"
Fast-forward / Rewind - each press will double the speed of playing or rewinding. Left / Right arrow keys - The speed can be reduced by pressing the opposing key
Skip forwards or backwards by 12 seconds Up / Down arrows keys respectively
Jump to a point in the video Numbers (0-9) - for example pressing the number 2 will jump to 20% of the way through the video

When the video is paused or the user is fast-forwarding a marquee is placed over the video indicating the current position and playing state.

"Marquee"

Thumbnails

Video thumbnails are displayed in the home and selection screens. If the thumbnail cannot be displayed, as in the case as there was an error when it was being created, text will be displayed instead.

Thumbnail Default choice of thumbnail Exception
Video Frame which is 30% of the way through the video Video has been part watched - a new thumbnail is displayed showing the position the video was stopped and is added to the folder thumbnails/part_watched.
Folder First video in the series Folder contains a video which is in the watch list - this video is displayed instead

Progress

At a selection screen, when a video file has been partially or fully watched, a progress bar will be displayed along the bottom. This bar will also be shown on folders, here representing the fraction of the videos contained within them which have been watched. Once all the videos in a series have been fully watched the progress on each of them and the progress on the folders containing them is reset.

Watch list

The application maintains a watch next list which is added to when videos that are part of a set have been played i.e. a TV series or film franchise. The videos in this list are displayed on the home screen underneath the video categories. The videos to watch next must be those that have not been fully watched and are chosen based on the position the user has stopped watching the current video at.

Stop position Watched list action
<5% Look from the start of the series to find video to add
>95% Look from the current location in the series to find video to add
Middle Add this video to watch list

An example is shown below.

"Watched List"

Menu

There is a menu that be accessed from the home and selection screens by pressing "m" and removed by pressing "m" or "Backspace". The menu can be browsed by pressing the "Up" and "Down" arrow keys. The options are listed below and are selected by pressing "Enter".

  • Update all - This is used to update the file structure saved in the application if the video library on the system has been changed. When at the home screen all folders in the library will be scanned, whereas, at a selection screen only the folders displayed in the screen will be scanned. Any new thumbnails needed will be created and any old ones deleted.

  • Update top folders only - Does the same as update all, but it only looks if the top folders in a selection screen have changed. This is useful if you have added a new folder to the video library, i.e. a new TV show, but don't want to scan all the videos in the TV folder. If new folders are found during this scan they are added to the watch list for easy access from the home page.

  • Wipe progress - Resets saved progress on the video files contained under the current folder and removes them from the watch next list.

  • Exit - Exits the application.

When the menu is running an update, a progress bar is displayed along the bottom showing what fraction of the folders have been scanned.

"Menu"

Customisation

There are a certain aspects of the application which are easily customisable should the user desire. The screen size is currently set to a standard HD (1920x1080), however, this can be altered to fit different size screens in fixed_sizes.py. The colour scheme can be changed by altering the HEX colour values in colours.py.

Using with TV remote control

The application was designed with connecting the output to a television in mind. Using a keyboard to control this can be cumbersome, so helpfully it is also possible to control the application with a TV remote control, if the TV used supports HDMI-CEC. A tutorial on this can be found here and there is more information to help in this Q&A.

Development

In this section some of the application's classes are explained. This does not need to be understood to run the application and is included only for interest.

The key development goal, aside from implementing the main features of the application, was to ensure the new screens load almost immediately. The aforementioned creation and caching of video thumbnails is one way to achieve this; some more design features which help the application run quickly are explained below.

Folder Simulation

To avoid the application getting bogged down, repeated access to video folders on the system needed to be avoided. The solution to this was for an object within the application to simulate the directory structure. A guide to this object is given here, with some parts omitted for simplicity, full details can be found in the directory_simulation package. A UML diagram for the folder simulation is shown below, more UML diagrams for different classes can be found here.

classDiagram
  direction LR
  class Navigation {
    current_folder: Folder
    list_location: list
    go_to_folder(name : str)
    go_back()
    do_in_elements(function, include_files : bool, include_folders : bool)
  }
  class Folder{
    children : list
    get_child(name : str) Folder
    new_file(name : str, display_name : str) File
    new_folder(name : str) Folder
  }
  class File{
    display_name: str
  }
  class Element{
    name : str
    progress : float
    parent : Folder
    get_parent() Folder
    is_folder() bool
  }
  Navigation "1" *-- "*" Folder
  Navigation "1" *-- "*" File
  Folder  --|>  Element
  File   --|>  Element

The navigation class contains the file and folder classes which when instantiated are arranged to replicate the system folders being simulated. The methods included enable movement throughout the simulated folder structure. Another useful method shown uses recursion to run a function inside all files or folders. This allows for easy manipulation of the folder simulation, for example when the watched progress on all video files and folders needs resetting.

Serialising the folder simulation

So that the video files on the system do not need to be rescanned each time the application is started, the folder simulation within the application is saved to file which can be loaded into the application. The pickle module was found to run much more quickly than saving a json file and was used for this reason.

Selection-screen loading

The way that selection screens are stored is designed to reduce the number need to be loaded. This works by adding the selection screens to a list, so previous screens can be retrieved quickly when the user presses "Back". The current selection screen is deleted when this happens.

Acknowledgments

I would like to thank, the Ubuntu MATE Community user GizmoXomziG, for their guide on how to set up HDMI-CEC control and the user who answered this Q&A.

Also, Dusty Phillips, whose book Python 3 Object-Oriented Programming I found very helpful.

Finally, for the non-copyrighted videos in the demo I would like the thank the Pexels Users: Rodolfo Angulo A., Yogendra Singh, Morteza Khaleghi, and Zura Narimanishvili. In addation to the user PUBLICMOVIES for the Public Domain Movies hosted on archive.org.

Licence

GNU General Public License v3.0

See LICENSE to for the full text.

video-library-application's People

Contributors

tom-mumby avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.