-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_csv.py
89 lines (61 loc) · 2.38 KB
/
search_csv.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import json
import os
import shutil
import time
import xml.dom.minidom
import zipfile
from pathlib import Path
import csv
import pandas as pd
import requests
import xmltodict
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from tqdm import tqdm
from webdriver_manager.chrome import ChromeDriverManager
from create_abs_json import func_create_abs_json
ua = UserAgent(verify_ssl=False)
def search_csv(search_term):
df = pd.read_csv(
"DrWhoAudiobooks.csv",
sep=",",
names=["SeriesTitle", "ProductTitle", "ReleaseDate", "FileName"],
)
search_result = df.loc[df["ProductTitle"] == search_term]
return search_result
def search_csv_reader(search_term):
with open("DrWhoAudiobooks.csv") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
for row in csv_reader:
if search_term.upper() in row[1].upper():
print(row)
return row
search_path = "X:\\Media\\CompletedTorrents\\8. August"
for path in Path(search_path).rglob("*.mp3"):
print(str(path))
if os.path.exists(os.path.join(str(path.parent), "metadata.json")):
continue
# trying to get the series code from parent folder, e.g. 1. Main Range (MR) = MR
series_code = path.parent.parent.name.split("(")[-1].split(")")[0]
# start by stripping that code out
# Currently: MR 001 - The Sirens of Time.mp3
episode_title = path.stem.replace(f"{series_code} ", "")
# titles will normally be something like: 001. Doctor Who: The Sirens of Time
episode_title = episode_title.replace(" - ", ". Doctor Who: ")
print(episode_title)
result = search_csv(episode_title)
if not result.empty:
SeriesTitle, ProductTitle, ReleaseDate, JSONFileName = result.values[0]
print(f"Series: {SeriesTitle}, Title: {ProductTitle}")
# func_create_abs_json(JSONFileName, str(path.parent))
continue
episode_title = path.stem.split(" - ")[-1]
result = search_csv_reader(episode_title)
if result:
SeriesTitle, ProductTitle, ReleaseDate, JSONFileName = result
print(f"Series: {SeriesTitle}, Title: {ProductTitle}")
func_create_abs_json(JSONFileName, str(path.parent))
continue