mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-14 12:07:30 +00:00
Fix search; use youtube-dlc
This commit is contained in:
parent
be1b1bc3a9
commit
ba88c53857
@ -1,6 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
import traceback
|
import traceback
|
||||||
import youtube_dl
|
import youtube_dlc
|
||||||
from tools.converters import *
|
from tools.converters import *
|
||||||
from tools.extractors import extract_yt_initial_data
|
from tools.extractors import extract_yt_initial_data
|
||||||
from cachetools import TTLCache
|
from cachetools import TTLCache
|
||||||
@ -13,7 +13,7 @@ ytdl_opts = {
|
|||||||
"playlist_items": "1-100",
|
"playlist_items": "1-100",
|
||||||
"extract_flat": "in_playlist"
|
"extract_flat": "in_playlist"
|
||||||
}
|
}
|
||||||
ytdl = youtube_dl.YoutubeDL(ytdl_opts)
|
ytdl = youtube_dlc.YoutubeDL(ytdl_opts)
|
||||||
|
|
||||||
def extract_search(q):
|
def extract_search(q):
|
||||||
try:
|
try:
|
||||||
|
@ -4,7 +4,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
import youtube_dl
|
import youtube_dlc
|
||||||
import urllib.error
|
import urllib.error
|
||||||
from tools.converters import *
|
from tools.converters import *
|
||||||
from tools.extractors import extract_yt_initial_data
|
from tools.extractors import extract_yt_initial_data
|
||||||
@ -21,7 +21,7 @@ ytdl_opts = {
|
|||||||
"write_pages": True,
|
"write_pages": True,
|
||||||
"source_address": "0.0.0.0"
|
"source_address": "0.0.0.0"
|
||||||
}
|
}
|
||||||
ytdl = youtube_dl.YoutubeDL(ytdl_opts)
|
ytdl = youtube_dlc.YoutubeDL(ytdl_opts)
|
||||||
|
|
||||||
def get_created_files(id):
|
def get_created_files(id):
|
||||||
if id[0] == "-":
|
if id[0] == "-":
|
||||||
@ -171,7 +171,7 @@ def extract_video(id):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except youtube_dl.DownloadError as e:
|
except youtube_dlc.DownloadError as e:
|
||||||
if isinstance(e.exc_info[1], urllib.error.HTTPError):
|
if isinstance(e.exc_info[1], urllib.error.HTTPError):
|
||||||
if e.exc_info[1].code == 429:
|
if e.exc_info[1].code == 429:
|
||||||
result = {
|
result = {
|
||||||
|
2
index.py
2
index.py
@ -1,7 +1,7 @@
|
|||||||
import configuration
|
import configuration
|
||||||
import cherrypy
|
import cherrypy
|
||||||
import json
|
import json
|
||||||
import youtube_dl
|
import youtube_dlc
|
||||||
import datetime
|
import datetime
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import os
|
import os
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
cherrypy
|
cherrypy
|
||||||
youtube-dl
|
youtube-dlc
|
||||||
cachetools
|
cachetools
|
||||||
python-dateutil
|
python-dateutil
|
||||||
requests
|
requests
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
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) = (\{.+\});</script>""")
|
||||||
|
|
||||||
def extract_yt_initial_data(content):
|
def extract_yt_initial_data(content):
|
||||||
|
content = content.replace("\n", "")
|
||||||
m_yt_initial_data = re.search(r_yt_initial_data, content)
|
m_yt_initial_data = re.search(r_yt_initial_data, content)
|
||||||
if m_yt_initial_data:
|
if m_yt_initial_data:
|
||||||
|
print(m_yt_initial_data.group(1))
|
||||||
yt_initial_data = json.loads(m_yt_initial_data.group(1))
|
yt_initial_data = json.loads(m_yt_initial_data.group(1))
|
||||||
return yt_initial_data
|
return yt_initial_data
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user