Skip to content

Commit

Permalink
pytube fix (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic authored Oct 15, 2024
1 parent e6e23be commit 01ed381
Show file tree
Hide file tree
Showing 5 changed files with 618 additions and 470 deletions.
24 changes: 24 additions & 0 deletions bot/integrations/reddit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytubefix


def monkey_patch_red_downloader():
import sys
from importlib import abc as importlib_abc
from importlib import machinery as importlib_machinery

class ReplaceLoader(importlib_abc.Loader):
def load_module(self, name):
sys.modules[name] = pytubefix
return pytubefix

class ReplaceFinder(importlib_abc.MetaPathFinder):
def find_spec(self, fullname, path, target=None):
if fullname == 'pytube':
return importlib_machinery.ModuleSpec(fullname, ReplaceLoader())
return None

# Insert the custom finder into sys.meta_path
sys.meta_path.insert(0, ReplaceFinder())


monkey_patch_red_downloader()
2 changes: 1 addition & 1 deletion bot/integrations/youtube/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pytube.innertube import _default_clients
from pytubefix.innertube import _default_clients


# Age restriction bypass - https://stackoverflow.com/a/78267693/10428848
Expand Down
2 changes: 1 addition & 1 deletion bot/integrations/youtube/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import typing

import pytube
import pytubefix as pytube
from django.conf import settings

from bot import constants
Expand Down
Loading

0 comments on commit 01ed381

Please sign in to comment.