Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Honeypot
mopidy-youtube
Commits
3d9aa6bd
Commit
3d9aa6bd
authored
Jan 19, 2016
by
Stein Magnus Jodal
Browse files
Release v2.0.2
parents
c566175f
830d757e
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
3d9aa6bd
*.egg-info
*.pyc
MANIFEST
.tox
*.swp
/_projects
.cache/
.coverage
.tox/
MANIFEST
build/
.idea/
dist/
xunit-*.xml
*.egg-info
/_builds
.coverage
/_steps
\ No newline at end of file
.mailmap
View file @
3d9aa6bd
Janez Troha <dz0ny@ubuntu.si>
Janez Troha <dz0ny@ubuntu.si> <dz0ny@users.noreply.github.com>
John Cass <john.cass77@gmail.com>
README.rst
View file @
3d9aa6bd
...
...
@@ -72,12 +72,19 @@ Project resources
- `Source code <https://github.com/mopidy/mopidy-youtube>`_
- `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
=========
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)
-------------------
...
...
mopidy_youtube/__init__.py
View file @
3d9aa6bd
...
...
@@ -6,7 +6,7 @@ import os
from
mopidy
import
config
,
ext
__version__
=
'2.0.
1
'
__version__
=
'2.0.
2
'
logger
=
logging
.
getLogger
(
__name__
)
...
...
mopidy_youtube/backend.py
View file @
3d9aa6bd
...
...
@@ -23,6 +23,9 @@ yt_api_endpoint = 'https://www.googleapis.com/youtube/v3/'
yt_key
=
'AIzaSyAl1Xq9DwdE_KD4AtPaE4EJl3WZe2zCqg4'
session
=
requests
.
Session
()
video_uri_prefix
=
'youtube:video'
search_uri
=
'youtube:search'
def
resolve_track
(
track
,
stream
=
False
):
logger
.
debug
(
"Resolving YouTube for track '%s'"
,
track
)
...
...
@@ -49,9 +52,8 @@ def resolve_url(url, stream=False):
try
:
video
=
pafy
.
new
(
url
)
if
not
stream
:
uri
=
'youtube:video/%s.%s'
%
(
safe_url
(
video
.
title
),
video
.
videoid
)
uri
=
'%s/%s.%s'
%
(
video_uri_prefix
,
safe_url
(
video
.
title
),
video
.
videoid
)
else
:
uri
=
video
.
getbestaudio
()
if
not
uri
:
# get video url
...
...
@@ -66,13 +68,19 @@ def resolve_url(url, stream=False):
logger
.
info
(
e
.
message
)
return
images
=
[]
if
video
.
bigthumb
is
not
None
:
images
.
append
(
video
.
bigthumb
)
if
video
.
bigthumbhd
is
not
None
:
images
.
append
(
video
.
bigthumbhd
)
track
=
Track
(
name
=
video
.
title
,
comment
=
video
.
videoid
,
length
=
video
.
length
*
1000
,
album
=
Album
(
name
=
'YouTube'
,
images
=
[
video
.
bigthumb
,
video
.
bigthumbhd
]
images
=
images
),
uri
=
uri
)
...
...
@@ -151,7 +159,7 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
else
:
return
[
item
for
item
in
[
resolve_url
(
track
)]
if
item
]
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
):
# TODO Support exact search
...
...
@@ -166,21 +174,21 @@ class YouTubeLibraryProvider(backend.LibraryProvider):
req
=
parse_qs
(
url
.
query
)
if
'list'
in
req
:
return
SearchResult
(
uri
=
'youtube:
search
'
,
uri
=
search
_uri
,
tracks
=
resolve_playlist
(
req
.
get
(
'list'
)[
0
])
)
else
:
logger
.
info
(
"Resolving YouTube for track '%s'"
,
search_query
)
return
SearchResult
(
uri
=
'youtube:
search
'
,
uri
=
search
_uri
,
tracks
=
[
t
for
t
in
[
resolve_url
(
search_query
)]
if
t
]
)
else
:
search_query
=
' '
.
join
(
query
.
values
()[
0
])
logger
.
info
(
"Searching YouTube for query '%s'"
,
search_query
)
return
SearchResult
(
uri
=
'youtube:
search
'
,
uri
=
search
_uri
,
tracks
=
search_youtube
(
search_query
)
)
...
...
tests/fixtures/lookup_video_uri.yaml
0 → 100644
View file @
3d9aa6bd
This diff is collapsed.
Click to expand it.
tests/test_backend.py
View file @
3d9aa6bd
...
...
@@ -9,6 +9,7 @@ import pytest
import
vcr
from
mopidy_youtube
import
backend
from
mopidy_youtube.backend
import
YouTubeLibraryProvider
@
pytest
.
yield_fixture
...
...
@@ -47,7 +48,7 @@ def test_search_yt(pafy_mock_with_video):
@
vcr
.
use_cassette
(
'tests/fixtures/resolve_track.yaml'
)
def
test_resolve_track
(
pafy_mock_with_video
):
video
=
backend
.
resolve_track
(
'
TU3b1qyEGsE
'
)
video
=
backend
.
resolve_track
(
'
C0DPdy98e4c
'
)
assert
video
...
...
@@ -63,6 +64,31 @@ def test_resolve_track_failed(pafy_mock):
@
vcr
.
use_cassette
(
'tests/fixtures/resolve_track_stream.yaml'
)
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
@
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'
tox.ini
View file @
3d9aa6bd
...
...
@@ -6,13 +6,12 @@ sitepackages = true
# vcrpy tries to patch tornado, so if it is present, it must be recent.
deps
=
mock
mopidy
=
=dev
pytest
pytest-cov
pytest-capturelog
pytest-xdist
tornado
>=
4
vcrpy
install_command
=
pip install --allow-unverified=mopidy --pre {opts} {packages}
commands
=
py.test
\
--basetemp
=
{envtmpdir}
\
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment