diff --git a/.idea/runConfigurations/Build_Tor.xml b/.idea/runConfigurations/Build_Tor.xml
new file mode 100644
index 0000000..d1c334a
--- /dev/null
+++ b/.idea/runConfigurations/Build_Tor.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Docker_Image.xml b/.idea/runConfigurations/Docker_Image.xml
index 19d103b..797f8b7 100644
--- a/.idea/runConfigurations/Docker_Image.xml
+++ b/.idea/runConfigurations/Docker_Image.xml
@@ -18,6 +18,10 @@
+
+
+
+
diff --git a/.idea/runConfigurations/Tor.xml b/.idea/runConfigurations/Tor.xml
new file mode 100644
index 0000000..dfc90a7
--- /dev/null
+++ b/.idea/runConfigurations/Tor.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Tor.Dockerfile b/Tor.Dockerfile
new file mode 100644
index 0000000..20841b8
--- /dev/null
+++ b/Tor.Dockerfile
@@ -0,0 +1,5 @@
+FROM dperson/torproxy
+RUN apk --no-cache upgrade && apk --no-cache add go git
+RUN git clone https://github.com/Yawning/obfs4.git
+RUN cd obfs4 && go build -o obfs4proxy/obfs4proxy ./obfs4proxy
+RUN cd obfs4 && cp ./obfs4proxy/obfs4proxy /usr/bin/obfs4proxy
diff --git a/v6d3music/core/cache_url.py b/v6d3music/core/cache_url.py
index 078185e..ab4ca99 100644
--- a/v6d3music/core/cache_url.py
+++ b/v6d3music/core/cache_url.py
@@ -6,6 +6,7 @@ from v6d2ctx.context import Benchmark
from v6d2ctx.lock_for import lock_for
from v6d3music.config import myroot
+from v6d3music.utils.tor_prefix import tor_prefix
cache_root = myroot / 'cache'
cache_root.mkdir(exist_ok=True)
@@ -23,7 +24,7 @@ async def cache_url(hurl: str, rurl: str, override: bool, tor: bool) -> None:
tmp_path = cache_root / f'{hurl}.tmp.opus'
args = []
if tor:
- args.append('torify')
+ args.extend(tor_prefix)
args.extend(
[
'ffmpeg', '-hide_banner', '-loglevel', 'warning',
diff --git a/v6d3music/core/ffmpegnormalaudio.py b/v6d3music/core/ffmpegnormalaudio.py
index aea41fd..836e42c 100644
--- a/v6d3music/core/ffmpegnormalaudio.py
+++ b/v6d3music/core/ffmpegnormalaudio.py
@@ -7,6 +7,7 @@ from typing import Optional
import discord
from v6d3music.utils.fill import FILL
+from v6d3music.utils.tor_prefix import tor_prefix
class FFmpegNormalAudio(discord.FFmpegAudio):
@@ -16,8 +17,8 @@ class FFmpegNormalAudio(discord.FFmpegAudio):
):
args = []
if tor:
- args.append(executable)
- executable = 'torify'
+ args.extend([*tor_prefix[1:], executable])
+ executable = tor_prefix[0]
subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}
diff --git a/v6d3music/core/real_url.py b/v6d3music/core/real_url.py
index 98278b7..3f27dbd 100644
--- a/v6d3music/core/real_url.py
+++ b/v6d3music/core/real_url.py
@@ -6,6 +6,7 @@ from v6d2ctx.context import Benchmark
from v6d3music.core.cache_url import cache_db, cache_url
from v6d3music.utils.bytes_hash import bytes_hash
+from v6d3music.utils.tor_prefix import tor_prefix
async def real_url(url: str, override: bool, tor: bool) -> str:
@@ -17,7 +18,7 @@ async def real_url(url: str, override: bool, tor: bool) -> str:
return curl
args = []
if tor:
- args.append('torify')
+ args.extend(tor_prefix)
args.extend(
[
'youtube-dl', '--no-playlist', '-f', 'bestaudio', '-g', '--', url
diff --git a/v6d3music/core/ytaudio.py b/v6d3music/core/ytaudio.py
index 4155156..a65ae61 100644
--- a/v6d3music/core/ytaudio.py
+++ b/v6d3music/core/ytaudio.py
@@ -10,6 +10,7 @@ from v6d3music.core.ffmpegnormalaudio import FFmpegNormalAudio
from v6d3music.core.real_url import real_url
from v6d3music.utils.fill import FILL
from v6d3music.utils.sparq import sparq
+from v6d3music.utils.tor_prefix import tor_prefix
class YTAudio(discord.AudioSource):
@@ -78,7 +79,7 @@ class YTAudio(discord.AudioSource):
return
self._durations.setdefault(url, '')
if self.tor:
- args = ['torify']
+ args = [*tor_prefix]
else:
args = []
args += [
diff --git a/v6d3music/utils/tor_extract.py b/v6d3music/utils/tor_extract.py
index 7071057..b7cbd98 100644
--- a/v6d3music/utils/tor_extract.py
+++ b/v6d3music/utils/tor_extract.py
@@ -2,11 +2,13 @@ import asyncio
import json
import subprocess
+from v6d3music.utils.tor_prefix import tor_prefix
+
async def tor_extract(params: dict, url: str, **kwargs):
print(f'tor extracting {url}')
p = subprocess.Popen(
- ['torify', 'python', '-m', 'v6d3music.run-extract'],
+ [*tor_prefix, 'python', '-m', 'v6d3music.run-extract'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True
diff --git a/v6d3music/utils/tor_prefix.py b/v6d3music/utils/tor_prefix.py
new file mode 100644
index 0000000..5bdfde3
--- /dev/null
+++ b/v6d3music/utils/tor_prefix.py
@@ -0,0 +1,10 @@
+__all__ = ('tor_prefix',)
+
+import os
+
+if (address := os.getenv('v6tor', None)) is not None:
+ print('tor through torsocks')
+ tor_prefix = ['torsocks', '--address', address]
+else:
+ print('tor through torify')
+ tor_prefix = ['torify']