torsocks
This commit is contained in:
parent
cfa4db383f
commit
5da82326e3
12
.idea/runConfigurations/Build_Tor.xml
Normal file
12
.idea/runConfigurations/Build_Tor.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Build Tor" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
|
||||||
|
<deployment type="dockerfile">
|
||||||
|
<settings>
|
||||||
|
<option name="imageTag" value="v6tor" />
|
||||||
|
<option name="buildOnly" value="true" />
|
||||||
|
<option name="sourceFilePath" value="Tor.Dockerfile" />
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
@ -18,6 +18,10 @@
|
|||||||
<option name="name" value="v6taurl" />
|
<option name="name" value="v6taurl" />
|
||||||
<option name="value" value="http://172.18.0.3:5910" />
|
<option name="value" value="http://172.18.0.3:5910" />
|
||||||
</DockerEnvVarImpl>
|
</DockerEnvVarImpl>
|
||||||
|
<DockerEnvVarImpl>
|
||||||
|
<option name="name" value="v6tor" />
|
||||||
|
<option name="value" value="172.18.0.40" />
|
||||||
|
</DockerEnvVarImpl>
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="commandLineOptions" value="--cpus="3" --memory="4000mb" --network="v6d" --ip="172.18.0.30"" />
|
<option name="commandLineOptions" value="--cpus="3" --memory="4000mb" --network="v6d" --ip="172.18.0.30"" />
|
||||||
|
20
.idea/runConfigurations/Tor.xml
Normal file
20
.idea/runConfigurations/Tor.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Tor" type="docker-deploy" factoryName="docker-image" server-name="Docker">
|
||||||
|
<deployment type="docker-image">
|
||||||
|
<settings>
|
||||||
|
<option name="imageTag" value="v6tor" />
|
||||||
|
<option name="containerName" value="v6tor" />
|
||||||
|
<option name="commandLineOptions" value="--network v6d --ip 172.18.0.40" />
|
||||||
|
<option name="volumeBindings">
|
||||||
|
<list>
|
||||||
|
<DockerVolumeBindingImpl>
|
||||||
|
<option name="containerPath" value="/etc/tor/torrc" />
|
||||||
|
<option name="hostPath" value="/home/timofey/deployment/tor/torrc" />
|
||||||
|
</DockerVolumeBindingImpl>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
5
Tor.Dockerfile
Normal file
5
Tor.Dockerfile
Normal file
@ -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
|
@ -6,6 +6,7 @@ from v6d2ctx.context import Benchmark
|
|||||||
from v6d2ctx.lock_for import lock_for
|
from v6d2ctx.lock_for import lock_for
|
||||||
|
|
||||||
from v6d3music.config import myroot
|
from v6d3music.config import myroot
|
||||||
|
from v6d3music.utils.tor_prefix import tor_prefix
|
||||||
|
|
||||||
cache_root = myroot / 'cache'
|
cache_root = myroot / 'cache'
|
||||||
cache_root.mkdir(exist_ok=True)
|
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'
|
tmp_path = cache_root / f'{hurl}.tmp.opus'
|
||||||
args = []
|
args = []
|
||||||
if tor:
|
if tor:
|
||||||
args.append('torify')
|
args.extend(tor_prefix)
|
||||||
args.extend(
|
args.extend(
|
||||||
[
|
[
|
||||||
'ffmpeg', '-hide_banner', '-loglevel', 'warning',
|
'ffmpeg', '-hide_banner', '-loglevel', 'warning',
|
||||||
|
@ -7,6 +7,7 @@ from typing import Optional
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
from v6d3music.utils.fill import FILL
|
from v6d3music.utils.fill import FILL
|
||||||
|
from v6d3music.utils.tor_prefix import tor_prefix
|
||||||
|
|
||||||
|
|
||||||
class FFmpegNormalAudio(discord.FFmpegAudio):
|
class FFmpegNormalAudio(discord.FFmpegAudio):
|
||||||
@ -16,8 +17,8 @@ class FFmpegNormalAudio(discord.FFmpegAudio):
|
|||||||
):
|
):
|
||||||
args = []
|
args = []
|
||||||
if tor:
|
if tor:
|
||||||
args.append(executable)
|
args.extend([*tor_prefix[1:], executable])
|
||||||
executable = 'torify'
|
executable = tor_prefix[0]
|
||||||
|
|
||||||
subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}
|
subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from v6d2ctx.context import Benchmark
|
|||||||
|
|
||||||
from v6d3music.core.cache_url import cache_db, cache_url
|
from v6d3music.core.cache_url import cache_db, cache_url
|
||||||
from v6d3music.utils.bytes_hash import bytes_hash
|
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:
|
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
|
return curl
|
||||||
args = []
|
args = []
|
||||||
if tor:
|
if tor:
|
||||||
args.append('torify')
|
args.extend(tor_prefix)
|
||||||
args.extend(
|
args.extend(
|
||||||
[
|
[
|
||||||
'youtube-dl', '--no-playlist', '-f', 'bestaudio', '-g', '--', url
|
'youtube-dl', '--no-playlist', '-f', 'bestaudio', '-g', '--', url
|
||||||
|
@ -10,6 +10,7 @@ from v6d3music.core.ffmpegnormalaudio import FFmpegNormalAudio
|
|||||||
from v6d3music.core.real_url import real_url
|
from v6d3music.core.real_url import real_url
|
||||||
from v6d3music.utils.fill import FILL
|
from v6d3music.utils.fill import FILL
|
||||||
from v6d3music.utils.sparq import sparq
|
from v6d3music.utils.sparq import sparq
|
||||||
|
from v6d3music.utils.tor_prefix import tor_prefix
|
||||||
|
|
||||||
|
|
||||||
class YTAudio(discord.AudioSource):
|
class YTAudio(discord.AudioSource):
|
||||||
@ -78,7 +79,7 @@ class YTAudio(discord.AudioSource):
|
|||||||
return
|
return
|
||||||
self._durations.setdefault(url, '')
|
self._durations.setdefault(url, '')
|
||||||
if self.tor:
|
if self.tor:
|
||||||
args = ['torify']
|
args = [*tor_prefix]
|
||||||
else:
|
else:
|
||||||
args = []
|
args = []
|
||||||
args += [
|
args += [
|
||||||
|
@ -2,11 +2,13 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from v6d3music.utils.tor_prefix import tor_prefix
|
||||||
|
|
||||||
|
|
||||||
async def tor_extract(params: dict, url: str, **kwargs):
|
async def tor_extract(params: dict, url: str, **kwargs):
|
||||||
print(f'tor extracting {url}')
|
print(f'tor extracting {url}')
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
['torify', 'python', '-m', 'v6d3music.run-extract'],
|
[*tor_prefix, 'python', '-m', 'v6d3music.run-extract'],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
text=True
|
text=True
|
||||||
|
10
v6d3music/utils/tor_prefix.py
Normal file
10
v6d3music/utils/tor_prefix.py
Normal file
@ -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']
|
Loading…
Reference in New Issue
Block a user