Commit 3d9aa6bd authored by Stein Magnus Jodal's avatar Stein Magnus Jodal
Browse files

Release v2.0.2

parents c566175f 830d757e
*.egg-info
*.pyc *.pyc
MANIFEST
.tox
*.swp *.swp
/_projects .cache/
.coverage
.tox/
MANIFEST
build/ build/
.idea/
dist/ dist/
xunit-*.xml xunit-*.xml
*.egg-info
/_builds
.coverage
/_steps
\ No newline at end of file
Janez Troha <dz0ny@ubuntu.si> Janez Troha <dz0ny@ubuntu.si>
Janez Troha <dz0ny@ubuntu.si> <dz0ny@users.noreply.github.com> Janez Troha <dz0ny@ubuntu.si> <dz0ny@users.noreply.github.com>
John Cass <john.cass77@gmail.com>
...@@ -72,12 +72,19 @@ Project resources ...@@ -72,12 +72,19 @@ Project resources
- `Source code <https://github.com/mopidy/mopidy-youtube>`_ - `Source code <https://github.com/mopidy/mopidy-youtube>`_
- `Issue tracker <https://github.com/mopidy/mopidy-youtube/issues>`_ - `Issue tracker <https://github.com/mopidy/mopidy-youtube/issues>`_
- `Download development snapshot <https://github.com/mopidy/mopidy-youtube/archive/develop.tar.gz#egg=Mopidy-Youtube-dev>`_
Changelog Changelog
========= =========
v2.0.2 (2016-01-19)
-------------------
- Fix resolving of ``youtube:video`` URIs when looking up tracks. (Fixes: #21,
PR: #50)
- Ensure ``None`` doesn't get includes in track image lists. (PR: #48)
v2.0.1 (2015-08-19) v2.0.1 (2015-08-19)
------------------- -------------------
......
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
from mopidy import config, ext from mopidy import config, ext
__version__ = '2.0.1' __version__ = '2.0.2'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -23,6 +23,9 @@ yt_api_endpoint = 'https://www.googleapis.com/youtube/v3/' ...@@ -23,6 +23,9 @@ yt_api_endpoint = 'https://www.googleapis.com/youtube/v3/'
yt_key = 'AIzaSyAl1Xq9DwdE_KD4AtPaE4EJl3WZe2zCqg4' yt_key = 'AIzaSyAl1Xq9DwdE_KD4AtPaE4EJl3WZe2zCqg4'
session = requests.Session() session = requests.Session()
video_uri_prefix = 'youtube:video'
search_uri = 'youtube:search'
def resolve_track(track, stream=False): def resolve_track(track, stream=False):
logger.debug("Resolving YouTube for track '%s'", track) logger.debug("Resolving YouTube for track '%s'", track)
...@@ -49,9 +52,8 @@ def resolve_url(url, stream=False): ...@@ -49,9 +52,8 @@ def resolve_url(url, stream=False):
try: try:
video = pafy.new(url) video = pafy.new(url)
if not stream: if not stream:
uri = 'youtube:video/%s.%s' % ( uri = '%s/%s.%s' % (
safe_url(video.title), video.videoid video_uri_prefix, safe_url(video.title), video.videoid)
)
else: else:
uri = video.getbestaudio() uri = video.getbestaudio()
if not uri: # get video url if not uri: # get video url
...@@ -66,13 +68,19 @@ def resolve_url(url, stream=False): ...@@ -66,13 +68,19 @@ def resolve_url(url, stream=False):
logger.info(e.message) logger.info(e.message)
return return
images = []
if video.bigthumb is not None:
images.append(video.bigthumb)
if video.bigthumbhd is not None:
images.append(video.bigthumbhd)
track = Track( track = Track(
name=video.title, name=video.title,
comment=video.videoid, comment=video.videoid,
length=video.length * 1000, length=video.length * 1000,
album=Album( album=Album(
name='YouTube', name='YouTube',
images=[video.bigthumb, video.bigthumbhd] images=images
), ),
uri=uri uri=uri
) )
...@@ -151,7 +159,7 @@ class YouTubeLibraryProvider(backend.LibraryProvider): ...@@ -151,7 +159,7 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
else: else:
return [item for item in [resolve_url(track)] if item] return [item for item in [resolve_url(track)] if item]
else: else:
return [item for item in [resolve_url(track)] if item] return [item for item in [resolve_track(track)] if item]
def search(self, query=None, uris=None, exact=False): def search(self, query=None, uris=None, exact=False):
# TODO Support exact search # TODO Support exact search
...@@ -166,21 +174,21 @@ class YouTubeLibraryProvider(backend.LibraryProvider): ...@@ -166,21 +174,21 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
req = parse_qs(url.query) req = parse_qs(url.query)
if 'list' in req: if 'list' in req:
return SearchResult( return SearchResult(
uri='youtube:search', uri=search_uri,
tracks=resolve_playlist(req.get('list')[0]) tracks=resolve_playlist(req.get('list')[0])
) )
else: else:
logger.info( logger.info(
"Resolving YouTube for track '%s'", search_query) "Resolving YouTube for track '%s'", search_query)
return SearchResult( return SearchResult(
uri='youtube:search', uri=search_uri,
tracks=[t for t in [resolve_url(search_query)] if t] tracks=[t for t in [resolve_url(search_query)] if t]
) )
else: else:
search_query = ' '.join(query.values()[0]) search_query = ' '.join(query.values()[0])
logger.info("Searching YouTube for query '%s'", search_query) logger.info("Searching YouTube for query '%s'", search_query)
return SearchResult( return SearchResult(
uri='youtube:search', uri=search_uri,
tracks=search_youtube(search_query) tracks=search_youtube(search_query)
) )
......
This diff is collapsed.
...@@ -9,6 +9,7 @@ import pytest ...@@ -9,6 +9,7 @@ import pytest
import vcr import vcr
from mopidy_youtube import backend from mopidy_youtube import backend
from mopidy_youtube.backend import YouTubeLibraryProvider
@pytest.yield_fixture @pytest.yield_fixture
...@@ -47,7 +48,7 @@ def test_search_yt(pafy_mock_with_video): ...@@ -47,7 +48,7 @@ def test_search_yt(pafy_mock_with_video):
@vcr.use_cassette('tests/fixtures/resolve_track.yaml') @vcr.use_cassette('tests/fixtures/resolve_track.yaml')
def test_resolve_track(pafy_mock_with_video): def test_resolve_track(pafy_mock_with_video):
video = backend.resolve_track('TU3b1qyEGsE') video = backend.resolve_track('C0DPdy98e4c')
assert video assert video
...@@ -63,6 +64,31 @@ def test_resolve_track_failed(pafy_mock): ...@@ -63,6 +64,31 @@ def test_resolve_track_failed(pafy_mock):
@vcr.use_cassette('tests/fixtures/resolve_track_stream.yaml') @vcr.use_cassette('tests/fixtures/resolve_track_stream.yaml')
def test_resolve_track_stream(pafy_mock_with_video): def test_resolve_track_stream(pafy_mock_with_video):
video = backend.resolve_track('TU3b1qyEGsE', stream=True) video = backend.resolve_track('C0DPdy98e4c', stream=True)
assert video assert video
@vcr.use_cassette('tests/fixtures/resolve_video_track_stream.yaml')
def test_resolve_video_track_stream(pafy_mock_with_video):
video = backend.resolve_track('youtube:video/a title.a video id',
stream=True)
assert video
assert video.uri == "http://example.com/"
@vcr.use_cassette('tests/fixtures/lookup_video_uri.yaml')
def test_lookup_video_uri(caplog):
provider = YouTubeLibraryProvider(mock.PropertyMock())
track = provider.lookup(backend.video_uri_prefix +
'/a title.C0DPdy98e4c')
assert 'Need 11 character video id or the URL of the video.' \
not in caplog.text()
assert track
assert track[0].uri == backend.video_uri_prefix + \
'/TEST VIDEO.C0DPdy98e4c'
...@@ -6,13 +6,12 @@ sitepackages = true ...@@ -6,13 +6,12 @@ sitepackages = true
# vcrpy tries to patch tornado, so if it is present, it must be recent. # vcrpy tries to patch tornado, so if it is present, it must be recent.
deps = deps =
mock mock
mopidy==dev
pytest pytest
pytest-cov pytest-cov
pytest-capturelog
pytest-xdist pytest-xdist
tornado >= 4 tornado >= 4
vcrpy vcrpy
install_command = pip install --allow-unverified=mopidy --pre {opts} {packages}
commands = commands =
py.test \ py.test \
--basetemp={envtmpdir} \ --basetemp={envtmpdir} \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment