From c5124adbfb5544e6d54fb6309bd9a71d8ae11371 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 1 Feb 2021 15:24:46 +0100 Subject: [PATCH] Support station search results, update localization (#160) --- ytmusicapi/locales/README.rst | 2 +- ytmusicapi/locales/base.pot | 30 +++++++++-------- ytmusicapi/locales/de/LC_MESSAGES/base.mo | Bin 667 -> 698 bytes ytmusicapi/locales/de/LC_MESSAGES/base.po | 33 +++++++++--------- ytmusicapi/locales/en/LC_MESSAGES/base.mo | Bin 378 -> 378 bytes ytmusicapi/locales/en/LC_MESSAGES/base.po | 30 +++++++++-------- ytmusicapi/locales/es/LC_MESSAGES/base.mo | Bin 703 -> 735 bytes ytmusicapi/locales/es/LC_MESSAGES/base.po | 33 +++++++++--------- ytmusicapi/locales/fr/LC_MESSAGES/base.mo | Bin 668 -> 592 bytes ytmusicapi/locales/fr/LC_MESSAGES/base.po | 39 +++++++++++----------- ytmusicapi/locales/it/LC_MESSAGES/base.mo | Bin 663 -> 626 bytes ytmusicapi/locales/it/LC_MESSAGES/base.po | 37 ++++++++++---------- ytmusicapi/locales/ja/LC_MESSAGES/base.mo | Bin 706 -> 749 bytes ytmusicapi/locales/ja/LC_MESSAGES/base.po | 33 +++++++++--------- ytmusicapi/parsers/browsing.py | 34 +++++++++++-------- ytmusicapi/parsers/utils.py | 8 ++--- ytmusicapi/ytmusic.py | 11 +++--- 17 files changed, 152 insertions(+), 138 deletions(-) diff --git a/ytmusicapi/locales/README.rst b/ytmusicapi/locales/README.rst index 8afe2c9..11e423c 100644 --- a/ytmusicapi/locales/README.rst +++ b/ytmusicapi/locales/README.rst @@ -10,7 +10,7 @@ This package uses the Linux command line utility xgettext, which you can install Add new translatable texts from code ---------------------------------------- -``xgettext -d base -o locales/base.pot ytmusicapi/*.py`` +``xgettext -d base -o locales/base.pot *.py mixins/*.py parsers/*.py`` ``sed --in-place locales/base.pot --expression=s/CHARSET/UTF-8/`` diff --git a/ytmusicapi/locales/base.pot b/ytmusicapi/locales/base.pot index c1e1610..3fab18e 100644 --- a/ytmusicapi/locales/base.pot +++ b/ytmusicapi/locales/base.pot @@ -1,14 +1,14 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,34 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "" + +#: parsers/browsing.py:123 msgid "albums" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "" diff --git a/ytmusicapi/locales/de/LC_MESSAGES/base.mo b/ytmusicapi/locales/de/LC_MESSAGES/base.mo index 069bdec6da47dcfbd76131ae83b487685c759168..87f1c26f71917bc9334fbedc9481b59db87e99b4 100644 GIT binary patch delta 278 zcmbQux{I~`o)F7a1|Z-9Vi_RL0b*Vt-UGxS@BxU~fcPVn{sE*pfcQTUbAs563=Hf* zS_nw90BI>GUmi%a0{QAd8l+zrNIL+r2~@n439LVep&G~l8Q2ODVCVzVAOmLrX^;U6 zfHcT}Wl;WFD1S4M2ATy1ApIb`55B`40R2RbPWs@ i3{9+z4YdsnH`g)>GKv(Z=B1<-F_dMdq~=4&Vg>+z>mrl@ delta 247 zcmdnRI-9lro)F7a1|Z-BVi_P#0b*VtUIWA+@BoO}fcPPlegUL8fcQNSgY^6WVs;>A zVq{=o0n%JRniWX%18I;xQ6TLA#4=FvSSE, YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,37 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "künstler" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "playlist" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "titel" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "video" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "sender" + +#: parsers/browsing.py:123 msgid "albums" msgstr "alben" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "singles" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "videos" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "playlists" - -#~ msgid "album" -#~ msgstr "album" diff --git a/ytmusicapi/locales/en/LC_MESSAGES/base.mo b/ytmusicapi/locales/en/LC_MESSAGES/base.mo index 88b4778076c9488a784121dcc22a6aff9f8ed1d5..ff4f7f4ce552fd55c5ae300f3e16db54496ffa22 100644 GIT binary patch delta 26 hcmeyx^owaimw=(Jfsw9(p@N}_m9e3=f#Jki4*+mB2rB>p delta 26 hcmeyx^owaimwm7%G&fziZS4*+n+2si)$ diff --git a/ytmusicapi/locales/en/LC_MESSAGES/base.po b/ytmusicapi/locales/en/LC_MESSAGES/base.po index 675d204..f419e30 100644 --- a/ytmusicapi/locales/en/LC_MESSAGES/base.po +++ b/ytmusicapi/locales/en/LC_MESSAGES/base.po @@ -1,14 +1,14 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,34 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "" + +#: parsers/browsing.py:123 msgid "albums" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "" diff --git a/ytmusicapi/locales/es/LC_MESSAGES/base.mo b/ytmusicapi/locales/es/LC_MESSAGES/base.mo index 85b0a60eeebb1c4f6a22a7ef70f9b2860c96db8b..4fc1452553fe90207f319dcf934b1c9c9ae265ee 100644 GIT binary patch delta 281 zcmdnbdY`rao)F7a1|Z-9Vi_RL0b*Vt-UGxS@BxU~fcPVn{sE*pfcQTUbAs563=Hf* zS_nw90BI>GUmi%a0{QAd8l+zrNIL+r2@r$ymokC%1u@hC8Dc2k!#{jGxp+=#FEVXyvclw@dAdr q21dFDh6;uzR>p?f28Nq!8I2jmQ*$$m^NSK0$_}qhNzI2+#S8$hs3u$h delta 249 zcmcc5x}UZFo)F7a1|Z-BVi_P#0b*VtUIWA+@BoO}fcPPlegUL8fcQNSgY^6WVs;>A zVq{=o0n%JRniWX%18I;xQ6TLA#4, YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,37 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "artista" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "lista de reproducción" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "canción" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "vídeo" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "emisora" + +#: parsers/browsing.py:123 msgid "albums" msgstr "álbumes" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "sencillos" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "vídeos" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "listas de reproducción" - -#~ msgid "album" -#~ msgstr "álbum" diff --git a/ytmusicapi/locales/fr/LC_MESSAGES/base.mo b/ytmusicapi/locales/fr/LC_MESSAGES/base.mo index 8c81d583b47519fac6e2f70cd63f5c4b04a0c45b..b670a8dad9743061ff4c78bf732a184ea7f41065 100644 GIT binary patch delta 288 zcmbQkdV!_>o)F7a1|VPuVi_O~0b*_-?g3&D*a5_BK)e%(Ie_>85VHXBNgxL4IS0h7 zKzt2|LF(=Ru>&Im!($)~l2>7Z=+gnxAa$lt+8Rg$)rT=S0vRBM9zYtX4-7yGnW1cu zWgvMF04f0kkVOoMMJ1WVB@6{QiIq7ZMsa>#Izw?uVo7Fx-ef+;cmYFQ10!7nLj^+< pD`P`#1H;L+j1RTJno<$EN-|4|QW=U8Q!?`z$}&?9uY^&>3;;y9FB<>= delta 364 zcmZ9GO$z~06owDRXNi=Zg}u~_l32*X-;hQ#Y3llD?xn0|X=Neo`~l@(_yab!VrOS- z={?+#Q%}$RIOpvgjcqhI=Zp=ZlAr(_kOq6ebpbJO)xNVjz_Dp;aS*avRZ`c, YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,37 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "artiste" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "playlist" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "titre" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "vidéo" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "radio" + +#: parsers/browsing.py:123 msgid "albums" -msgstr "albums" +msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" -msgstr "singles" +msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "vidéos" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" -msgstr "playlists" - -#~ msgid "album" -#~ msgstr "album" +msgstr "" diff --git a/ytmusicapi/locales/it/LC_MESSAGES/base.mo b/ytmusicapi/locales/it/LC_MESSAGES/base.mo index 52564665670e743959a713385dd52863a549b1ab..f879c91c8cd1e0ffd6bd066b82a31565825c9a38 100644 GIT binary patch delta 284 zcmbQv`iZ6fo)F7a1|Z-7Vi_Qg0b*_-o&&@nZ~}!i`G5q_B1AfzhGTFR=3D{p zfRcLeX+i%0#+(gJf(!ZTV-53wt@2KJ4`W7H+{4Ao@B&eQmS6EAyc{n;marF7N!HwV zq)#(pt;GLQl)fbCxMMMbJ$Fn?XE^fquWrt$8O@qmFB`3Py-_vHLqGDagmKPz!XbNZ Jxn2-b=NFn!HPiqA diff --git a/ytmusicapi/locales/it/LC_MESSAGES/base.po b/ytmusicapi/locales/it/LC_MESSAGES/base.po index d6b3833..5b82b80 100644 --- a/ytmusicapi/locales/it/LC_MESSAGES/base.po +++ b/ytmusicapi/locales/it/LC_MESSAGES/base.po @@ -1,14 +1,14 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,37 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "artista" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" -msgstr "playlist" +msgstr "" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "brano" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" -msgstr "video" +msgstr "" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "stazione" + +#: parsers/browsing.py:123 msgid "albums" msgstr "album" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "singoli" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "video" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "playlist" - -#~ msgid "album" -#~ msgstr "album" diff --git a/ytmusicapi/locales/ja/LC_MESSAGES/base.mo b/ytmusicapi/locales/ja/LC_MESSAGES/base.mo index 043192c084a97c2c4af2c0b4cc51565d5eee82e8..71452b56dde42f20751679079d4508fd6521a4f2 100644 GIT binary patch delta 291 zcmX@a`j)l+o)F7a1|Z-9Vi_RL0b*Vt-UGxS@BxU~fcPVn{sE*pfcQTUbAs563=Hf* zS_nw90BI>GUmi%a0{QAd8l+zrNIL+r2@vxD`K3%iJq!#%3{4OQ!&E4}0!V`t>;}@z zK>7q!{0xu=8FU{?KLgT0v%mo4AdqDsz&Y`tI3w4@n`Z3AC5a`O`FWH17~=&Dbq$Pk y4Ga|wO{|O!wG9k6*D{(jDn4%7`MA05ar2(XP1_$gFMr&;nc->o)aO%n!zcg}vN9b2 delta 248 zcmaFMdWg0Do)F7a1|Z-BVi_P#0b*VtUIWA+@BoO}fcPPlegUL8fcQNSgY^6WVs;>A zVq{=o0n%JRniWX%18I;xQ6TLA#4;+sf^}~ Pd{4WlKA*Ci0ZIV?DP$oR diff --git a/ytmusicapi/locales/ja/LC_MESSAGES/base.po b/ytmusicapi/locales/ja/LC_MESSAGES/base.po index 5a36e61..b441079 100644 --- a/ytmusicapi/locales/ja/LC_MESSAGES/base.po +++ b/ytmusicapi/locales/ja/LC_MESSAGES/base.po @@ -1,14 +1,14 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Translations for ytmusicapi +# Copyright (C) 2021 sigma67 +# This file is distributed under the same license as ytmusicapi +# sigma67 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-21 09:15+0200\n" +"POT-Creation-Date: 2021-02-01 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,37 +17,38 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "artist" msgstr "アーティスト" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "playlist" msgstr "プレイリスト" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "song" msgstr "曲" -#: ytmusicapi/parsers.py:44 +#: parsers/browsing.py:21 msgid "video" msgstr "動画" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:21 +msgid "station" +msgstr "ステーション" + +#: parsers/browsing.py:123 msgid "albums" msgstr "アルバム" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "singles" msgstr "シングル" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "videos" msgstr "動画" -#: ytmusicapi/parsers.py:93 +#: parsers/browsing.py:123 msgid "playlists" msgstr "プレイリスト" - -#~ msgid "album" -#~ msgstr "アルバム" diff --git a/ytmusicapi/parsers/browsing.py b/ytmusicapi/parsers/browsing.py index 37382e0..ab62b05 100644 --- a/ytmusicapi/parsers/browsing.py +++ b/ytmusicapi/parsers/browsing.py @@ -17,8 +17,12 @@ class Parser: search_result = {} if not resultType: resultType = get_item_text(data, 1).lower() - result_types = ['artist', 'playlist', 'song', 'video'] - result_types_local = [_('artist'), _('playlist'), _('song'), _('video')] + result_types = ['artist', 'playlist', 'song', 'video', 'station'] + result_types_local = [ + _('artist'), _('playlist'), + _('song'), _('video'), + _('station') + ] # default to album since it's labeled with multiple values ('Single', 'EP', etc.) if resultType not in result_types_local: resultType = 'album' @@ -27,23 +31,28 @@ class Parser: search_result['resultType'] = resultType - if resultType in ['artist']: + if resultType != 'artist': + search_result['title'] = get_item_text(data, 0) + + if resultType == 'artist': search_result['artist'] = get_item_text(data, 0) parse_menu_playlists(data, search_result) - elif resultType in ['album']: - search_result['title'] = get_item_text(data, 0) + elif resultType == 'album': search_result['type'] = get_item_text(data, 1) search_result['artist'] = get_item_text(data, 1, 2) search_result['year'] = get_item_text(data, 1, 4, True) - elif resultType in ['playlist']: - search_result['title'] = get_item_text(data, 0) + elif resultType == 'playlist': search_result['author'] = get_item_text(data, 1, default_offset) search_result['itemCount'] = get_item_text(data, 1, - default_offset + 2).split(' ')[0] + default_offset + 2).split('\xa0')[0] - elif resultType in ['song']: + elif resultType == 'station': + search_result['videoId'] = nav(data, NAVIGATION_VIDEO_ID) + search_result['playlistId'] = nav(data, NAVIGATION_PLAYLIST_ID) + + elif resultType == 'song': search_result['duration'] = None if 'menu' in data: toggle_menu = find_object_by_key(nav(data, MENU_ITEMS), @@ -51,12 +60,10 @@ class Parser: if toggle_menu: search_result['feedbackTokens'] = parse_song_menu_tokens(toggle_menu) - elif resultType in ['video']: + elif resultType == 'video': search_result['views'] = None - elif resultType in ['upload']: - search_result['title'] = get_item_text(data, 0) - + elif resultType == 'upload': browse_id = nav(data, NAVIGATION_BROWSE_ID, True) if not browse_id: # song result flex_items = [ @@ -97,7 +104,6 @@ class Parser: search_result['videoId'] = nav( data, PLAY_BUTTON + ['playNavigationEndpoint', 'watchEndpoint', 'videoId'], True) - search_result['title'] = get_item_text(data, 0) song_info = parse_song_runs(get_flex_column_item(data, 1)['text']['runs']) search_result.update(song_info) diff --git a/ytmusicapi/parsers/utils.py b/ytmusicapi/parsers/utils.py index 05c1773..1600b10 100644 --- a/ytmusicapi/parsers/utils.py +++ b/ytmusicapi/parsers/utils.py @@ -22,10 +22,7 @@ def parse_song_runs(runs): for run in runs: text = run['text'] if 'navigationEndpoint' in run: # artist or album - item = { - 'name': text, - 'id': nav(run, NAVIGATION_BROWSE_ID, True) - } + item = {'name': text, 'id': nav(run, NAVIGATION_BROWSE_ID, True)} if item['id'] and item['id'].startswith('MPRE'): # album parsed['album'] = item @@ -33,7 +30,8 @@ def parse_song_runs(runs): parsed['artists'].append(item) else: - if text.endswith(' views'): + # note: YT uses non-breaking space \xa0 to separate number and magnitude + if re.match(r"^\d([^ ])* [^ ]*$", text): parsed['views'] = text.split(' ')[0] elif re.match(r"^(\d+:)*\d+:\d+$", text): diff --git a/ytmusicapi/ytmusic.py b/ytmusicapi/ytmusic.py index 2ff06fa..87fb511 100644 --- a/ytmusicapi/ytmusic.py +++ b/ytmusicapi/ytmusic.py @@ -24,7 +24,6 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi Permits both authenticated and non-authenticated requests. Authentication header data must be provided on initialization. """ - def __init__(self, auth: str = None, user: str = None, @@ -84,11 +83,9 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi with open(pkg_resources.resource_filename('ytmusicapi', 'context.json')) as json_file: self.context = json.load(json_file) - + self.context['context']['client']['hl'] = language - supported_languages = [ - f for f in pkg_resources.resource_listdir('ytmusicapi', 'locales') - ] + supported_languages = [f for f in pkg_resources.resource_listdir('ytmusicapi', 'locales')] if language not in supported_languages: raise Exception("Language not supported. Supported languages are " ', '.join(supported_languages)) @@ -96,8 +93,8 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi try: locale.setlocale(locale.LC_ALL, self.language) except locale.Error: - with suppress(locale.Error): - locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') + with suppress(locale.Error): + locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') self.lang = gettext.translation('base', localedir=pkg_resources.resource_filename( 'ytmusicapi', 'locales'),