init
This commit is contained in:
commit
75312b5ee3
17 files changed
+2503
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import vfetcher
|
||||
import vobjects
|
||||
import urllib.parse
|
||||
import json
|
||||
import subprocess
|
||||
import os
|
||||
import shlex
|
||||
|
||||
|
||||
def audio_list(config):
|
||||
payload = config.audio_list_payload()
|
||||
json_list = vfetcher.fetch(
|
||||
payload["method"],
|
||||
f"{config.vk_host()}{config.audio_list_url()}",
|
||||
payload["headers"].items(),
|
||||
payload["body"].encode(),
|
||||
)
|
||||
plain_list = json.loads(json_list)
|
||||
return vobjects.audio_list(plain_list)
|
||||
|
||||
|
||||
def audio_data(config, audio_list):
|
||||
payload = config.audio_data_payload()
|
||||
body = {
|
||||
"al": "1",
|
||||
"audio_ids": ",".join([audio.cid() for audio in audio_list]),
|
||||
}
|
||||
json_data = vfetcher.fetch(
|
||||
payload["method"],
|
||||
f"{config.vk_host()}{config.audio_data_url()}",
|
||||
payload["headers"].items(),
|
||||
urllib.parse.urlencode(body).encode("ascii"),
|
||||
)
|
||||
plain_data = json.loads(json_data.decode("windows-1251"))
|
||||
return vobjects.audio_data(plain_data)
|
||||
|
||||
|
||||
def audio_manifest(config, audio_data):
|
||||
body = {}
|
||||
raw_content = vfetcher.fetch(
|
||||
"GET",
|
||||
audio_data.blessed_url(config),
|
||||
{}.items(),
|
||||
urllib.parse.urlencode(body).encode(),
|
||||
)
|
||||
return vobjects.Manifest(raw_content)
|
||||
|
||||
|
||||
def audio_chunk(config, audio_data, chunk):
|
||||
body = {}
|
||||
manifest = audio_data.manifest()
|
||||
raw_data = vfetcher.fetch(
|
||||
"GET",
|
||||
f"{audio_data.root_url(config)}{chunk}",
|
||||
{}.items(),
|
||||
urllib.parse.urlencode(body).encode("utf-8"),
|
||||
)
|
||||
return vobjects.Chunk(manifest, chunk, raw_data)
|
||||
|
||||
|
||||
def audio(config, audio_manifest, idx=None):
|
||||
data = audio_manifest.data()
|
||||
audio_dir = config.audio_directory()
|
||||
if not os.path.exists(audio_dir):
|
||||
os.makedirs(audio_dir)
|
||||
subprocess.run(
|
||||
[
|
||||
f'ffmpeg -y -protocol_whitelist file,http,https,tcp,tls,crypto -allowed_extensions ALL -i {audio_manifest.index(config)} -metadata title={shlex.quote(data.title())} -metadata artist={shlex.quote(data.artist())} -metadata track={idx} {shlex.quote(data.findex(config))}',
|
||||
],
|
||||
shell=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
Reference in new issue
Block a user