Skip to content

Commit

Permalink
Merge pull request #206 from barrucadu/nya/backup-youtube
Browse files Browse the repository at this point in the history
[nyarlathotep] Add a youtube video "backup" script
  • Loading branch information
barrucadu authored Jul 17, 2023
2 parents b9cdbf9 + d3758ca commit d65c8b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion hosts/nyarlathotep/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ in

nixfiles.backups.enable = true;
nixfiles.backups.environmentFile = config.sops.secrets."nixfiles/backups/env".path;
nixfiles.backups.pythonScripts.share = fileContents ./jobs/backup-share.py;
nixfiles.backups.pythonScripts = {
share = fileContents ./jobs/backup-share.py;
youtube = fileContents ./jobs/backup-youtube.py;
};
sops.secrets."nixfiles/backups/env" = { };


Expand Down
26 changes: 26 additions & 0 deletions hosts/nyarlathotep/jobs/backup-youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

"""Youtube "backup" script - generates a script to download videos.
"""

import os
import shlex

SOURCE_DIR = "/mnt/nas/misc/youtube"
VIDEO_URL = "https://www.youtube.com/watch?v="

with open("download-videos.sh", "w") as f:
print("#!/bin/sh", file=f)
print("", file=f)

for dirpath, dirnames, filenames in os.walk(SOURCE_DIR, topdown=True):
for dirname in dirnames:
print(f"mkdir {shlex.quote(os.path.join(dirpath, dirname))}", file=f)
for filename in filenames:
# filenames are of the form "title [id].ext"
name_pattern = filename.split("[")[-2] + "[%(id)s].%(ext)s"
url = VIDEO_URL + filename.split("[")[-1].split("]")[0]
print(
f"yt-dlp -P {shlex.quote(dirpath)} -o {shlex.quote(name_pattern)} {shlex.quote(url)}",
file=f,
)

0 comments on commit d65c8b5

Please sign in to comment.