youtube-rss

This commit is contained in:
Bram Kelchtermans
2024-06-06 20:10:43 +02:00
parent f3ec017fa3
commit 89d818fe34
4 changed files with 115 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
# Use an official Python runtime as a parent image
FROM python:3.8-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 5000 available to the world outside this container
EXPOSE 5000
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
+24
View File
@@ -0,0 +1,24 @@
# Docker Hub Repository Overview
**Repository Name:**
[Your Docker Hub Repository Name]
**Description:**
This Docker image provides a Flask application that acts as a proxy to convert YouTube channel RSS feeds to a more accessible format. It uses a simple Flask API to expose an endpoint that takes a YouTube channel name as a parameter and returns the channel's RSS feed.
**Usage:**
- **Pull the Docker Image:**
```bash
docker pull [username/repository-name:tag]
```
- **Run the Docker Container:**
```bash
docker run -p 5000:5000 -e youtube-proxy=[your_proxy_url] bramkel/youtuberss/latest
```
- Replace [your_proxy_url] with the URL of your preferred YouTube proxy (default is 'https://www.youtube.com').
- The application will be accessible at http://localhost:5000/[channelName].
- **API Endpoint:**
- /[channelName]: Returns the converted RSS feed for the specified YouTube channel.
+66
View File
@@ -0,0 +1,66 @@
from flask import Flask, redirect, url_for, request, Response
import requests
from bs4 import BeautifulSoup
import os
from urllib.parse import urlparse
import xmltodict
import json
import dicttoxml
app = Flask(__name__)
def get_youtube_rss_url(channel_url):
# Send a GET request to the YouTube channel page
response = requests.get(channel_url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the HTML content of the page
soup = BeautifulSoup(response.text, 'html.parser')
# Find the RSS feed URL in the HTML source
rss_link = soup.find('link', {'type': 'application/rss+xml'})
if rss_link:
return rss_link.get('href')
else:
print("RSS feed not found on the page.")
return None
else:
print(f"Failed to retrieve the page. Status code: {response.status_code}")
return None
def prepend_title(xml):
xml_dict = xmltodict.parse(xml)
channel_title = xml_dict["feed"]["title"]
for entry in xml_dict["feed"]["entry"]:
entry["title"] = channel_title + ' - ' + entry["title"]
xml_data = xmltodict.unparse(xml_dict, pretty=True)
return xml_data
def read_rss(rss_url):
resp = requests.get(rss_url)
if resp.status_code == 200:
proxy_url = os.getenv('youtube-proxy', 'https://www.youtube.com')
parsed_url = urlparse(proxy_url)
scheme = parsed_url.scheme
netloc = parsed_url.netloc
replace_url = scheme + "://" + netloc + "/watch?"
rss_xml = prepend_title(resp.text)
return rss_xml.replace("https://www.youtube.com/watch?", replace_url)
else:
return None
@app.route('/<channelName>')
def doMagic(channelName):
link = 'https://www.youtube.com/@' + channelName
rss_url = get_youtube_rss_url(link)
rss_xml = read_rss(rss_url)
return Response(rss_xml, content_type='application/xml')
if __name__ == '__main__':
app.run(debug = True)
+5
View File
@@ -0,0 +1,5 @@
flask
requests
beautifulsoup4
xmltodict
dicttoxml