From e387d54b1d370050515e108bea8c7a4c6acbf26d Mon Sep 17 00:00:00 2001 From: nanometer5088 Date: Sat, 4 Feb 2023 02:08:51 -0300 Subject: [PATCH] PEP8 Compliance * Version bump * 30 -> 24 videos are now able to be retrieved... --- VERSION | 2 +- log.py | 3 ++- main.py | 6 +++--- src/byuser.py | 18 +++++++++++++----- src/downloader.py | 20 ++++++++++++-------- src/functions.py | 4 +++- src/init.py | 13 +++++++++---- src/logs.py | 13 +++++++++---- src/streaming.py | 22 ++++++++++++++++------ src/trending.py | 29 +++++++++++++++++++++-------- 10 files changed, 89 insertions(+), 41 deletions(-) diff --git a/VERSION b/VERSION index e6adf3f..5176aab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4 \ No newline at end of file +0.41 \ No newline at end of file diff --git a/log.py b/log.py index 0f5799b..01172a3 100644 --- a/log.py +++ b/log.py @@ -1,2 +1,3 @@ from src.logs import Logging -logtofile = Logging().log \ No newline at end of file + +logtofile = Logging().log diff --git a/main.py b/main.py index 08c9ac8..c9f85d7 100644 --- a/main.py +++ b/main.py @@ -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." diff --git a/src/byuser.py b/src/byuser.py index 1db9c01..9151fc8 100644 --- a/src/byuser.py +++ b/src/byuser.py @@ -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) diff --git a/src/downloader.py b/src/downloader.py index 638d4d4..335533d 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -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 \ No newline at end of file + return diff --git a/src/functions.py b/src/functions.py index 57f5d20..7980b51 100644 --- a/src/functions.py +++ b/src/functions.py @@ -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): diff --git a/src/init.py b/src/init.py index e72aaa2..9ba7b8e 100644 --- a/src/init.py +++ b/src/init.py @@ -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" ) diff --git a/src/logs.py b/src/logs.py index 19fd473..635e023 100644 --- a/src/logs.py +++ b/src/logs.py @@ -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") \ No newline at end of file + logFile.write( + f"[{time.strftime('%Y.%m.%d-%H.%M.%S', time.localtime(time.time()))}]" + f" {stringToLog.encode('ascii', 'replace').decode()}\n" + ) diff --git a/src/streaming.py b/src/streaming.py index b854e0c..37f65c3 100644 --- a/src/streaming.py +++ b/src/streaming.py @@ -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.") diff --git a/src/trending.py b/src/trending.py index 8ca65cf..321c479 100644 --- a/src/trending.py +++ b/src/trending.py @@ -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])