Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
Fix #33 by selecting best quality in YoutubeDL, Fix #34 by letting us…
Browse files Browse the repository at this point in the history
…er know if they're trying to download premium contents
  • Loading branch information
CoffeeStraw committed May 18, 2021
1 parent 3eac60a commit 06f5b57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ def dl_from_vvvvid(url, requests_obj):
print(f"\n{Style.BRIGHT}Stagione: {Fore.BLUE + season['name']}")

# Creating content directory if not existing
content_dir = os.path.join(
dl_path, os_fix_filename(f'{cont_title} - {season["name"]}')
)
dir_name = os_fix_filename(f'{cont_title} - {season["name"]}')
content_dir = os.path.join(dl_path, dir_name)
if not os.path.exists(content_dir):
os.mkdir(content_dir)

Expand Down Expand Up @@ -97,12 +96,13 @@ def dl_from_vvvvid(url, requests_obj):

# Get m3u8 link and HTTP headers
try:
with YoutubeDL({"quiet": True}) as ydl:
r = ydl.extract_info(ep_url, download=False)
media_url = r["url"]
http_headers = "".join(
[f"{k}: {v}\n" for k, v in r["http_headers"].items()]
)
with YoutubeDL({"quiet": True, "no_warnings": True}) as ydl:
r = ydl.extract_info(ep_url, download=False)["formats"][-1]

media_url = r["url"]
http_headers = "".join(
[f"{k}: {v}\n" for k, v in r["http_headers"].items()]
)
except KeyError:
# Video could be provided by external services (like youtube). In those cases, skip the episode
print(
Expand All @@ -117,11 +117,14 @@ def dl_from_vvvvid(url, requests_obj):
)

# Download the episode using ffmpeg
ffmpeg_dl(
error = ffmpeg_dl(
media_url,
http_headers,
os.path.join(content_dir, f"{ep_name}.part.mkv"),
)
if error:
print(f"{Fore.RED}[ERROR]{Style.RESET_ALL}", error)
continue

# Remove ".part" from end of file
os.rename(
Expand All @@ -133,7 +136,7 @@ def dl_from_vvvvid(url, requests_obj):
# In that case, delete the folder as well.
if not os.listdir(content_dir):
print(
f"\n{Fore.YELLOW}NOTA:{Style.RESET_ALL} Rimozione della cartella creata per {season['name']} (non è stato scaricato alcun contenuto)."
f'\n{Fore.YELLOW}NOTA:{Style.RESET_ALL} Rimozione della cartella creata per "{dir_name}" (non è stato scaricato alcun contenuto).'
)
os.rmdir(content_dir)

Expand Down
4 changes: 3 additions & 1 deletion src/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from tqdm import tqdm
from platform import system
from functools import reduce
from colorama import Fore, Style


def os_fix_filename(filename):
Expand Down Expand Up @@ -111,4 +110,7 @@ def ffmpeg_dl(media_url, http_headers, output_path, timeout=30):
cmd, stderr=subprocess.PIPE, bufsize=1, text=True, encoding="utf-8"
) as p, ProgressBar() as pbar:
for line in p.stderr:
if "access denied" in line.lower():
return "Il server ha rifiutato l'accesso al file. Si ricorda che con il presente software non è possibile scaricare contenuti a pagamento. Se pensi si tratti di un errore, puoi aprire una issue su GitHub."

pbar.update(line)

0 comments on commit 06f5b57

Please sign in to comment.