首页 编程教程正文

python+django 聚合直播平台

piaodoo 编程教程 2020-02-22 22:15:48 1606 0 python教程

本文来源吾爱破解论坛

本帖最后由 hubing607 于 2019-7-30 08:49 编辑

看个小姐姐还要被各种广告和会员所扰,于是想着自己写一个,做的比较匆忙,演示地址 http://192.144.141.252:8000/   可以用test/Test123456登陆看效果此为PC版本,需浏览器支持flash或H5播放器,移动端只有部分源可播放

view文件
[Python] 纯文本查看 复制代码

import datetime
import json
import os
import time
from os import path
import hashlib
import requests
from PIL import Image
# from .models import Home
# Create your views here.
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.http import require_http_methods
from django.views.generic import View


# @method_decorator(login_required, name='dispatch')

@method_decorator(login_required, name='dispatch')
class HomeListView(View):
    def pingtai(self):
        url = 'http://api.hclyz.com:81/mf/json.txt'
        response = requests.get(url)
        self.pingtai = json.loads(response.text)['pingtai']
        return self.pingtai
    def get(self, request):
        return render(request,'home.html',{'pingtai':self.pingtai})

@method_decorator(login_required, name='dispatch')
class liveRoomView(View):
    def render(self, request):
        return render(request, 'liveRoom.html',{"room_title":self.title,"anchors":self.liveroom} )
    def get(self, request,title):
        plates = HomeListView()
        rooms = plates.pingtai()
        for plate in rooms:
            try:
                if plate['title'] == title:
                    self.address = plate['address']
                    self.title = plate['title']
                    break
                else:
                    self.address = "获取不到地址"
            except:
                self.address = "获取不到地址"
        zhubo = str("http://api.hclyz.com:81/mf/"+self.address)
        response = requests.get(zhubo)
        self.liveroom = json.loads(response.text)['zhubo']
        return self.render(request)

@method_decorator(login_required, name='dispatch')
class anchor(View):
    def render(self, request):
        return render(request, 'anchor.html', {'anchor_name':self.anchor_name,'room_title':self.room_title, 'anchor_address':self.anchor_address})
    def get(self, request,title,title2):
        self.anchor_name = str(title2)
        self.room_title = str(title)
        plates = HomeListView()
        rooms = plates.pingtai()
        for plate in rooms:
            if plate['title'] == self.room_title:
                pingtai = plate['address']
                self.title = plate['title']
                zhubo = str("http://api.hclyz.com:81/mf/" + pingtai)
                response = requests.get(zhubo)
                self.liveroom = json.loads(response.text)['zhubo']
                break
        for zhubo in self.liveroom:
            if zhubo['title'] == self.anchor_name:
                if getHttp(zhubo['address']) is not None :
                    self.anchor_address = getHttp(zhubo['address'])
                else:
                    self.anchor_address = zhubo['address']
                print(self.anchor_address)
                break
            else:
                self.anchor_address = "获取不到地址"
        return self.render(request)
@method_decorator(login_required, name='dispatch')
class anchor_mo(View):
    def render(self, request):
        return render(request, 'anchor_mo.html', {'anchor_name':self.anchor_name,'room_title':self.room_title, 'anchor_address':self.anchor_address})
    def get(self, request,title,title2):
        self.anchor_name = str(title2)
        self.room_title = str(title)
        plates = HomeListView()
        rooms = plates.pingtai()
        for plate in rooms:
            if plate['title'] == self.room_title:
                pingtai = plate['address']
                self.title = plate['title']
                zhubo = str("http://api.hclyz.com:81/mf/" + pingtai)
                response = requests.get(zhubo)
                self.liveroom = json.loads(response.text)['zhubo']
                break
        for zhubo in self.liveroom:
            if zhubo['title'] == self.anchor_name:
                if getHttp(zhubo['address']) is not None :
                    self.anchor_address = getHttp(zhubo['address'])
                else:
                    self.anchor_address = zhubo['address']
                print(self.anchor_address)
                break
            else:
                self.anchor_address = "获取不到地址"
        return self.render(request)

def getHttp(url):
    Ourl = str(url)
    if 't.cn' in Ourl:
        try:
            apiUrl = 'https://api.weibo.com/2/short_url/expand.json'
            apiKey = '1242113336'
            request = requests.get('http://api.t.sina.com.cn/short_url/expand.json?source=%s&url_short=%s' % (apiKey, url))
            nUrl = json.loads(request.text)[0]['url_long']
            return nUrl
        except:
            return Ourl
    else:
        Nurl = Ourl
        return Nurl

class support(View):
    def render(self, request):
        return render(request, 'support.html', )
    def get(self,request):
        return self.render(request)


主页文件
[HTML] 纯文本查看 复制代码
{% extends 'base.html' %}
{% block content %}
<tbody>
<div class="card-body p-3">
        <div class="container">
            <div class="row">
                {% for pi in pingtai %}
                    <div style="position:inherit;width:200px;height:200px;">
                            <a href="{% url 'liveRoom' pi.title %}"><img src="{{ pi.xinimg }}" width="100" height="100" alt="{{ pi.title }}"></a>
<div style="position:absolute;width:100px;height:100px;">
                        {{ pi.title }}
                    </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>
</tbody>
{% endblock %}


直播平台文件
[HTML] 纯文本查看 复制代码
{% block breadcrumb %}
    <li class="breadcrumb-item"><a href="{% url 'main' %}">返回</a></li>
    <li class="breadcrumb-item active">{{ room_title }}</li>
{% endblock %}
{% block content %}
<div class="card-body p-3">
<div class="container">
            <div class="row">
                {% for anchor in anchors  %}
                    <div style="position:inherit;width:200px;height:200px;">
                        <a href="{% url 'zhubo' room_title anchor.title  %}"><img src="{{ anchor.img }}" width="100" height="100"></a>
                        <div style="position:absolute;width:100px;height:100px;">
                            <a href="{% url 'zhubo' room_title anchor.title  %}">{{anchor.title }}</a>
                            <a href="{% url 'yidong' room_title anchor.title  %}"><small>移动版</small></a>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}


主播间文件
[Python] 纯文本查看 复制代码
{% block breadcrumb %}
    <li class="breadcrumb-item"><a href="{% url 'main' %}">返回</a></li>
    <li class="breadcrumb-item"><a href="{% url 'liveRoom' room_title %}">{{ room_title }}</a></li>
    <li class="breadcrumb-item active">{{ anchor_name }}</li>
{#    <li class="breadcrumb-item active">{{ anchor_address }}</li>#}
{% endblock %}
{% block content %}
<div align="center">
    <link rel="stylesheet"  />
    <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.8.0/aliplayer-flash-min.js"></script>
    <div  class="prism-player" id="J_prismPlayer"></div>
    <script>
            var player = new Aliplayer({
            id: 'J_prismPlayer',
            width: '400px',
            height:'600px',
            autoplay: true,
            isLive:true,
            snapshot:true,
            //支持播放地址播放,此播放优先级最高
            source : '{{ anchor_address }}'
                });
        </script>
</div>
{% endblock %}

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/8023.html

搜索