diff --git a/app/data_export.json b/app/data_export.json index bdb151c..7cc2ffd 100644 --- a/app/data_export.json +++ b/app/data_export.json @@ -1 +1 @@ -{"twitter": [{"username": "aantonop"}, {"username": "Trezor"}, {"username": "aitor13023985"}, {"username": "guaridadelzorro"}, {"username": "elonmusk"}, {"username": "bitcoin"}, {"username": "monero"}, {"username": "xmroutreach"}, {"username": "Locha_io"}, {"username": "randybrito"}, {"username": "btcven"}, {"username": "Snowden"}, {"username": "_prestwich"}, {"username": "TradeOnFire"}], "youtube": [{"channelId": "UCjr2bPAyPV7t35MvcgT3W8Q"}, {"channelId": "UCJWCJCWOxBYSi5DhCieLOLQ"}, {"channelId": "UCW3iqZr2cQFYKdO9Kpa97Yw"}, {"channelId": "UCLXo7UDZvByw2ixzpQCufnA"}, {"channelId": "UCR9sFzaG9Ia_kXJhfxtFMBA"}, {"channelId": "UCbdSYaPD-lr1kW27UJuk8Pw"}, {"channelId": "UCa3DVlGH2_QhvwuWlPa6MDQ"}, {"channelId": "UComoqWnjQlH7JpvqfyGnWNA"}, {"channelId": "UCA58hhLv4pdgDjBW5oNSklA"}]} \ No newline at end of file +{"twitter": [{"username": "aantonop"}, {"username": "Trezor"}, {"username": "aitor13023985"}, {"username": "guaridadelzorro"}, {"username": "elonmusk"}, {"username": "bitcoin"}, {"username": "monero"}, {"username": "xmroutreach"}, {"username": "Locha_io"}, {"username": "randybrito"}, {"username": "btcven"}, {"username": "Snowden"}, {"username": "_prestwich"}, {"username": "TradeOnFire"}], "youtube": [{"channelId": "UCjr2bPAyPV7t35MvcgT3W8Q"}, {"channelId": "UCJWCJCWOxBYSi5DhCieLOLQ"}, {"channelId": "UCW3iqZr2cQFYKdO9Kpa97Yw"}, {"channelId": "UCLXo7UDZvByw2ixzpQCufnA"}, {"channelId": "UCR9sFzaG9Ia_kXJhfxtFMBA"}, {"channelId": "UCbdSYaPD-lr1kW27UJuk8Pw"}, {"channelId": "UCa3DVlGH2_QhvwuWlPa6MDQ"}, {"channelId": "UComoqWnjQlH7JpvqfyGnWNA"}, {"channelId": "UCA58hhLv4pdgDjBW5oNSklA"}, {"channelId": "UCkHR9m-tscD3ojD7_viIfTA"}, {"channelId": "UCYO_jab_esuFRV4b17AJtAw"}, {"channelId": "UC9-y-6csu5WGm29I7JiwpnA"}, {"channelId": "UC2PA-AKmVpU6NKCGtZq_rKQ"}, {"channelId": "UC2Qc22WUjL_GbBDIPvmHWmQ"}, {"channelId": "UC3Hx81QYLoEQkm3vyl4N4eQ"}, {"channelId": "UCiwy9Lx6h1Oi-UYwYDbgBZA"}, {"channelId": "UCHW_zn-nX5nvMjEA6mtNZ1A"}]} \ No newline at end of file diff --git a/app/forms.py b/app/forms.py index 158a481..d920f4b 100644 --- a/app/forms.py +++ b/app/forms.py @@ -15,8 +15,8 @@ class SearchForm(FlaskForm): submit = SubmitField('Search') class ChannelForm(FlaskForm): - channelId = StringField('Channel ID') - submit = SubmitField('Follow') + channelId = StringField('') + submit = SubmitField('Search') class RegistrationForm(FlaskForm): diff --git a/app/models.py b/app/models.py index 82c71da..561faee 100644 --- a/app/models.py +++ b/app/models.py @@ -28,7 +28,8 @@ class User(UserMixin, db.Model): def check_password(self, password): return check_password_hash(self.password_hash, password) - + + # TWITTER def follow(self, user): if not self.is_following(user): self.followed.append(user) @@ -46,9 +47,21 @@ class User(UserMixin, db.Model): def saved_posts(self): return Post.query.filter_by(user_id=self.id) - + + # YOUTUBE def youtube_following_list(self): return self.youtubeFollowed.all() + + def is_following_yt(self, cid): + temp_cid = invidiousFollow.query.filter_by(channelId = cid).first() + if temp_cid is None: + return False + else: + following = self.youtube_following_list() + for f in following: + if f.channelId == cid: + return True + return False followed = db.relationship( 'User', secondary=followers, @@ -88,6 +101,7 @@ class invidiousPost(): videoThumb = '#' description = "LOREM IPSUM" date = 'None' + views = 'NaN' class invidiousFollow(db.Model): diff --git a/app/routes.py b/app/routes.py index 53001de..8cf6b09 100644 --- a/app/routes.py +++ b/app/routes.py @@ -146,6 +146,29 @@ def invidious(): videos.sort(key=lambda x: x.date, reverse=True) return render_template('invidious.html', videos=videos, form=form) +@app.route('/ytsearch', methods=['GET', 'POST']) +@login_required +def ytsearch(): + form = ChannelForm() + button_form = EmptyForm() + if form.validate_on_submit(): + channelId = form.channelId.data + r = requests.get('https://invidio.us/api/v1/search?type=channel&q={}'.format(channelId)) + if r.status_code == 200: + results = json.loads(r.content) + channels = [] + for res in results: + channels.append({ + 'username':res['author'], + 'channelId':res['authorId'], + 'thumbnail':res['authorThumbnails'][0]['url'], + 'subCount':letterify(res['subCount']) + }) + + return render_template('ytsearch.html', form=form, btform=button_form, results=channels) + else: + return render_template('ytsearch.html', form=form) + @app.route('/savePost/', methods=['POST']) @login_required def savePost(url): @@ -181,6 +204,43 @@ def deleteSaved(id): db.session.commit() return redirect(url_for('saved')) +@app.route('/ytfollow/', methods=['POST']) +@login_required +def ytfollow(channelId): + form = EmptyForm() + if form.validate_on_submit(): + channel = invidiousFollow.query.filter_by(channelId=channelId).first() + if requests.get('https://invidio.us/feed/channel/{}'.format(channelId)).status_code == 200: + if channel is None: + follow = invidiousFollow() + follow.channelId = channelId + follow.followers.append(current_user) + try: + db.session.add(follow) + db.session.commit() + except: + flash("Something went wrong. Try again!") + return redirect(url_for('invidious')) + flash('You are following {}!'.format(channelId)) + else: + flash("Something went wrong... try again") + return redirect(url_for('ytsearch')) + else: + return redirect(url_for('ytsearch')) + +@app.route('/ytunfollow/', methods=['POST']) +@login_required +def ytunfollow(channelId): + form = EmptyForm() + channel = invidiousFollow.query.filter_by(channelId=channelId).first() + try: + db.session.delete(channel) + db.session.commit() + flash("User unfollowed!") + except: + flash("There was an error unfollowing the user. Try again.") + return redirect(url_for('ytsearch')) + @app.route('/follow/', methods=['POST']) @login_required def follow(username): @@ -412,7 +472,27 @@ def getInvidiousPosts(ids): video.videoUrl = vid.link video.videoTitle = vid.title video.videoThumb = vid.media_thumbnail[0]['url'] + video.views = vid.media_statistics['views'] video.description = vid.summary.split('

