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

Ruff cleanup #337

Merged
merged 8 commits into from
Nov 20, 2023
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
11 changes: 11 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Ruff
run-name: Ruff

on: [ push, pull_request ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
1 change: 0 additions & 1 deletion m3u8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# license that can be found in the LICENSE file.

import os
import sys
from urllib.parse import urljoin, urlsplit

from m3u8.httpclient import DefaultHTTPClient
Expand Down
76 changes: 0 additions & 76 deletions m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Use of this source code is governed by a MIT License
# license that can be found in the LICENSE file.
import decimal
import errno
import os

from m3u8.mixins import BasePathMixin, GroupedBasePathMixin
Expand Down Expand Up @@ -1609,81 +1608,6 @@ def dumps(self):
def __str__(self):
return self.dumps()

class ImagePlaylist(BasePathMixin):
'''
ImagePlaylist object representing a link to a
variant M3U8 image playlist with a specific bitrate.

Attributes:

`image_stream_info` is a named tuple containing the attributes:
`bandwidth`, `resolution` which is a tuple (w, h) of integers and `codecs`,

More info: https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf
'''

def __init__(self, base_uri, uri, image_stream_info):
self.uri = uri
self.base_uri = base_uri

resolution = image_stream_info.get('resolution')
if resolution is not None:
values = resolution.split('x')
resolution_pair = (int(values[0]), int(values[1]))
else:
resolution_pair = None

self.image_stream_info = StreamInfo(
bandwidth=image_stream_info.get('bandwidth'),
average_bandwidth=image_stream_info.get('average_bandwidth'),
video=image_stream_info.get('video'),
# Audio, subtitles, closed captions, video range and hdcp level should not exist in
# EXT-X-IMAGE-STREAM-INF, so just hardcode them to None.
audio=None,
subtitles=None,
closed_captions=None,
program_id=image_stream_info.get('program_id'),
resolution=resolution_pair,
codecs=image_stream_info.get('codecs'),
video_range=None,
hdcp_level=None,
frame_rate=None,
pathway_id=image_stream_info.get('pathway_id'),
stable_variant_id=image_stream_info.get('stable_variant_id')
)

def __str__(self):
image_stream_inf = []
if self.image_stream_info.program_id:
image_stream_inf.append('PROGRAM-ID=%d' %
self.image_stream_info.program_id)
if self.image_stream_info.bandwidth:
image_stream_inf.append('BANDWIDTH=%d' %
self.image_stream_info.bandwidth)
if self.image_stream_info.average_bandwidth:
image_stream_inf.append('AVERAGE-BANDWIDTH=%d' %
self.image_stream_info.average_bandwidth)
if self.image_stream_info.resolution:
res = (str(self.image_stream_info.resolution[0]) + 'x' +
str(self.image_stream_info.resolution[1]))
image_stream_inf.append('RESOLUTION=' + res)
if self.image_stream_info.codecs:
image_stream_inf.append('CODECS=' +
quoted(self.image_stream_info.codecs))
if self.uri:
image_stream_inf.append('URI=' + quoted(self.uri))
if self.image_stream_info.pathway_id:
image_stream_inf.append(
'PATHWAY-ID=' + quoted(self.image_stream_info.pathway_id)
)
if self.image_stream_info.stable_variant_id:
image_stream_inf.append(
'STABLE-VARIANT-ID=' + quoted(self.image_stream_info.stable_variant_id)
)

return '#EXT-X-IMAGE-STREAM-INF:' + ','.join(image_stream_inf)


def find_key(keydata, keylist):
if not keydata:
return None
Expand Down
1 change: 0 additions & 1 deletion m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import itertools
import re
from datetime import datetime, timedelta
from urllib.parse import urljoin as _urljoin

try:
from backports.datetime_fromisoformat import MonkeyPatch
Expand Down
6 changes: 3 additions & 3 deletions tests/m3u8server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@route("/path/to/redirect_me")
def simple():
def redirect_route():
redirect("/simple.m3u8")


Expand All @@ -25,14 +25,14 @@ def simple():


@route("/timeout_simple.m3u8")
def simple():
def timeout_simple():
time.sleep(5)
response.set_header("Content-Type", "application/vnd.apple.mpegurl")
return m3u8_file("simple-playlist.m3u8")


@route("/path/to/relative-playlist.m3u8")
def simple():
def relative_playlist():
response.set_header("Content-Type", "application/vnd.apple.mpegurl")
return m3u8_file("relative-playlist.m3u8")

Expand Down
5 changes: 3 additions & 2 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# license that can be found in the LICENSE file.

import os
import socket
import urllib.parse
import m3u8
import pytest
Expand Down Expand Up @@ -140,8 +141,8 @@ def test_presence_of_base_uri_if_provided_when_loading_from_string():

def test_raise_timeout_exception_if_timeout_happens_when_loading_from_uri():
try:
obj = m3u8.load(playlists.TIMEOUT_SIMPLE_PLAYLIST_URI, timeout=1)
except:
m3u8.load(playlists.TIMEOUT_SIMPLE_PLAYLIST_URI, timeout=1)
except socket.timeout:
assert True
else:
assert False
Loading