Update download.py
This commit is contained in:
parent
ad24e0827e
commit
7345d1535e
106
app/download.py
106
app/download.py
@ -39,68 +39,66 @@ class grab():
|
|||||||
print("Downloaded MP4 but no thumbnail found.")
|
print("Downloaded MP4 but no thumbnail found.")
|
||||||
|
|
||||||
class dropout():
|
class dropout():
|
||||||
def show(show,season,episode):
|
def show(show, season, episode_start):
|
||||||
directory='/tv/'+show+'/Season '+season+'/'
|
directory = f'/tv/{show}/Season {season}/'
|
||||||
|
if not os.path.exists(directory):
|
||||||
|
os.makedirs(directory)
|
||||||
|
|
||||||
with open('/data/dropout.json', 'r') as json_file:
|
with open('/data/dropout.json', 'r') as json_file:
|
||||||
url_mapping = json.load(json_file)
|
url_mapping = json.load(json_file)
|
||||||
url = next((item['URL'] for item in url_mapping if item['SHOW'] == show), None)
|
url = next((item['URL'] for item in url_mapping if item['SHOW'] == show), None)
|
||||||
if url is not None:
|
if url is None:
|
||||||
url = f'{url}/season:{season}'
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Show '{show}' not found in the JSON data.")
|
raise ValueError(f"Show '{show}' not found in the JSON data.")
|
||||||
if not os.path.exists(directory):
|
|
||||||
os.makedirs(directory)
|
playlist_url = f'{url}/season:{season}'
|
||||||
if episode is None or episode == '':
|
|
||||||
episode = '%(playlist_index)02d'
|
# Create match_filter
|
||||||
else:
|
filter_pattern = (
|
||||||
try:
|
"title !~= "
|
||||||
dl_ops['playliststart'] = int(episode)
|
r"'(?i).*behind.?the.?scenes.*"
|
||||||
except ValueError:
|
r"|.*trailer.*"
|
||||||
# Handle the error, e.g., log it or set a default value
|
r"|.*recap.*"
|
||||||
dl_ops['playliststart'] = 0 # or some appropriate default value
|
r"|.*last.looks.*'"
|
||||||
dl_ops = {
|
)
|
||||||
'format': 'bestvideo+bestaudio/best',
|
match_filter = yt_dlp.utils.match_filter_func(filter_pattern)
|
||||||
'audio_quality': '256K',
|
|
||||||
'paths': {
|
ydl_opts = {
|
||||||
'temp': '/temp',
|
'quiet': True,
|
||||||
'home': directory
|
'skip_download': True,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Step 1: Extract playlist info
|
||||||
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
playlist_info = ydl.extract_info(playlist_url, download=False)
|
||||||
|
|
||||||
|
entries = playlist_info.get('entries', [])
|
||||||
|
filtered_entries = []
|
||||||
|
for entry in entries:
|
||||||
|
if match_filter(entry) is None: # Not filtered out
|
||||||
|
filtered_entries.append(entry)
|
||||||
|
|
||||||
|
# Step 2: Download filtered entries with corrected episode numbers
|
||||||
|
episode_start = int(episode_start) if episode_start else 1
|
||||||
|
|
||||||
|
for i, entry in enumerate(filtered_entries, start=episode_start):
|
||||||
|
episode_number = f"{i:02}"
|
||||||
|
filename_template = f"{show} - S{int(season):02}E{episode_number} - %(title)s.%(ext)s"
|
||||||
|
|
||||||
|
dl_opts = {
|
||||||
|
'format': 'bestvideo+bestaudio/best',
|
||||||
|
'audio_quality': '256K',
|
||||||
|
'paths': {
|
||||||
|
'temp': '/temp',
|
||||||
|
'home': directory
|
||||||
},
|
},
|
||||||
'cookiefile': '/data/dropout.cookies.txt',
|
'cookiefile': '/data/dropout.cookies.txt',
|
||||||
'match_filter': yt_dlp.utils.match_filter_func("title !~= '(?i).*behind.?the.?scenes.*|.*trailer.*|.*recap.*|.*last.looks.*'"),
|
'writesubtitles': True,
|
||||||
# 'reject_title': [
|
'subtitleslangs': ['en'],
|
||||||
# r'(?i).*behind.?the.?scenes.*', # Reject titles with "behind the scenes" (case-insensitive)
|
'outtmpl': filename_template,
|
||||||
# r'(?i).*trailer.*', # Reject titles with "trailer" (case-insensitive)
|
|
||||||
# r'(?i).*recap.*', # Reject titles with "recap" (case-insensitive)
|
|
||||||
# r'(?i).*last.looks.*' # Reject titles with "last looks" (case-insensitive)
|
|
||||||
# ],
|
|
||||||
'outtmpl': show + ' - S'+f"{int(season):02}"+'E'+episode+' - %(title)s.%(ext)s',
|
|
||||||
'noplaylist': True,
|
|
||||||
# Additional options for downloading subtitles
|
|
||||||
'writesubtitles': True, # Download subtitles
|
|
||||||
'subtitleslangs': ['en'] # Specify the language for subtitles (e.g., 'en' for English)
|
|
||||||
}
|
}
|
||||||
with yt_dlp.YoutubeDL(dl_ops) as ydl:
|
|
||||||
ydl.download([url])
|
|
||||||
# ydl_opts = {
|
|
||||||
# 'quiet': True, # Turn off download progress messages
|
|
||||||
# 'skip_download': True, # Don't download anything
|
|
||||||
# 'cookiefile': '/data/dropout.cookies.txt',
|
|
||||||
# }
|
|
||||||
|
|
||||||
# with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
||||||
# info = ydl.extract_info(url, download=False)
|
|
||||||
|
|
||||||
# print(f"Playlist Title: {info.get('title')}")
|
|
||||||
# print(f"Uploader: {info.get('uploader')}")
|
|
||||||
# print(f"Number of videos: {len(info.get('entries', []))}")
|
|
||||||
# print()
|
|
||||||
|
|
||||||
# for i, entry in enumerate(info['entries'], 1):
|
|
||||||
# print(f"{i}. {entry.get('title')}")
|
|
||||||
# print(f" URL: {entry.get('webpage_url')}")
|
|
||||||
# print(f" Duration: {entry.get('duration')} seconds")
|
|
||||||
# print()
|
|
||||||
|
|
||||||
|
with yt_dlp.YoutubeDL(dl_opts) as ydl:
|
||||||
|
ydl.download([entry['webpage_url']])
|
||||||
|
|
||||||
|
|
||||||
def series():
|
def series():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user