YouTube API Search and Classification - Python Code Explanation

Goal of the Script

This Python script searches the YouTube Data API for videos related to violence against religious minorities in Bangladesh, classifies retrieved videos using keyword-based categories, and produces CSV and HTML reports for analysis.

Required Modules

The program uses several supporting modules:

Libraries Used

The script uses:

Video Classification Process

The classify() function examines video titles and descriptions using the keyword categories defined in CATEGORY_MAP. When matching terms are found, the script assigns categories, records matched keywords, and calculates a weighted classification score.

If no keywords are matched, the video is assigned to the Other category.

Search and Retrieval Workflow

  1. The user selects the maximum number of YouTube results per query.
  2. The user selects a publication period, such as a specific half-year, calendar year, or all available years.
  3. The script executes searches using the predefined search themes.
  4. For each retrieved video, the program collects title, description, channel, publication date, and URL information.
  5. The video text is classified using the keyword-based classification system.

Date Filtering

The program provides multiple publication-date filters, including:

Output Files

The script creates output files in the configured output folder:

Data Cleaning and Reporting

After retrieval, the program:

Summary

This script provides an automated workflow for collecting and analyzing YouTube videos. It integrates API-based retrieval, keyword classification, weighted scoring, data cleaning, and HTML report generation to support research on violence against religious minorities in Bangladesh.