Akshat-Jain / django-fetch-youtube

Django project to fetch YouTube videos and display them in reverse chronological order in paginated form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Fetch YouTube

Python Version Django Version

Table of Contents

Project Goal

To make an API to fetch latest videos sorted in reverse chronological order of their publishing date-time from YouTube for a given tag/search query in a paginated response.

Running the Project Locally

  1. First, clone the repository to your local machine:
git clone https://github.com/Akshat-Jain/django-assignment.git
  1. Change the current directory to the project directory and install the requirements:
cd django-assignment
pip install -r requirements.txt
  1. Setup migrations and database:
python manage.py makemigrations youtube
python manage.py migrate
  1. Create an admin user:
python manage.py createsuperuser

Follow the prompts on the terminal to create an admin user.

  1. We're almost there! There's just one more thing we need to do! We need to create a keys.json file in the root directory of the project where we will store our YouTube Data API Key which will be required to fetch the videos using that API.
touch keys.json

Now open this file with any text editor. The structure of keys.json is required to be as follows:

{
	"YOUTUBE_DATA_API_KEYS": {
		"key1": "Enter your API Key 1 here",
		"key2": "Enter your API Key 2 here",
		"key3": "Enter your API Key 3 here",
		"key4": "Enter your API Key 4 here",
	}
}

You can get an API key by following this link. Make sure that you have atleast one API Key in this file with valid amount of quota left.

  1. Finally, run the development server:
python manage.py runserver

The project will be available at 127.0.0.1:8000.

Different Endpoints

There are 3 endpoints in the project:

  1. /admin: This allows user to login with the admin credentials and manage the project. The user can view the tables of the database and can also edit them directly in the provided interface.
  2. /youtube/startFetching: This endpoint triggers a background asynchronorous job to fetch information of videos. This endpoint also supports an optional query parameter to take the search query:
http://localhost:8000/youtube/startFetching?searchQuery=Cricket
http://localhost:8000/youtube/startFetching?searchQuery=Westeros

The searchQuery is optional and defaults to Game of Thrones if not provided.

  1. /youtube: This endpoint returns the stored video data in a paginated response sorted in descending order of published datetime. This endpoint also supports a query parameter to facilitate pagination as following:
http://localhost:8000/youtube/?page=1
http://localhost:8000/youtube/?page=2
.
.
http://localhost:8000/youtube/?page=pageNumber

You can find the demonstration of each of these in the Demonstration section.

Key Features

  1. Information about YouTube videos is being fetched asynchronously as a background task on regular intervals (10 seconds as per the current implementation).
  2. Pagination support with latest published videos shown first.
  3. Stores Video ID, Title, Description, Publishing Datetime and Thumbnails URLs in the database with indexing done on Publishing Datetime column in reverse chronological ordering for faster access.
  4. Support for supplying multiple API keys so that if quota is exhausted on one, it automatically uses the next available key.
  5. Renders the response in a custom implemented template.

Video Demonstration

References

  1. YouTube Data v3 API
  2. Search API reference
  3. Django Official Documentation

License

The source code is released under the MIT License.

About

Django project to fetch YouTube videos and display them in reverse chronological order in paginated form.

License:MIT License


Languages

Language:Python 91.6%Language:HTML 8.4%