吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 32946|回复: 73
收起左侧

[Python 转载] python+django 聚合直播平台

  [复制链接]
hubing607 发表于 2019-3-14 09:38
本帖最后由 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 %}

免费评分

参与人数 22吾爱币 +21 热心值 +18 收起 理由
13176816865 + 1 + 1 我很赞同!
半世流离 + 1 + 1 我很赞同!
双人余aaa + 1 我很赞同!
polly521 + 1 + 1 我很赞同!
kof9898 + 1 + 1 演示网址失效了,可以更新一下吗?谢谢
全部忽略 + 1 + 1 用心讨论,共获提升!
yukoyu + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
良人123 + 1 + 1 热心回复!
passengerlee + 1 + 1 牛逼阿
luoluoovo + 1 + 1 谢谢@Thanks!
uumesafe + 1 楼主方便的话就分享一下 urls.py文件吧。
cokar + 1 + 1 谢谢@Thanks!
狼痞_wolf + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
sprnt + 1 + 1 多线楼主。这真是个好东西啊。各位注意身体~!
水泥工艺学 + 1 + 1 谢谢@Thanks!
shenhuasxs + 1 我很赞同!
超啊超啊超啊 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
sblk0402Apj + 1 + 1 谢谢@Thanks!
爬小萌新虫 + 1 + 1 用心讨论,共获提升!
niebaohua + 1 + 1 &amp;lt;font style=&amp;quot;vertical-align: inherit;&amp;quot;&amp;gt;&amp;lt;font style=
antfly + 1 我很赞同!
微微笑95 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

uumesafe 发表于 2019-4-8 21:10
一夜恶补 Django  + html
0.PNG


2.PNG
 楼主| hubing607 发表于 2019-3-21 18:34
elliotxin 发表于 2019-3-21 13:03
真厉害,可以分享一下源代码吗?

https://blog.csdn.net/qq_35554125/article/details/79462885  

整个架构是按照这个来的 ,替换其中的view文件和页面文件,还有url文件需要对应下即可
旗木卡卡西515 发表于 2019-3-14 11:28
chinaqin 发表于 2019-3-14 11:32
最近刚好在学习Django  ,向大佬学习了
简单小太阳 发表于 2019-3-14 19:22
强啊,正准备学PY
wan66d 发表于 2019-3-14 19:34 来自手机
老哥分享下源码?
okz 发表于 2019-3-14 19:59
强,给力,学习到了
paulz2018 发表于 2019-3-15 10:55
强啊,正准备学PY
wymust 发表于 2019-3-15 11:52
感谢楼主分享
爬小萌新虫 发表于 2019-3-15 14:30
现在使用python做网页的公司多吗
 楼主| hubing607 发表于 2019-3-15 15:13
爬小萌新虫 发表于 2019-3-15 14:30
现在使用python做网页的公司多吗

只能说有一些 百度 新浪 都有业务线在用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 10:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表