Skip to content

Commit

Permalink
update to version 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
natumbri committed Dec 22, 2020
1 parent 0412232 commit 6e146e1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
*********

v3.2 (2020-12-22)
========================================

- release to fix breaking changes and other minor bugs

v3.1 (2020-07-24)
========================================

Expand Down
48 changes: 32 additions & 16 deletions mopidy_youtube/apis/youtube_bs4api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class bs4API(scrAPI):

ytdata_regex = (
r'window\["ytInitialData"] = ({.*?});',
r'ytInitialData = ({.*});'
r"ytInitialData = ({.*});",
)

@classmethod
Expand All @@ -37,7 +37,6 @@ def _find_yt_data(cls, text):
logger.error("No data found on page")
raise Exception("No data found on page")


@classmethod
def run_search(cls, query):

Expand Down Expand Up @@ -76,14 +75,16 @@ def run_search(cls, query):
logger.info("nothing in the soup, trying japi")

yt_data = cls._find_yt_data(result.text)
extracted_json = yt_data["contents"]\
["twoColumnSearchResultsRenderer"]["primaryContents"]\
["sectionListRenderer"]["contents"][0]\
["itemSectionRenderer"]["contents"]
extracted_json = yt_data["contents"][
"twoColumnSearchResultsRenderer"
]["primaryContents"]["sectionListRenderer"]["contents"][0][
"itemSectionRenderer"
][
"contents"
]

return jAPI.json_to_items(cls, extracted_json)


@classmethod
def soup_to_items(cls, results):
items = []
Expand Down Expand Up @@ -237,11 +238,23 @@ def list_playlistitems(cls, id, page, max_results):
)

yt_data = cls._find_yt_data(result.text)
extracted_json = yt_data["contents"]\
["twoColumnBrowseResultsRenderer"]["tabs"][0]\
["tabRenderer"]["content"]["sectionListRenderer"]\
["contents"][0]["itemSectionRenderer"]["contents"]\
[0]["playlistVideoListRenderer"]["contents"]
extracted_json = yt_data["contents"][
"twoColumnBrowseResultsRenderer"
]["tabs"][0]["tabRenderer"]["content"]["sectionListRenderer"][
"contents"
][
0
][
"itemSectionRenderer"
][
"contents"
][
0
][
"playlistVideoListRenderer"
][
"contents"
]

items = jAPI.json_to_items(cls, extracted_json)
else:
Expand All @@ -265,7 +278,8 @@ def plsoup_to_items(cls, videos):
"duration": "PT"
+ cls.format_duration(
re.match(
cls.time_regex, video.find(class_="timestamp").text,
cls.time_regex,
video.find(class_="timestamp").text,
)
),
},
Expand Down Expand Up @@ -372,9 +386,11 @@ def list_related_videos(cls, video_id):
logger.info("nothing in the soup, trying japi related videos")

yt_data = cls._find_yt_data(result.text)
extracted_json = yt_data["contents"]\
["twoColumnWatchNextResults"]["secondaryResults"]\
["secondaryResults"]["results"] # noqa: E501
extracted_json = yt_data["contents"][
"twoColumnWatchNextResults"
]["secondaryResults"]["secondaryResults"][
"results"
] # noqa: E501

items = jAPI.json_to_items(cls, extracted_json)

Expand Down
4 changes: 3 additions & 1 deletion mopidy_youtube/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def lookup(self, uri):
comment=video.id,
length=video.length.get() * 1000,
artists=[Artist(name=video.channel.get())],
album=Album(name="YouTube Video",),
album=Album(
name="YouTube Video",
),
uri="youtube:video/%s.%s"
% (safe_url(video.title.get()), video.id),
)
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = Mopidy-YouTube
version = 3.1
version = 3.2
url = https://github.com/natumbri/mopidy-youtube
author = nik tumbri
author_email = [email protected]
Expand All @@ -27,11 +27,11 @@ python_requires = >= 3.7
install_requires =
beautifulsoup4
cachetools
Mopidy >= 3.0
Mopidy >= 3.1
Pykka >= 2.0.1
requests
setuptools
youtube_dl >= 2020.5.3
youtube_dl >= 2020.12.22

[options.extras_require]
lint =
Expand Down

0 comments on commit 6e146e1

Please sign in to comment.