add ability to choose format

Łukasz Klatka 2024-04-05 20:57:36 +02:00
parent 8756523211
commit 42578be027
2 changed files with 33 additions and 7 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/.venv/
/cookies.txt
/output/
/Logs/
/data/

35
main.py
View File

@ -19,13 +19,27 @@ from pywidevine.pssh import PSSH
from http.cookiejar import Cookie
cdmKeyFile=None
session= requests.Session()
output_format ="mkv"
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import string
import unicodedata
def get_int(list_len, accept_zero=False):
while True:
try:
num = int(input("Choose "))
if num > list_len + 1 or (num == 0 and not accept_zero):
print("no such option")
continue
break
except ValueError:
print("Invalid input")
continue
return num
INVALID_FILE_CHARS = '/\\?%*:|"<>' # https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
def secure_filename(filename):
@ -154,6 +168,13 @@ def main():
print("put cookies txt in the folder where this script is ")
return 1
url =input("Please provide url of movie or series or episode: ")
print("Output formats:")
print("0. mkv")
print("1.mp4")
choice = get_int(1,True)
if choice == 1:
global output_format
output_format = "mp4"
session.cookies = http.cookiejar.MozillaCookieJar('cookies.txt')
session.cookies.load(ignore_discard=True, ignore_expires=True)
session.headers.update({
@ -213,7 +234,7 @@ def main():
mainfest_url: str | Any = 'https:' + playlist['sources']['DASH'][0]['src']
licenseurl = playlist['drm']['WIDEVINE']['src']
key = getkey(licenseurl, apifrbid, apicorelid, url, mainfest_url)
title = metadata['title'] + '.mkv'
title = metadata['title'] + '.'+output_format
title = secure_filename(title)
args = [
"N_m3u8DL-RE.exe",
@ -226,7 +247,7 @@ def main():
"--key",
key,
"-M",
"format=mkv",
"format="+output_format,
"--del-after-done",
"-ss",
"all",
@ -245,7 +266,7 @@ def main():
]
subprocess.call(args)
output_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "temp.mkv")
output_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "temp."+output_format)
final_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", title)
os.rename(output_filename, final_filename)
else:
@ -291,7 +312,7 @@ def download_episode(apicorelid, apifrbid, ep, metadata, ses):
licenseurl = playlist['drm']['WIDEVINE']['src']
key = getkey(licenseurl, apifrbid, apicorelid, ep['webUrl'], mainfest_url)
print(key)
title = metadata['title'] + ' S' + str(ses['number']) + 'E' + str(ep['number']) + ' ' + ep['title'] + ".mkv"
title = metadata['title'] + ' S' + str(ses['number']) + 'E' + str(ep['number']) + ' ' + ep['title'] + "."+output_format
title = secure_filename(title)
args = [
@ -305,7 +326,7 @@ def download_episode(apicorelid, apifrbid, ep, metadata, ses):
"--key",
key,
"-M",
"format=mkv",
"format="+output_format,
"--del-after-done",
"-ss",
"all",
@ -324,7 +345,7 @@ def download_episode(apicorelid, apifrbid, ep, metadata, ses):
]
subprocess.call(args)
output_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "temp.mkv")
output_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "temp."+output_format)
final_filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", title)
os.rename(output_filename, final_filename)