|
|
@ -2,54 +2,44 @@ import threading
|
|
|
|
|
|
|
|
|
|
|
|
import feedparser
|
|
|
|
import feedparser
|
|
|
|
import wx
|
|
|
|
import wx
|
|
|
|
from youtube_dl import YoutubeDL as yt
|
|
|
|
import time
|
|
|
|
from youtube_dl.utils import DownloadError, ExtractorError
|
|
|
|
import youtube_dl
|
|
|
|
|
|
|
|
|
|
|
|
from Channel import Channel
|
|
|
|
from Channel import Channel
|
|
|
|
from Items import Item
|
|
|
|
from Items import Item
|
|
|
|
from Utils import (add_video, get_default_logo, hash_string,
|
|
|
|
from Utils import (add_video, get_default_logo, get_latest_video_timestamp, hash_string,
|
|
|
|
make_bitmap_from_url, video_exists)
|
|
|
|
make_bitmap_from_url, video_exists)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class YouTube(Channel):
|
|
|
|
class YouTube(Channel):
|
|
|
|
def __init__(self, channel_id: str, name: str) -> None:
|
|
|
|
def __init__(self, channel_id: str, name: str) -> None:
|
|
|
|
self.m_channel_id = channel_id
|
|
|
|
|
|
|
|
self.m_name = name
|
|
|
|
self.m_name = name
|
|
|
|
rss_url = 'https://www.youtube.com/feeds/videos.xml?channel_id={}'.format(
|
|
|
|
rss_url = 'https://www.youtube.com/feeds/videos.xml?channel_id={}'.format(
|
|
|
|
channel_id)
|
|
|
|
channel_id)
|
|
|
|
self.m_logo = get_default_logo('YouTube')
|
|
|
|
self.m_logo = get_default_logo('YouTube')
|
|
|
|
|
|
|
|
self.m_items: list[Item] = list()
|
|
|
|
super().__init__(channel_id, 'YouTube', rss_url, self.m_logo, name)
|
|
|
|
super().__init__(channel_id, 'YouTube', rss_url, self.m_logo, name)
|
|
|
|
|
|
|
|
|
|
|
|
self.m_thr = threading.Thread(target=self.parse_feed,
|
|
|
|
|
|
|
|
args=(),
|
|
|
|
|
|
|
|
kwargs={})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh(self) -> None:
|
|
|
|
|
|
|
|
self.m_thr.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wait(self) -> bool:
|
|
|
|
|
|
|
|
return self.m_thr.is_alive()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_feed(self) -> None:
|
|
|
|
def parse_feed(self) -> None:
|
|
|
|
feed = feedparser.parse(self.get_feed())
|
|
|
|
feed = feedparser.parse(self.get_feed())
|
|
|
|
|
|
|
|
|
|
|
|
ydl_opts = {
|
|
|
|
ydl_opts = {
|
|
|
|
'format':
|
|
|
|
'format':
|
|
|
|
'worstvideo[ext=mp4]+worstaudio[ext=m4a]/worstvideo+worstaudio',
|
|
|
|
'worstvideo[ext=mp4]+worstaudio[ext=m4a]/worstvideo+worstaudio',
|
|
|
|
'container': 'webm_dash',
|
|
|
|
'container': 'webm_dash',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entries = feed['entries']
|
|
|
|
entries = feed['entries']
|
|
|
|
self.m_items: list[Item] = list()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for entry in entries:
|
|
|
|
for entry in entries:
|
|
|
|
video_id = hash_string(entry['id'])
|
|
|
|
video_id = hash_string(entry['id'])
|
|
|
|
if video_exists(video_id, self.m_channel_id):
|
|
|
|
if video_exists(video_id, self.m_id):
|
|
|
|
pass
|
|
|
|
continue
|
|
|
|
title = str(entry['title'])
|
|
|
|
title = str(entry['title'])
|
|
|
|
thumbnail_link = str(entry['media_thumbnail'][0]['url'])
|
|
|
|
thumbnail_link = str(entry['media_thumbnail'][0]['url'])
|
|
|
|
description = str(entry['description'])
|
|
|
|
description = str(entry['description'])
|
|
|
|
link = ''
|
|
|
|
link = ''
|
|
|
|
with yt(ydl_opts) as ydl:
|
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
video = ydl.extract_info(entry['link'], download=False)
|
|
|
|
video = ydl.extract_info(entry['link'], download=False)
|
|
|
|
|
|
|
|
|
|
|
@ -58,7 +48,7 @@ class YouTube(Channel):
|
|
|
|
if form['height'] < 480 and form[
|
|
|
|
if form['height'] < 480 and form[
|
|
|
|
'acodec'] != 'none':
|
|
|
|
'acodec'] != 'none':
|
|
|
|
link = form['url']
|
|
|
|
link = form['url']
|
|
|
|
except ExtractorError or DownloadError:
|
|
|
|
except youtube_dl.utils.ExtractorError and youtube_dl.utils.DownloadError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
resolved_link = link
|
|
|
|
resolved_link = link
|
|
|
@ -72,6 +62,6 @@ class YouTube(Channel):
|
|
|
|
item = Item(description, resolved_link, self.m_provider_name,
|
|
|
|
item = Item(description, resolved_link, self.m_provider_name,
|
|
|
|
published_parsed, thumbnail, title)
|
|
|
|
published_parsed, thumbnail, title)
|
|
|
|
self.m_items.append(item)
|
|
|
|
self.m_items.append(item)
|
|
|
|
add_video(video_id, self.m_channel_id, self.m_provider_name,
|
|
|
|
add_video(video_id, self.m_id, self.m_provider_name,
|
|
|
|
description, resolved_link, published_parsed, thumbnail,
|
|
|
|
description, resolved_link, published_parsed, thumbnail,
|
|
|
|
title, 0)
|
|
|
|
title, 0)
|
|
|
|