Skip to content

Commit

Permalink
Changed twitch-python imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetterKraabol committed May 23, 2019
1 parent 75bc1a8 commit d28abb4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/PetterKraabol/Twitch-Chat-Downloader',
version='3.0.7',
version='3.0.8',
zip_safe=True,
)
2 changes: 1 addition & 1 deletion tcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .settings import Settings

__name__: str = 'tcd'
__version__: str = '3.0.7'
__version__: str = '3.0.8'
__all__: List[Callable] = [Arguments, Settings, Downloader, Logger, Log]


Expand Down
7 changes: 4 additions & 3 deletions tcd/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from typing import List

import dateutil
import twitch
from twitch import Helix
from twitch.helix import Video

from .arguments import Arguments
from .formatter import Formatter
Expand All @@ -18,7 +19,7 @@
class Downloader:

def __init__(self):
self.helix_api = twitch.Helix(client_id=Settings().config['client_id'], use_cache=True)
self.helix_api = Helix(client_id=Settings().config['client_id'], use_cache=True)

self.formats: List[str] = []
self.whitelist: List[str] = []
Expand Down Expand Up @@ -64,7 +65,7 @@ def _can_use_format(self, format_name: str) -> bool:

return True

def video(self, video: twitch.helix.Video) -> None:
def video(self, video: Video) -> None:
"""
Download chat from video
:param video: Video object
Expand Down
9 changes: 5 additions & 4 deletions tcd/formats/custom.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from typing import Generator, Tuple

import twitch
from twitch.helix import Video
from twitch.v5 import Comments, Comment

from tcd.formats.format import Format
from tcd.pipe import Pipe


class Custom(Format):

def __init__(self, video: twitch.helix.Video, format_name: str):
def __init__(self, video: Video, format_name: str):
super().__init__(video, format_name)

def use(self) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str]:
def use(self) -> Tuple[Generator[Tuple[str, Comment], None, None], str]:
"""
Use this format
:return: tuple(formatted comment, comment), output format
Expand All @@ -24,6 +25,6 @@ def use(self) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str

return comments, output

def comment_generator(self, comments: twitch.v5.Comments) -> Generator[Tuple[str, twitch.v5.Comment], None, None]:
def comment_generator(self, comments: Comments) -> Generator[Tuple[str, Comment], None, None]:
for comment in comments:
yield Pipe(self.format_dictionary['comments']).comment(comment.data), comment
6 changes: 3 additions & 3 deletions tcd/formats/format.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import twitch
from twitch.helix import Video

from tcd.settings import Settings


class Format:

def __init__(self, video: twitch.helix.Video, format_name: str):
self.video: twitch.helix.Video = video
def __init__(self, video: Video, format_name: str):
self.video: Video = video
self.format_name: str = format_name
self.format_dictionary: dict = Settings().config['formats'][format_name]
9 changes: 5 additions & 4 deletions tcd/formats/srt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
from typing import Tuple, Generator

import twitch
from twitch.helix import Video
from twitch.v5 import Comment, Comments

from tcd.formats.format import Format
from tcd.pipe import Pipe
Expand All @@ -10,14 +11,14 @@

class SRT(Format):

def __init__(self, video: twitch.helix.Video):
def __init__(self, video: Video):
"""
Initialize SRT format
:param video: Video object
"""
super().__init__(video, format_name='srt')

def use(self) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str]:
def use(self) -> Tuple[Generator[Tuple[str, Comment], None, None], str]:
"""
Use SRT format
:return: Comment generator and output string
Expand All @@ -44,7 +45,7 @@ def format_timestamp(time: datetime.timedelta) -> str:

return f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d},{milliseconds:03d}'

def subtitles(self, comments: twitch.v5.Comments) -> Generator[Tuple[str, twitch.v5.Comment], None, None]:
def subtitles(self, comments: Comments) -> Generator[Tuple[str, Comment], None, None]:
"""
Subtitle generator
:param comments: Comments to turn into subtitles
Expand Down
11 changes: 6 additions & 5 deletions tcd/formats/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from itertools import chain
from typing import Tuple, Generator, List, Optional

import twitch
from twitch.helix import Video
from twitch.v5 import Comment, Comments

from tcd.formats.format import Format
from tcd.pipe import Pipe
Expand All @@ -14,10 +15,10 @@ class SSA(Format):
CLOSE: str = '[SSA_CLOSE]'
SPECIAL: str = '♣'

def __init__(self, video: twitch.helix.Video):
def __init__(self, video: Video):
super().__init__(video, format_name='ssa')

def use(self) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str]:
def use(self) -> Tuple[Generator[Tuple[str, Comment], None, None], str]:
"""
Use SSA format
:return:
Expand All @@ -26,7 +27,7 @@ def use(self) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str

return self.generator(), output

def generator(self) -> Generator[Tuple[str, Optional[twitch.v5.Comment]], None, None]:
def generator(self) -> Generator[Tuple[str, Optional[Comment]], None, None]:
"""
Line generator
:return:
Expand Down Expand Up @@ -54,7 +55,7 @@ def format_timestamp(time: datetime.timedelta) -> str:

return f'{int(hours):01d}:{int(minutes):02d}:{int(seconds):02d}.{centiseconds:02d}'

def dialogues(self, comments: twitch.v5.Comments) -> Generator[Tuple[str, twitch.v5.Comments], None, None]:
def dialogues(self, comments: Comments) -> Generator[Tuple[str, Comments], None, None]:
"""
Format comments as SSA dialogues
:param comments: Comment to format
Expand Down
9 changes: 5 additions & 4 deletions tcd/formatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Generator, Tuple

import twitch
from twitch.helix import Video
from twitch.v5 import Comment

from .formats.custom import Custom
from .formats.srt import SRT
Expand All @@ -10,10 +11,10 @@

class Formatter:

def __init__(self, video: twitch.helix.Video):
self.video: twitch.helix.Video = video
def __init__(self, video: Video):
self.video: Video = video

def use(self, format_name: str) -> Tuple[Generator[Tuple[str, twitch.v5.Comment], None, None], str]:
def use(self, format_name: str) -> Tuple[Generator[Tuple[str, Comment], None, None], str]:
"""
Use format
:param format_name:
Expand Down

0 comments on commit d28abb4

Please sign in to comment.