Skip to content

Commit

Permalink
Merge pull request #14 from URN/downloader-fixes
Browse files Browse the repository at this point in the history
Some fixes to the downloader
  • Loading branch information
Emersont1 authored Oct 20, 2021
2 parents d4a4b8b + 1f4d68a commit 8ae1452
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
23 changes: 15 additions & 8 deletions audioboom/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import audioboom
import audioboom.utils as utils

from os.path import join, exists
from os.path import join, exists, relpath
from os import mkdir
import requests
import time


class Channel:
Expand Down Expand Up @@ -93,7 +94,7 @@ def save(self, root):
continue
ep_ = [e for e in self.episodes if e.id == id][0]
path__ = join(path_, ep_.slug)
self.save_episode(path__, ep_)
self.save_episode(path__, ep_, root)
consumed.append(ep_.id)

# save unused episodes
Expand All @@ -107,9 +108,10 @@ def save(self, root):
path_ = join(path, ep.slug)

mkdir(path_)
self.save_episode(path_, ep)
self.save_episode(path_, ep, root)

def save_episode(self, path, ep):
def save_episode(self, path, ep, root):
print(f"Saving {ep.title} to {path}")
if not exists(path):
mkdir(path)

Expand All @@ -122,7 +124,12 @@ def save_episode(self, path, ep):
i = requests.get(ep.thumbnail, allow_redirects=True)
f.write(i.content)

with open(join(path, "audio.mp3"), 'wb') as f:
pass
a = requests.get(ep.mp3, allow_redirects=True)
f.write(a.content)
# Does not download the audios, just outputs a list to be used in download_tool.py
# with open(join(path, "audio.mp3"), 'wb') as f:
# pass
# a = requests.get(ep.mp3, allow_redirects=True)
# f.write(a.content)

with open(join(root, "downloads.txt"), 'a') as f:
out = join(relpath(path, root), "audio.mp3")
f.write(f"{ep.mp3}\t{out}\n")
12 changes: 12 additions & 0 deletions download_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
import requests

for line in sys.stdin:
[url, path] = line.split()

a = requests.get(url, allow_redirects=True)
if a.status_code != 200 or a.headers['Content-length'] == 94:
print(f"{url}\t{path}")
else:
with open(path, 'wb') as f:
f.write(a.content)

0 comments on commit 8ae1452

Please sign in to comment.