From ba88c53857d8a5c0ee0bec3759101530364b4fae Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 3 Dec 2020 16:32:31 +1300 Subject: [PATCH] Fix search; use youtube-dlc --- extractors/search.py | 4 ++-- extractors/video.py | 6 +++--- index.py | 2 +- requirements.txt | 2 +- tools/extractors.py | 4 +++- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/extractors/search.py b/extractors/search.py index 9c3fef2..d2ffc0a 100644 --- a/extractors/search.py +++ b/extractors/search.py @@ -1,6 +1,6 @@ import requests import traceback -import youtube_dl +import youtube_dlc from tools.converters import * from tools.extractors import extract_yt_initial_data from cachetools import TTLCache @@ -13,7 +13,7 @@ ytdl_opts = { "playlist_items": "1-100", "extract_flat": "in_playlist" } -ytdl = youtube_dl.YoutubeDL(ytdl_opts) +ytdl = youtube_dlc.YoutubeDL(ytdl_opts) def extract_search(q): try: diff --git a/extractors/video.py b/extractors/video.py index bb5dac3..008b548 100644 --- a/extractors/video.py +++ b/extractors/video.py @@ -4,7 +4,7 @@ import json import os import re import traceback -import youtube_dl +import youtube_dlc import urllib.error from tools.converters import * from tools.extractors import extract_yt_initial_data @@ -21,7 +21,7 @@ ytdl_opts = { "write_pages": True, "source_address": "0.0.0.0" } -ytdl = youtube_dl.YoutubeDL(ytdl_opts) +ytdl = youtube_dlc.YoutubeDL(ytdl_opts) def get_created_files(id): if id[0] == "-": @@ -171,7 +171,7 @@ def extract_video(id): return result - except youtube_dl.DownloadError as e: + except youtube_dlc.DownloadError as e: if isinstance(e.exc_info[1], urllib.error.HTTPError): if e.exc_info[1].code == 429: result = { diff --git a/index.py b/index.py index e2e7ac2..620068c 100644 --- a/index.py +++ b/index.py @@ -1,7 +1,7 @@ import configuration import cherrypy import json -import youtube_dl +import youtube_dlc import datetime import dateutil.parser import os diff --git a/requirements.txt b/requirements.txt index 4657b25..1454d70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ cherrypy -youtube-dl +youtube-dlc cachetools python-dateutil requests diff --git a/tools/extractors.py b/tools/extractors.py index b62cfba..7236850 100644 --- a/tools/extractors.py +++ b/tools/extractors.py @@ -1,11 +1,13 @@ import re import json -r_yt_initial_data = re.compile(r"""^(?:\s*window\["ytInitialData"\]|var ytInitialData) = (\{.*\});\s*\n?$""", re.M) +r_yt_initial_data = re.compile(r"""(?:\s*window\["ytInitialData"\]|var ytInitialData) = (\{.+\});""") def extract_yt_initial_data(content): + content = content.replace("\n", "") m_yt_initial_data = re.search(r_yt_initial_data, content) if m_yt_initial_data: + print(m_yt_initial_data.group(1)) yt_initial_data = json.loads(m_yt_initial_data.group(1)) return yt_initial_data else: