-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.nim
49 lines (39 loc) · 1.37 KB
/
common.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Regular expression support is provided by the PCRE library package,
# which is open source software, written by Philip Hazel, and copyright
# by the University of Cambridge, England. Source can be found at
# ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
import std/[options, strutils, sugar, sequtils, json, nre, os]
import cache
type
Item* = object
url*: string
performer*: Option[string]
title*: string
duration*: int
cache_items*: seq[JsonNode]
thumbnail_id*: string
keep_thumbnail*: bool
need_proxy*: bool
ItemsCollector*[T] = object
url*: T
cache*: Cache
performer_from_title*: bool
Downloaded* = object
audio_path*: string
thumbnail_path*: string
UnsupportedUrlError* = object of ValueError
var ytdlp_proxy* = ""
let configs_dir* = get_config_dir() / "podcaster"
proc decouple_performer_and_title*(
performer: string, title: string
): tuple[performer: Option[string], title: string] =
var p = performer.replace(re"Various Artists? *(?:-|—)? *", "").strip
var t = title.replace(re"Various Artists? *(?:-|—)? *", "").strip
if p in ["", "NA"]:
let splitted = t.split(re"-|—", 1).map (s: string) => s.strip
if splitted.len == 1:
return (performer: none(string), title: t)
else:
p = splitted[0]
t = splitted[1]
return (performer: some(p), title: strip t.replace p & " -")