PEP8 Compliance

* Version bump
* 30 -> 24 videos are now able to be retrieved...
This commit is contained in:
nanometer5088
2023-02-04 02:08:51 -03:00
parent c4b5aa102e
commit e387d54b1d
10 changed files with 89 additions and 41 deletions

View File

@@ -1 +1 @@
0.4
0.41

3
log.py
View File

@@ -1,2 +1,3 @@
from src.logs import Logging
logtofile = Logging().log
logtofile = Logging().log

View File

@@ -63,7 +63,7 @@ try:
if downloadquestion == 2:
log("The user chose to download videos from a creator")
print(
"Due to specific limitations of the current data method, downloading by creator will only get the latest 30 videos."
"Due to specific limitations of the current data method, downloading by creator will only get the latest 24 videos."
)
print(
"This limitation is being actively researched, any contributions will be welcome."
@@ -122,7 +122,7 @@ try:
if watchquestion == 2:
log("The user chose to stream videos from a creator")
print(
"Due to specific limitations of the current data method, watching by creator will only get the latest 30 videos."
"Due to specific limitations of the current data method, watching by creator will only get the latest 24 videos."
)
print(
"This limitation is being actively researched, any contributions will be welcome."
@@ -136,7 +136,7 @@ try:
if watchquestion == 3:
log("The user chose to stream trending videos\n")
print(
"Due to specific limitations of the current data method, watching by creator will only get the latest 30 videos."
"Due to specific limitations of the current data method, watching by creator will only get the latest 24 videos."
)
print(
"This limitation is being actively researched, any contributions will be welcome."

View File

@@ -1,8 +1,9 @@
import sys
from log import logtofile as log
import atoma
import requests
from log import logtofile as log
from src.streaming import getVideoInfo
@@ -13,10 +14,14 @@ def info(username):
print(
"Something went wrong while getting the information. Make sure the username was correctly inserted and try again."
)
log(f"https://tik.hostux.net/@{username}/rss returned a 404 error. The username is likely incorrect")
log(
f"https://tik.hostux.net/@{username}/rss returned a 404 error. The username is likely incorrect"
)
sys.exit()
if str(response.content) == "b''":
log("https://tik.hostux.net/@{username}/rss returned no information. The account likely does not exist")
log(
"https://tik.hostux.net/@{username}/rss returned no information. The account likely does not exist"
)
print("The specified account does not exist.")
sys.exit()
@@ -24,7 +29,7 @@ def info(username):
# log("This account does not have a bio.\n")
# else:
# log(f"Bio: {str(response.description)}\n") ## TIKTOK BIO
return atoma.parse_rss_bytes(response.content)
@@ -41,9 +46,12 @@ def streamuser(username):
links = getLinks(username)
if len(links) == 0:
log("The link list is empty. The specified account is likely private or has no published videos")
log(
"The link list is empty. The specified account is likely private or has no published videos"
)
print("This account is private or has no published videos.")
from src.streaming import mpv, getVideoInfo
for i in range(len(links)):
url = getVideoInfo(links[i])
mpv(url)

View File

@@ -1,14 +1,16 @@
import os
from log import logtofile as log
from src.functions import url_redirection
from yt_dlp import YoutubeDL
from yt_dlp.utils import DownloadError
from log import logtofile as log
from src.functions import url_redirection
def downloader(url):
ydl_opts = {
"format": "bestvideo*+bestaudio/best",
"outtmpl": os.getcwd()
+ "/video/by-creator/%(creator)s/%(id)s.%(ext)s",
"outtmpl": os.getcwd() + "/video/by-creator/%(creator)s/%(id)s.%(ext)s",
}
YoutubeDL(ydl_opts).download(url)
@@ -24,7 +26,7 @@ def downloadtiktoks(urls):
\n\tPress ENTER to proceed...
"""
)
if a != "":
log(f"User denied to download {len(urls)} tiktoks - Software exited")
print("Operation canceled.")
@@ -41,9 +43,11 @@ def downloadtiktoks(urls):
print("")
except DownloadError:
print("This video is unavailable ")
log(f"Video {url} will not be downloaded - The video is unavailable (banned or taken down)")
log(
f"Video {url} will not be downloaded - The video is unavailable (banned or taken down)"
)
errorcount.append(urls)
except IndexError:
print("The tiktoks were downloaded")
log("The tiktoks were downloaded")
@@ -52,4 +56,4 @@ def downloadtiktoks(urls):
f"\n{len(errorcount)} video(s) failed to download.\nThe video(s) were likely banned or removed from the platform."
)
log(f"{len(errorcount)} video(s) failed to download.")
return
return

View File

@@ -1,7 +1,8 @@
import os
import random
from log import logtofile as log
import requests
from log import logtofile as log
def listas():
@@ -38,6 +39,7 @@ def removevideo():
if os.path.exists(os.getcwd() + "/video/video"):
os.remove(os.getcwd() + "/video/video")
# Broken as of 2023-02-03
# A workaround has been put in place
def detect_dead_link(url):

View File

@@ -1,7 +1,9 @@
import sys
from os import system
from log import logtofile as log
def init():
# Intro for the user
system("cls || clear")
@@ -39,6 +41,7 @@ def init():
# If the user does not have internet access, warns him the software won't work properly and quit.
try:
import requests
log("Started update / networking test")
data = requests.get(
"https://raw.githubusercontent.com/nanometer5088/CLI-TikTok/main/VERSION"
@@ -46,7 +49,9 @@ def init():
version = open("VERSION", "r", encoding="utf=8")
userversion = version.readline().rstrip()
if userversion < (data.text):
log(f"New version detected! User version is {userversion}, but {data.text} was found on Github.")
log(
f"New version detected! User version is {userversion}, but {data.text} was found on Github."
)
system("cls || clear")
log("User was prompted to update")
input(
@@ -65,10 +70,10 @@ def init():
log("The user has internet acess and the software is up-to-date.")
version.close()
except requests.exceptions.ConnectionError:
log("A connection error was detected when trying to connect to https://raw.githubusercontent.com/ to check for updates.")
print(
"CLI-TikTok detected your device isn't connected to the internet"
log(
"A connection error was detected when trying to connect to https://raw.githubusercontent.com/ to check for updates."
)
print("CLI-TikTok detected your device isn't connected to the internet")
print(
"This software requires a reliable and uncensored internet connection to properly work"
)

View File

@@ -2,6 +2,7 @@ import glob
import os
import time
class Logging:
def __init__(self):
self.logFileOpened = False
@@ -19,10 +20,14 @@ class Logging:
filenames.append(0)
if self.logFileOpened:
with open(f"logs/log-{max(filenames)}.txt", "a") as logFile:
logFile.write(f"[{time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))}]"
f" {stringToLog.encode('ascii', 'replace').decode()}\n")
logFile.write(
f"[{time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))}]"
f" {stringToLog.encode('ascii', 'replace').decode()}\n"
)
else:
with open(f"logs/log-{max(filenames) + 1}.txt", "w") as logFile:
self.logFileOpened = True
logFile.write(f"[{time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))}]"
f" {stringToLog.encode('ascii', 'replace').decode()}\n")
logFile.write(
f"[{time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))}]"
f" {stringToLog.encode('ascii', 'replace').decode()}\n"
)

View File

@@ -1,10 +1,12 @@
import os
import subprocess
from log import logtofile as log
from src.functions import url_redirection
from yt_dlp import YoutubeDL
from yt_dlp.utils import DownloadError
from log import logtofile as log
from src.functions import url_redirection
def getVideoInfo(url):
ydl_opts = {"quiet": True, "simulate": True, "forceurl": False}
@@ -19,8 +21,9 @@ def mpv(url):
def playbackrandom(urls, datas):
while True:
from src.functions import randomvideo
os.system("cls || clear")
randomvideo = randomvideo(urls)
url = url_redirection(urls[randomvideo])
@@ -30,9 +33,12 @@ def playbackrandom(urls, datas):
mpv(link)
log(f"Video {url} was reproduced")
except DownloadError:
log(f"Video {url} could not be played, it might have been banned or taken down")
log(
f"Video {url} could not be played, it might have been banned or taken down"
)
print("Video could not be played, it might have been banned or taken down.")
def playback(urls, datas):
index = 0
while True:
@@ -47,8 +53,12 @@ def playback(urls, datas):
mpv(link)
log(f"Video {url} was reproduced")
except DownloadError:
log(f"Video {url} could not be played, it might have been banned or taken down")
print("Video could not be played, it might have been banned or taken down.")
log(
f"Video {url} could not be played, it might have been banned or taken down"
)
print(
"Video could not be played, it might have been banned or taken down."
)
except IndexError:
log("All tiktoks were played")
print("All tiktoks were played.")

View File

@@ -1,24 +1,34 @@
import sys
from log import logtofile as log
import atoma
import requests
from log import logtofile as log
def getInfoTrending():
response = requests.get("https://tik.hostux.net/trending/rss")
if response.status_code == 404:
log(f"https://tik.hostux.net/trending/rss returned a 404 error. This is likely a server-side issue")
print("""Something went wrong while getting the trending information.
This is likely an issue with your internet connection or with the API.""")
log(
f"https://tik.hostux.net/trending/rss returned a 404 error. This is likely a server-side issue"
)
print(
"""Something went wrong while getting the trending information.
This is likely an issue with your internet connection or with the API."""
)
sys.exit()
if str(response.content) == "b''":
print("Something went wrong while parsing the trending information. If it persists, report this issue on Discord or Github.")
log("https://tik.hostux.net/trending/rss returned an empty response. This is likely a server-side issue")
print(
"Something went wrong while parsing the trending information. If it persists, report this issue on Discord or Github."
)
log(
"https://tik.hostux.net/trending/rss returned an empty response. This is likely a server-side issue"
)
sys.exit()
return atoma.parse_rss_bytes(response.content)
def getLinksTrending():
feed = getInfoTrending()
linklist = []
@@ -32,9 +42,12 @@ def streamtrending():
links = getLinksTrending()
if len(links) == 0:
print("Something went wrong while parsing the trending information. If it persists, report this issue on Discord or Github.")
print(
"Something went wrong while parsing the trending information. If it persists, report this issue on Discord or Github."
)
log("The link list is empty. This is likely a server-side issue")
from src.streaming import mpv
from src.streaming import mpv
for i in range(len(links)):
mpv(links[i])