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

Repair tests (without recomputing most of the cassettes) #1074

Merged
merged 1 commit into from
May 14, 2024
Merged
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
2 changes: 2 additions & 0 deletions subliminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def list_subtitles_provider(self, provider, video, languages):
except Exception as e:
handle_exception(e, 'Provider {}'.format(provider))

return []

def list_subtitles(self, video, languages):
"""List subtitles.

Expand Down
12 changes: 9 additions & 3 deletions subliminal/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def __init__(self, language, hearing_impaired=False, page_link=None, encoding=No
@property
def id(self):
"""Unique identifier of the subtitle"""
raise NotImplementedError
return ""

@property
def info(self):
"""Info of the subtitle, human readable. Usually the subtitle name for GUI rendering"""
raise NotImplementedError
return ""

@property
def text(self):
Expand Down Expand Up @@ -94,12 +94,18 @@ def is_valid(self):
return False

try:
srt.parse(self.text)
self.parsed()
except srt.SRTParseError:
return False

return True

def parsed(self):
"""Text content parsed to a valid subtitle.

"""
return srt.compose(srt.parse(self.text))

def guess_encoding(self):
"""Guess encoding using the language, falling back on chardet.

Expand Down
6 changes: 3 additions & 3 deletions subliminal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import socket
import struct
from datetime import datetime
from datetime import datetime, timezone

import requests
from requests.exceptions import SSLError
Expand Down Expand Up @@ -154,14 +154,14 @@ def sanitize_release_group(string):


def timestamp(date):
"""Get the timestamp of the `date`, python2/3 compatible
"""Get the timestamp of the `date` (with timezone).

:param datetime.datetime date: the utc date.
:return: the timestamp of the date.
:rtype: float

"""
return (date - datetime(1970, 1, 1)).total_seconds()
return (date - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()


def matches_title(actual, title, alternative_titles):
Expand Down
Loading