Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from jschwindt/master
Browse files Browse the repository at this point in the history
Update to new pseudo obfuscated chunks url
  • Loading branch information
mgaitan authored Aug 30, 2019
2 parents c1f9b9f + cc52d36 commit 7822044
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.vscode
venv
__pycache__
build
dist
radiocut_downloader.egg-info
*.pyc
13 changes: 12 additions & 1 deletion radiocut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dateutil.parser import parse
from pyquery import PyQuery
import requests
import base64
from moviepy.editor import AudioFileClip, ImageClip, concatenate_audioclips

__version__ = '0.4'
Expand All @@ -39,6 +40,16 @@
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0',
}

def get_chunks_url(base_url, station, start_folder):
"""
Computes first the (not too) 'obfuscated' code that the new chunks server requires
and returns the final URL.
"""
code = base64.b64encode('andaa{}|{}cagar'.format(station, start_folder).encode('ascii'))
code = code.decode('ascii').replace('=', '~').replace('/', '_').replace('+', '-')
url = '{}/server/gec/www/{}/'.format(base_url, code)
return url

def get_audiocut(url, verbose=False, duration=None):
"""
Given an "audio cut" url, return a moviepy's AudioClip instance with the cut
Expand All @@ -57,7 +68,7 @@ def get_audiocut(url, verbose=False, duration=None):
start_folder = int(seconds[:6])
chunks = []
while True:
chunks_url = "{}/server/get_chunks/{}/{:d}/".format(base_url, station, start_folder)
chunks_url = get_chunks_url(base_url, station, start_folder)
if verbose:
print('Getting chunks index {}'.format(chunks_url))
chunks_json = requests.get(chunks_url, headers=HEADERS).json()[str(start_folder)]
Expand Down

0 comments on commit 7822044

Please sign in to comment.