')[1] video.description = re.sub(r'^https?:\/\/.*[\r\n]*', '', video.description[0:120]+"...", flags=re.MULTILINE) videos.append(video) - return videos \ No newline at end of file + return videos + +def letterify(number): + order = len(str(number)) + if order == 4: + subCount = "{k}.{c}k".format(k=str(number)[0:1], c=str(number)[1:2]) + elif order == 5: + subCount = "{k}.{c}k".format(k=str(number)[0:2], c=str(number)[2:3]) + elif order == 6: + subCount = "{k}.{c}k".format(k=str(number)[0:3], c=str(number)[3:4]) + elif order == 7: + subCount = "~{M}M".format(M=str(number)[0:1]) + elif order == 8: + subCount = "~{M}M".format(M=str(number)[0:2]) + elif order >= 8: + subCount = "{M}M".format(M=str(number)[0:3]) + else: + subCount = str(number) + + return subCount \ No newline at end of file diff --git a/app/templates/_post.html b/app/templates/_post.html index 7e26fb1..7ca8cd2 100644 --- a/app/templates/_post.html +++ b/app/templates/_post.html @@ -20,7 +20,7 @@

-

+ diff --git a/app/templates/_post_nort.html b/app/templates/_post_nort.html index 53860e1..20134ac 100644 --- a/app/templates/_post_nort.html +++ b/app/templates/_post_nort.html @@ -21,7 +21,7 @@

{{post.content}}

- + diff --git a/app/templates/_video.html b/app/templates/_video.html index 1ecfd64..f3d5f0c 100644 --- a/app/templates/_video.html +++ b/app/templates/_video.html @@ -12,13 +12,17 @@
+ + + ‎‎{{video.views}} + - {{video.timeStamp}} + {{video.timeStamp}}‎‎‎‎ ‎‎‎ - + Open diff --git a/app/templates/base.html b/app/templates/base.html index 822c776..437ee66 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -38,6 +38,7 @@ Youtube + Search Logout {% endif %} diff --git a/app/templates/ytsearch.html b/app/templates/ytsearch.html new file mode 100644 index 0000000..c289727 --- /dev/null +++ b/app/templates/ytsearch.html @@ -0,0 +1,53 @@ +{% extends "base.html" %} + +{% block content %} +
+ + {{ form.hidden_tag() }} +

+ {{ form.channelId.label }}
+ {{ form.channelId(size=32) }}
+ {% for error in form.channelId.errors %} + [{{ error }}] + {% endfor %} +

+

{{ form.submit() }}

+ + + {% if results %} +
+
+ {% for res in results %} +
+
+ {% if not current_user.is_following_yt(res.channelId) %} +

+

+ {{ btform.hidden_tag() }} + {{ btform.submit(value='Follow') }} +
+

+ {% else %} +

+

+ {{ btform.hidden_tag() }} + {{ btform.submit(value='Unfollow') }} +
+

+ {% endif %} +
+ +
+ {{res.username}} +
+ {{res.subCount}} +
+
+
+ {% endfor %} +
+
+ {% endif %} +
+ +{% endblock %} \ No newline at end of file