Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 3a59612cb787ecad16a188222105a96b060659fa
  • master par défaut protégée
  • rust-playlist-sync
  • rust
  • fix-qt-deprecated-qvariant-type
  • fix-mpris-qtwindow-race-condition
  • rust-appimage-wayland
  • windows-build-rebased
  • v2.5 protégée
  • v2.4 protégée
  • v2.3-1 protégée
  • v2.3 protégée
  • v2.2 protégée
  • v2.1 protégée
  • v2.0 protégée
  • v1.8-3 protégée
  • v1.8-2 protégée
  • v1.8-1 protégée
  • v1.8 protégée
  • v1.7 protégée
  • v1.6 protégée
  • v1.5 protégée
  • v1.4 protégée
  • v1.3 protégée
  • v1.2 protégée
  • v1.1 protégée
  • v1.0 protégée
27 résultats

module_sdl2.c

Blame
  • mixcloud.pm 1,28 Kio
    package mixcloud;
    
    use LWP::UserAgent;
    use HTML::Parser;
    use HTML::Entities;
    
    require Exporter;
    our @ISA = qw(Exporter);
    our @EXPORT = qw(mixcloud);
    
    
    my $inTitle = 0;
    my $inAuthor = 0;
    my %infos;
    
    
    sub mixcloud {
    	my ($url) = @_;
    
    	my $ua = LWP::UserAgent->new(
    		agent   => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1",
    		timeout => 30
    	);
    
    	my $response = $ua->get($url);
    	die($response->status_line) unless ($response->is_success);
    
    	my $content = $response->decoded_content;
    
    	my $parser = HTML::Parser->new();
    	$parser->handler(text => \&parser_text, 'text');
    	$parser->handler(start => \&parser_start, 'tagname');
    	$parser->handler(end => \&parser_end, 'tagname');
    	$parser->unbroken_text(1);
    	$parser->report_tags('title', 'a');
    	$parser->parse($content);
    	$parser->eof();
    	
    	$infos{'url'} = $url;
    	
    	return %infos;
    }
    
    sub parser_text
    {
    	my ($text) = @_;
    	chomp $text;
    	$text = decode_entities($text);
    
    	if ($inTitle) {
    		$text =~ s/\n//;
    		$text =~ s/ \| Mixcloud .*//;
    		$text =~ s/^ *//;
    		$text =~ s/[^a-zA-Z0-9\(\)\[\]]*$//;
    		($infos{'author'}, $infos{'title'}) = split (' - ', $text, 2);
    	}
    }
    
    sub parser_start
    {
    	my ($tag) = @_;
    	$inTitle = 1 if ($tag eq 'title');
    }
    
    sub parser_end
    {
    	my ($tag) = @_;
    	$inTitle = 0 if ($tag eq 'title');
    }