summaryrefslogtreecommitdiff
path: root/src/shoki
diff options
context:
space:
mode:
Diffstat (limited to 'src/shoki')
-rw-r--r--src/shoki/py/providers/twitter.py3
-rw-r--r--src/shoki/py/providers/youtube.py29
2 files changed, 19 insertions, 13 deletions
diff --git a/src/shoki/py/providers/twitter.py b/src/shoki/py/providers/twitter.py
index 2fc0faf..4770dda 100644
--- a/src/shoki/py/providers/twitter.py
+++ b/src/shoki/py/providers/twitter.py
@@ -2,7 +2,6 @@ import json
import config
import http.cookiejar
from datetime import timezone
-from socketserver import UDPServer
import log
from provider import Provider
@@ -13,7 +12,7 @@ from query_parser import QueryParser
# Official Twitter API
#from twitter import Twitter2, TwitterError, OAuth
-# GraphQL Scrape API
+# GraphQL API
import snscrape.modules.twitter
from snscrape.base import ScraperException
from snscrape.modules.twitter import (TwitterSearchScraper, TwitterProfileScraper,
diff --git a/src/shoki/py/providers/youtube.py b/src/shoki/py/providers/youtube.py
index f17211e..3cbf0c8 100644
--- a/src/shoki/py/providers/youtube.py
+++ b/src/shoki/py/providers/youtube.py
@@ -1,9 +1,9 @@
import log
-import yt_dlp
from provider import Provider
from search import Search
from post import Post, PostType, Image, Video
from query_parser import QueryParser
+from yt_dlp import YoutubeDL
class YDLLogger():
def debug(self, msg):
@@ -28,24 +28,28 @@ ydl_opts = {
# 'cookiefile': '',
}
-ydl = yt_dlp.YoutubeDL(ydl_opts)
+ydl = YoutubeDL(ydl_opts)
def get_playback_url(data, video=True):
if 'entries' in data:
+ if len(data['entries']) == 0:
+ return None
data = data['entries'][0]
- url = data['formats'][0]['url']
+ if 'formats' not in data:
+ if 'url' in data:
+ return data['url']
+ return None
- '''
- data['formats'] = list(filter(lambda f: 'container' not in f, data['formats']))
+ # Filter out hls temporarily.
+ data['formats'] = list(filter(lambda f: not f['protocol'].startswith('m3u8'), data['formats']))
- data['formats'] = list(filter(
- lambda f: not ('container' in f and (f['container'] in ['mp4_dash', 'webm_dash'])), data['formats']
- ))
- '''
+ if len(data['formats']) == 0:
+ return None
- data['formats'] = list(filter(lambda f: 'manifest_url' not in f, data['formats']))
+ url = data['formats'][0]['url']
+ # audio_ext?
has_audio = list(filter(lambda f: 'acodec' not in f or f['acodec'] != 'none', data['formats']))
if video:
@@ -86,7 +90,10 @@ class YoutubeBase(Search):
self.pages[index] = { 'posts': [], 'list': [] }
res = self.get_info()
if res:
- media = [Video(url=get_playback_url(res))]
+ url = get_playback_url(res)
+ if not url:
+ return False
+ media = [Video(url=url)]
self.pages[index]['posts'].append(Post(type=PostType.POST, unique_id='', url='', title='', text='', media=media))
return True