Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved how seasons and episodes appear in titles for ert extractor. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions extractors/ertflix_extractor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests
import re
from bs4 import BeautifulSoup
import json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pr, I will add it, just fix this. The json module is needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks, I will. KR


from utils.extractor_utils import pad_season_or_episode


class ErtflixExtractor:
Expand Down Expand Up @@ -62,7 +63,15 @@ def select_episode(self):
selection = int(input("\nΔιαλέξτε Επεισόδιο | Select Episode\n"))
selected_episode = episode_list[selection]
episode_name = re.sub(":|\/|\||\"", "-", selected_episode["subtitle"])
self.title = "{} s{}e{} - {}".format(self.title, selected_episode["seasonNumber"], selected_episode["episodeNumber"], episode_name)

# Pad season and episode number
selected_episode['seasonNumber'] = pad_season_or_episode(
selected_episode['seasonNumber'])
selected_episode['episodeNumber'] = pad_season_or_episode(
selected_episode['episodeNumber'])

self.title = f"{self.title} s{selected_episode['seasonNumber']}e" \
f"{selected_episode['episodeNumber']} - {episode_name}"
return selected_episode["codename"]

def obtain_index(self):
Expand Down
15 changes: 15 additions & 0 deletions utils/extractor_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def pad_season_or_episode(number):
"""
If the number is not provided, assume it is the first
(especially for season).
Otherwise, left-pad the season/episode number with zero. So, season "2"
will become "02". Also, episode "5" will become "05", while episode
"15" or "127" will remain as is.

:param number: the number representing the season or the episode
:return: padded number
"""
if not str(number).strip():
return '01'
else:
return str(number).zfill(2)