Skip to content

Commit

Permalink
feat: pass video_id into text.py to do advanced filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoOwO committed Apr 19, 2021
1 parent 0de93ab commit 2d760d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions getjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ def get_image(url):

return f"data:image/jpeg;base64,{b64}"

def get_json(video_url, file=None):
video_id = get_youtube_id(video_url)

def build_req(video_id):
video_url = f"https://www.youtube.com/watch?v={video_id}"
info_req = urllib.request.Request(
video_url,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36',
}
)
with utils.urlopen(info_req) as response:
return utils.urlopen(info_req)

def get_json(video_url, file=None):
video_id = get_youtube_id(video_url)

with build_req(video_id) as response:
data = response.read().decode()

match = re.findall(r'"itag":(\d+),"url":"([^"]+)"', data)
Expand Down
2 changes: 1 addition & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def clear_chat():
else:
utils.warn(f" Chat file for {video_id} not found. This shouldn't happen, maybe someone stealed it...?")

message = text.get_private_check_text(status).format(video_id=video_id, channel_name=channel_name, channel_id=channel_id)
message = text.get_private_check_text(status, video_id).format(video_id=video_id, channel_name=channel_name, channel_id=channel_id)

utils.notify(message, files)
fetched[channel_name][video_id]["skipPrivateCheck"] = True
Expand Down
8 changes: 7 additions & 1 deletion text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import utils

def get_private_check_text(status):
def get_private_check_text(status, video_id=None):
# import getjson
# with utils.build_req(video_id) as res:
# html = res.read().decode()
# info = get_youtube_video_info(html)
# # Do some if-else using info object

if status is utils.PlayabilityStatus.PRIVATED:
return "[{video_id}](https://youtu.be/{video_id}) is privated on [{channel_name}](https://www.youtube.com/channel/{channel_id})."
elif status is utils.PlayabilityStatus.REMOVED:
Expand Down

0 comments on commit 2d760d4

Please sign in to comment.