Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
P
PlayBot
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de modèles
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Alexandre MORIGNOT
PlayBot
Validations
42cb995d
Valider
42cb995d
rédigé
Il y a 3 ans
par
Alexandre Morignot
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Implement new soundcloud auth
parent
8c3ec48b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
PlayBot/sessions/irc.pm
+6
-4
6 ajouts, 4 suppressions
PlayBot/sessions/irc.pm
PlayBot/sites/soundcloud.pm
+94
-74
94 ajouts, 74 suppressions
PlayBot/sites/soundcloud.pm
playbot-example.conf
+1
-0
1 ajout, 0 suppression
playbot-example.conf
avec
101 ajouts
et
78 suppressions
PlayBot/sessions/irc.pm
+
6
−
4
Voir le fichier @
42cb995d
...
@@ -15,6 +15,7 @@ use Module::Reload;
...
@@ -15,6 +15,7 @@ use Module::Reload;
use
PlayBot::utils::
Logging
;
use
PlayBot::utils::
Logging
;
use
PlayBot::sessions::irc::
later
;
use
PlayBot::sessions::irc::
later
;
use
PlayBot::
sites
;
use
PlayBot::
sites
;
use
PlayBot::sites::
soundcloud
;
use
PlayBot::commands::
parser
;
use
PlayBot::commands::
parser
;
my
$log
=
PlayBot::utils::
Logging
->
new
('
STDOUT
',
1
);
my
$log
=
PlayBot::utils::
Logging
->
new
('
STDOUT
',
1
);
...
@@ -119,6 +120,7 @@ sub setConf
...
@@ -119,6 +120,7 @@ sub setConf
$
PlayBot::sites::
irc
=
$irc
;
$
PlayBot::sites::
irc
=
$irc
;
$
PlayBot::sites::
log
=
$log
;
$
PlayBot::sites::
log
=
$log
;
$
PlayBot::sites::soundcloud::
clientSecret
=
$conf
->
{'
soundcloud_secret
'};
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
PlayBot/sites/soundcloud.pm
+
94
−
74
Voir le fichier @
42cb995d
...
@@ -12,8 +12,11 @@ use PlayBot::utils::Logging;
...
@@ -12,8 +12,11 @@ use PlayBot::utils::Logging;
my
$log
=
PlayBot::utils::
Logging
->
new
('
STDOUT
',
1
);
my
$log
=
PlayBot::utils::
Logging
->
new
('
STDOUT
',
1
);
my
$root
=
'
http://api.soundcloud.com
';
my
$root
=
'
http
s
://api.soundcloud.com
';
my
$clientId
=
'
f4956716fe1a9dc9c3725af822963365
';
my
$clientId
=
'
f4956716fe1a9dc9c3725af822963365
';
our
$clientSecret
;
my
$access_token
=
'';
my
$access_token_time
;
sub
regex_playlist
sub
regex_playlist
...
@@ -27,6 +30,32 @@ sub regex
...
@@ -27,6 +30,32 @@ sub regex
return
qr#(?:^|[^!])https?://(?:www\.)?soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)(?:\?.+)?#
;
return
qr#(?:^|[^!])https?://(?:www\.)?soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)(?:\?.+)?#
;
}
}
sub
get_access_token
{
if
(
$access_token
ne
''
&&
time
()
-
$access_token_time
<=
3000
)
{
return
$access_token
;
}
$log
->
info
("
Get a new soundcloud token
");
my
$ua
=
LWP::
UserAgent
->
new
(
timeout
=>
30
,
env_proxy
=>
1
,
);
$log
->
info
("
the url is
"
.
$root
.
'
/oauth2/token?grant_type=client_credentials&client_id=
'
.
$clientId
.
'
&client_secret=
'
.
$clientSecret
);
my
$response
=
$ua
->
post
(
$root
.
'
/oauth2/token?grant_type=client_credentials&client_id=
'
.
$clientId
.
'
&client_secret=
'
.
$clientSecret
,
);
die
(
$response
->
status_line
)
unless
(
$response
->
is_success
);
my
$content
=
decode_json
(
$response
->
decoded_content
);
$access_token
=
$content
->
{'
access_token
'};
$access_token_time
=
time
();
return
$access_token
;
}
sub
get_playlist
{
sub
get_playlist
{
shift
;
shift
;
...
@@ -82,31 +111,22 @@ sub get {
...
@@ -82,31 +111,22 @@ sub get {
my
$response
;
my
$response
;
$log
->
info
("
the id is
"
.
$id
);
$log
->
info
("
the id is
"
.
$id
);
my
$retries
=
0
;
while
(
$retries
<
10
)
{
$log
->
info
("
Soundcloud API is half break, try number
"
.
(
$retries
+
1
));
if
(
looks_like_number
(
$id
))
if
(
looks_like_number
(
$id
))
{
{
$response
=
$ua
->
get
(
$root
.
'
/tracks/
'
.
$id
.
'
?client_id=
'
.
$clientId
);
$response
=
$ua
->
get
(
$root
.
'
/tracks/
'
.
$id
,
'
Authorization
'
=>
'
OAuth
'
.
get_access_token
(),
);
}
}
else
else
{
{
my
$url
=
'
https://www.soundcloud.com/
'
.
$id
;
my
$url
=
'
https://soundcloud.com/
'
.
$id
;
$log
->
info
("
the url is
"
.
$root
.
'
/resolve.json?url=
'
.
$url
.
'
&client_id=
'
.
$clientId
);
$response
=
$ua
->
get
(
$response
=
$ua
->
get
(
$root
.
'
/resolve.json?url=
'
.
$url
.
'
&client_id=
'
.
$clientId
);
$root
.
'
/resolve?url=
'
.
$url
,
'
Authorization
'
=>
'
OAuth
'
.
get_access_token
(),
);
}
}
if
(
$response
->
code
==
404
)
{
$retries
++
;
sleep
(
1
);
}
else
{
last
;
}
}
die
(
$response
->
status_line
)
unless
(
$response
->
is_success
);
die
(
$response
->
status_line
)
unless
(
$response
->
is_success
);
my
$content
=
decode_json
(
$response
->
decoded_content
);
my
$content
=
decode_json
(
$response
->
decoded_content
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
playbot-example.conf
+
1
−
0
Voir le fichier @
42cb995d
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
"youtube_api_key"
:
"somegarbage"
,
"youtube_api_key"
:
"somegarbage"
,
"facebook_access_token"
:
"myid|myscret"
,
"facebook_access_token"
:
"myid|myscret"
,
"nick"
:
"PlayBot"
,
"nick"
:
"PlayBot"
,
"soundcloud_secret"
:
SOUNDCLOUD_SECRET
,
"channels"
: [
"channels"
: [
"#hello"
,
"#hello"
,
"#world"
"#world"
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter