This commit is contained in:
AF 2022-08-23 18:32:45 +03:00
parent cfa4db383f
commit 5da82326e3
10 changed files with 63 additions and 6 deletions

View 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>

View File

@ -18,6 +18,10 @@
<option name="name" value="v6taurl" />
<option name="value" value="http://172.18.0.3:5910" />
</DockerEnvVarImpl>
<DockerEnvVarImpl>
<option name="name" value="v6tor" />
<option name="value" value="172.18.0.40" />
</DockerEnvVarImpl>
</list>
</option>
<option name="commandLineOptions" value="--cpus=&quot;3&quot; --memory=&quot;4000mb&quot; --network=&quot;v6d&quot; --ip=&quot;172.18.0.30&quot;" />

View 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
View 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

View File

@ -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',

View File

@ -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}

View File

@ -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

View File

@ -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 += [

View File

@ -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

View 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']