Carica file su ''
parent
f29d8a16bb
commit
69c8d1171e
|
@ -0,0 +1,97 @@
|
|||
import os
|
||||
from urllib.parse import urlparse
|
||||
import urllib
|
||||
from unidecode import unidecode
|
||||
import subprocess
|
||||
import glob
|
||||
import shutil
|
||||
import emoji
|
||||
import re
|
||||
from functools import reduce
|
||||
import time
|
||||
|
||||
LIMIT = 20
|
||||
|
||||
|
||||
def extractURL():
|
||||
with open("external_links.txt", "r") as file:
|
||||
url_list = file.read().splitlines()
|
||||
return url_list
|
||||
|
||||
|
||||
def writeToText(text):
|
||||
with open("converted_links.txt", "a", encoding="utf-8", errors="ignore") as f:
|
||||
f.write(f"{text}\n")
|
||||
|
||||
|
||||
def replaceString(string):
|
||||
repls = (".", " "), ("()", "")
|
||||
return reduce(lambda a, kv: a.replace(*kv), repls, string)
|
||||
|
||||
|
||||
def removeYearString(string):
|
||||
pattern = r"\d{4}"
|
||||
return re.sub(pattern, "", string)
|
||||
|
||||
|
||||
def checkURLConverted(value, status):
|
||||
if status:
|
||||
emojitype = emoji.emojize(":check_mark_button:")
|
||||
text = f"{value} - Stato : {emojitype} Convertito"
|
||||
else:
|
||||
emojitype = emoji.emojize(":cross_mark:")
|
||||
text = f"{value} - Stato : {emojitype} Non Convertito {emojitype}"
|
||||
writeToText(text)
|
||||
|
||||
|
||||
def convertMP4toHLSFFmpeg(url,folder,subfolder):
|
||||
limitCounter = 1
|
||||
if (limitCounter % LIMIT) == 0:
|
||||
time.sleep(3600)
|
||||
|
||||
# Encode URL
|
||||
encoded_url = urllib.parse.quote(url)
|
||||
|
||||
# Extract the filename from the URL
|
||||
filename = os.path.basename(urlparse(encoded_url).path)
|
||||
|
||||
# Remove the file extension from the filename
|
||||
extractFileName = os.path.splitext(filename)[0]
|
||||
|
||||
# Decode Folder in More Human Friendly Name
|
||||
decode_filename = urllib.parse.unquote(extractFileName)
|
||||
|
||||
decode_filename = urllib.parse.unquote(decode_filename)
|
||||
|
||||
decode_filename = unidecode(decode_filename.replace(".", " "))
|
||||
|
||||
convertedFileName = decode_filename.replace(" ", "")
|
||||
|
||||
convertedFileName = removeYearString(convertedFileName)
|
||||
|
||||
convertedFileName = replaceString(convertedFileName)
|
||||
|
||||
try:
|
||||
|
||||
ffmpeg_command = f"ffmpeg -i {url} -c:v copy -c:a aac -start_number 0 -hls_time 10 -hls_list_size 0 -f hls '{convertedFileName}.m3u8'"
|
||||
|
||||
subprocess.call(ffmpeg_command, shell=True)
|
||||
|
||||
os.makedirs(folder)
|
||||
|
||||
os.makedirs(os.path.join(folder, subfolder))
|
||||
|
||||
ts_files = glob.glob(f"/var/www/{convertedFileName}*.ts")
|
||||
m3u8_files = glob.glob(f"/var/www/{convertedFileName}*.m3u8")
|
||||
vtt_files = glob.glob(f"/var/www/{convertedFileName}*.vtt")
|
||||
all_files = ts_files + m3u8_files + vtt_files
|
||||
for file in all_files:
|
||||
shutil.move(file, subfolder)
|
||||
checkURLConverted(folder, status=True)
|
||||
limitCounter += 1
|
||||
except Exception:
|
||||
checkURLConverted(folder, status=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
convertMP4toHLSFFmpeg()
|
|
@ -0,0 +1,37 @@
|
|||
import requests
|
||||
from ffmpegHLS import convertMP4toHLSFFmpeg
|
||||
|
||||
LC_URL = "https://onedrive-vercel-index-nnyg.vercel.app/api/?path=/"
|
||||
LC_FILEURL = "https://onedrive-vercel-index-nnyg.vercel.app/api/raw/?path=/"
|
||||
session = requests.Session() # Avvio la Sessione
|
||||
ROOT_FOLDER = input("Inserisci la cartella di Root : ")
|
||||
|
||||
def checkHLS(folder=""): # sourcery skip: move-assign
|
||||
# print("CARTELLA :",folder)
|
||||
apiURL = f"{LC_URL}{ROOT_FOLDER}/{folder}"
|
||||
rawURL = f"{LC_FILEURL}{ROOT_FOLDER}/{folder}"
|
||||
r = session.get(apiURL)
|
||||
if r.status_code == 200:
|
||||
r = r.json()
|
||||
data = r["folder"]["value"]
|
||||
if "next" in r:
|
||||
while "next" in r:
|
||||
nextLink = r["next"]
|
||||
r = session.get(f"{apiURL}&next={nextLink}").json()
|
||||
data.extend(r["folder"]["value"])
|
||||
for elements in data:
|
||||
fileorFolderName = requests.utils.quote(elements["name"])
|
||||
if "stagione" in fileorFolderName.lower():
|
||||
checkHLS(f"{folder}/{fileorFolderName}")
|
||||
if(fileorFolderName.endswith(".mp4")):
|
||||
# print("MP4 FILES : ",fileorFolderName)
|
||||
# print(f"FULL URL : {rawURL}/{fileorFolderName}")
|
||||
cartella_principale,sottocartella = folder.split("/")
|
||||
# TODO: FFMPEG HLS CONVERTER
|
||||
convertMP4toHLSFFmpeg(f"{rawURL}/{fileorFolderName}",cartella_principale,sottocartella)
|
||||
checkHLS(fileorFolderName)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
checkHLS()
|
Loading…
Reference in New Issue